}
@Test
public void testGetBounds() throws Exception {
securityManager.createSecurityContext(null); // assure a security context exists for this thread
Envelope bounds;
// first run, this should put things in the cache
recorder.clear();
bounds = vectorLayerService.getBounds(LAYER_BEANS, geoService.getCrs2("EPSG:4326"), null);
Assert.assertNotNull(bounds);
Assert.assertEquals(0.0, bounds.getMinX(), DELTA);
Assert.assertEquals(0.0, bounds.getMinY(), DELTA);
Assert.assertEquals(7.0, bounds.getMaxX(), DELTA);
Assert.assertEquals(3.0, bounds.getMaxY(), DELTA);
Assert.assertEquals("", recorder.matches(CacheCategory.BOUNDS,
"Put item in cache"));
// verify that data is in the cache
DummyCacheService cache = (DummyCacheService)cacheManager.getCacheForTesting(LAYER_BEANS, CacheCategory.BOUNDS);
Assert.assertEquals(1, cache.size());
String key = cache.getKey();
BoundsCacheContainer bcc = (BoundsCacheContainer) cache.getObject();
CacheContext cc = bcc.getContext();
bcc = new BoundsCacheContainer(new Envelope(0, 10, 0, 10));
bcc.setContext(cc);
cache.put(key, bcc);
// get bounds again, the result should be different because we changed the cached value
recorder.clear();
bounds = vectorLayerService.getBounds(LAYER_BEANS, geoService.getCrs2("EPSG:4326"), null);
Assert.assertNotNull(bounds);
Assert.assertEquals(0.0, bounds.getMinX(), DELTA);
Assert.assertEquals(0.0, bounds.getMinY(), DELTA);
Assert.assertEquals(10.0, bounds.getMaxX(), DELTA);
Assert.assertEquals(10.0, bounds.getMaxY(), DELTA);
Assert.assertEquals("", recorder.matches(CacheCategory.BOUNDS,
"Got item from cache"));
// ask for different layer, should not be found in cache as context is different
recorder.clear();