public void testDiskQuotaStorage() throws Exception {
// normal state, quota is not enabled by default
GWC gwc = GWC.get();
ConfigurableQuotaStoreProvider provider = GeoServerExtensions.bean(ConfigurableQuotaStoreProvider.class);
DiskQuotaConfig quota = gwc.getDiskQuotaConfig();
JDBCConfiguration jdbc = gwc.getJDBCDiskQuotaConfig();
assertFalse("Disk quota is enabled??", quota.isEnabled());
assertNull("jdbc quota config should be missing", jdbc);
assertTrue(getActualStore(provider) instanceof DummyQuotaStore);
// enable disk quota in H2 mode
quota.setEnabled(true);
quota.setQuotaStore("H2");
gwc.saveDiskQuotaConfig(quota, null);
GeoServerDataDirectory dd = GeoServerExtensions.bean(GeoServerDataDirectory.class);
File jdbcConfigFile = dd.findFile("gwc/geowebcache-diskquota-jdbc.xml");
assertNull("jdbc config should not be there", jdbcConfigFile);
File h2DefaultStore = dd.findFile("gwc/diskquota_page_store_h2");
assertNotNull("jdbc store should be there", h2DefaultStore);
assertTrue(getActualStore(provider) instanceof JDBCQuotaStore);
// disable again and clean up
quota.setEnabled(false);
gwc.saveDiskQuotaConfig(quota, null);
FileUtils.deleteDirectory(h2DefaultStore);
// now enable it in JDBC mode, with H2 local storage
quota.setEnabled(true);
quota.setQuotaStore("JDBC");
jdbc = new JDBCConfiguration();
jdbc.setDialect("H2");
ConnectionPoolConfiguration pool = new ConnectionPoolConfiguration();
pool.setDriver("org.h2.Driver");
pool.setUrl("jdbc:h2:./target/quota-h2");
pool.setUsername("sa");
pool.setPassword("");
pool.setMinConnections(1);
pool.setMaxConnections(1);
pool.setMaxOpenPreparedStatements(50);
jdbc.setConnectionPool(pool);
gwc.saveDiskQuotaConfig(quota, jdbc);
jdbcConfigFile = dd.findFile("gwc/geowebcache-diskquota-jdbc.xml");
assertNotNull("jdbc config should be there", jdbcConfigFile);
assertNull("jdbc store should be there", dd.findDataFile("gwc/diskquota_page_store_h2"));
File newQuotaStore = new File("./target/quota-h2.data.db");