* @throws Exception if an error occurs
*/
public void testImageInfoCache() throws Exception {
ImageSessionContext sessionContext = imageContext.newSessionContext();
ImageManager manager = imageContext.getImageManager();
String invalid1 = "invalid1.jpg";
String invalid2 = "invalid2.jpg";
String valid1 = "bgimg300dpi.bmp";
String valid2 = "big-image.png";
ImageCacheStatistics statistics = new ImageCacheLoggingStatistics(true);
manager.getCache().setCacheListener(statistics);
ImageInfo info1, info2;
info1 = manager.getImageInfo(valid1, sessionContext);
assertNotNull(info1);
assertEquals(valid1, info1.getOriginalURI());
try {
manager.getImageInfo(invalid1, sessionContext);
fail("Expected FileNotFoundException for invalid URI");
} catch (FileNotFoundException e) {
//expected
}
//2 requests:
assertEquals(0, statistics.getImageInfoCacheHits());
assertEquals(2, statistics.getImageInfoCacheMisses());
assertEquals(0, statistics.getInvalidHits());
statistics.reset();
//Cache Hit
info1 = manager.getImageInfo(valid1, sessionContext);
assertNotNull(info1);
assertEquals(valid1, info1.getOriginalURI());
//Cache Miss
info2 = manager.getImageInfo(valid2, sessionContext);
assertNotNull(info2);
assertEquals(valid2, info2.getOriginalURI());
try {
//Invalid Hit
manager.getImageInfo(invalid1, sessionContext);
fail("Expected FileNotFoundException for invalid URI");
} catch (FileNotFoundException e) {
//expected
}
try {
//Invalid (Cache Miss)
manager.getImageInfo(invalid2, sessionContext);
fail("Expected FileNotFoundException for invalid URI");
} catch (FileNotFoundException e) {
//expected
}