/** Creates a new instance of the resource pool explicitly supplying the application context. */ public static ResourcePool create(Catalog catalog, ApplicationContext appContext) { // look for an implementation in spring context ResourcePool pool = appContext == null ? GeoServerExtensions.bean(ResourcePool.class) : GeoServerExtensions.bean(ResourcePool.class, appContext); if (pool == null) { pool = new ResourcePool(); } pool.setCatalog(catalog); return pool; }
@Test public void testGetParamsFixesDatabaseFilePath() { Catalog catalog = getCatalog(); ResourcePool pool = new ResourcePool(catalog); DataStoreInfo ds = getCatalog().getFactory().createDataStore(); ds.getConnectionParameters().put("database", "file:data/test.gpkg"); Map newParams = pool.getParams(ds.getConnectionParameters(), getResourceLoader()); GeoServerDataDirectory dataDir = new GeoServerDataDirectory(getResourceLoader()); String absolutePath = dataDir.get("data/test.gpkg").dir().getAbsolutePath(); assertNotEquals(newParams.get("database"), "file:data/test.gpkg"); assertTrue(((String) newParams.get("database")).contains(absolutePath)); }
Catalog catalog = getCatalog(); ResourcePool pool = new ResourcePool(catalog) {
@Test public void testCacheClearing() throws IOException { cleared = false; ResourcePool pool = new ResourcePool(getCatalog()) { @Override public void clear(FeatureTypeInfo info) { cleared = true; super.clear(info); } }; FeatureTypeInfo info = getCatalog() .getFeatureTypeByName( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); assertNotNull(pool.getFeatureType(info)); info.setTitle("changed"); assertFalse(cleared); getCatalog().save(info); assertTrue(cleared); cleared = false; assertNotNull(pool.getFeatureType(info)); for (LayerInfo l : getCatalog().getLayers(info)) { getCatalog().remove(l); } getCatalog().remove(info); assertTrue(cleared); }
@Configuration // optional @ComponentScan(basePackages = {"name.your.package.here"} public class AppConfig { @Bean // or @Bean(name = "nameOfYourBean") public ResourcePool getResourcePool() { return new ResourcePool(); } }