X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fio%2Fcache%2FAppCacheTest.java;fp=test%2Fjalview%2Fio%2Fcache%2FAppCacheTest.java;h=56380287b25db830cc3fa8e996080d23b89e395f;hb=f063821ed0be9c1581af74643a1aa5798731af65;hp=0000000000000000000000000000000000000000;hpb=fd18e2c73cd015d4e38ad91da0e5d7532ff0ef42;p=jalview.git diff --git a/test/jalview/io/cache/AppCacheTest.java b/test/jalview/io/cache/AppCacheTest.java new file mode 100644 index 0000000..5638028 --- /dev/null +++ b/test/jalview/io/cache/AppCacheTest.java @@ -0,0 +1,61 @@ +package jalview.io.cache; + +import java.util.LinkedHashSet; + +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AppCacheTest +{ + private AppCache appCache; + + private static final String TEST_CACHE_KEY = "CACHE.UNIT_TEST"; + + private static final String TEST_FAKE_CACHE_KEY = "CACHE.UNIT_TEST_FAKE"; + + @BeforeClass(alwaysRun = true) + public void setUpCache() + { + appCache = AppCache.getInstance(); + } + + public void generateTestCacheItems() + { + LinkedHashSet testCacheItems = new LinkedHashSet(); + for (int x = 0; x < 10; x++) + { + testCacheItems.add("TestCache" + x); + } + appCache.putCache(TEST_CACHE_KEY, testCacheItems); + appCache.persistCache(TEST_CACHE_KEY); + } + + @Test(groups = { "Functional" }) + public void appCacheTest() + { + LinkedHashSet cacheItems = appCache + .getAllCachedItemsFor(TEST_FAKE_CACHE_KEY); + Assert.assertEquals(cacheItems.size(), 0); + generateTestCacheItems(); + cacheItems = appCache.getAllCachedItemsFor(TEST_CACHE_KEY); + Assert.assertEquals(cacheItems.size(), 10); + appCache.deleteCacheItems(TEST_CACHE_KEY); + cacheItems = appCache.getAllCachedItemsFor(TEST_CACHE_KEY); + Assert.assertEquals(cacheItems.size(), 0); + } + + @Test(groups = { "Functional" }) + public void appCacheLimitTest() + { + String limit = appCache.getCacheLimit(TEST_CACHE_KEY); + Assert.assertEquals(limit, "99"); + limit = String.valueOf(appCache.updateCacheLimit(TEST_CACHE_KEY, 20)); + Assert.assertEquals(limit, "20"); + limit = appCache.getCacheLimit(TEST_CACHE_KEY); + Assert.assertEquals(limit, "20"); + appCache.updateCacheLimit(TEST_CACHE_KEY, 99); + } + + +}