@Test
public void testCacheConfig() throws Exception {
// Simulates the situation where multiple GeoServer instances are sharing a database.
ServiceInfo service = new WMSInfoImpl();
((WMSInfoImpl) service).setId("WMS-TEST");
service.setName("WMS");
service.setMaintainer("Foo");
service = database.add(service);
assertEquals(service.getMaintainer(), "Foo");
// Change the stored configuration
// KS: sorry, this is an utter kludge
Connection conn = testSupport.getDataSource().getConnection();
try {
Statement stmt = conn.createStatement();
//assertEquals(1, stmt.executeUpdate("UPDATE object_property SET value='Bar' WHERE property_type=(SELECT oid FROM property_type WHERE type_id = (SELECT oid FROM type WHERE typename='org.geoserver.wms.ServiceInfo') AND name='maintainer') AND id = '"+service.getId()+"';"));
assertEquals(1, stmt.executeUpdate("UPDATE object SET blob=(SELECT replace(blob, '<maintainer>Foo</maintainer>', '<maintainer>Bar</maintainer>') FROM object WHERE id = '"+service.getId()+"')"));
} finally {
conn.close();
}
// Should be cached
service = database.getById(service.getId(), ServiceInfo.class);
assertEquals("Foo", service.getMaintainer());
// Notify of update
for(ConfigurationListener l : database.getGeoServer().getListeners()){
l.handlePostServiceChange(service);
}
// Should show the new value
service = database.getById(service.getId(), ServiceInfo.class);
assertEquals("Bar", service.getMaintainer());
}