1 package jalview.io.cache;
3 import java.util.LinkedHashSet;
5 import org.testng.Assert;
6 import org.testng.annotations.BeforeClass;
7 import org.testng.annotations.Test;
9 public class AppCacheTest
11 private AppCache appCache;
13 private static final String TEST_CACHE_KEY = "CACHE.UNIT_TEST";
15 private static final String TEST_FAKE_CACHE_KEY = "CACHE.UNIT_TEST_FAKE";
17 @BeforeClass(alwaysRun = true)
18 public void setUpCache()
20 appCache = AppCache.getInstance();
23 public void generateTestCacheItems()
25 LinkedHashSet<String> testCacheItems = new LinkedHashSet<String>();
26 for (int x = 0; x < 10; x++)
28 testCacheItems.add("TestCache" + x);
30 appCache.putCache(TEST_CACHE_KEY, testCacheItems);
31 appCache.persistCache(TEST_CACHE_KEY);
34 @Test(groups = { "Functional" })
35 public void appCacheTest()
37 LinkedHashSet<String> cacheItems = appCache
38 .getAllCachedItemsFor(TEST_FAKE_CACHE_KEY);
39 Assert.assertEquals(cacheItems.size(), 0);
40 generateTestCacheItems();
41 cacheItems = appCache.getAllCachedItemsFor(TEST_CACHE_KEY);
42 Assert.assertEquals(cacheItems.size(), 10);
43 appCache.deleteCacheItems(TEST_CACHE_KEY);
44 cacheItems = appCache.getAllCachedItemsFor(TEST_CACHE_KEY);
45 Assert.assertEquals(cacheItems.size(), 0);
48 @Test(groups = { "Functional" })
49 public void appCacheLimitTest()
51 String limit = appCache.getCacheLimit(TEST_CACHE_KEY);
52 Assert.assertEquals(limit, "99");
53 limit = String.valueOf(appCache.updateCacheLimit(TEST_CACHE_KEY, 20));
54 Assert.assertEquals(limit, "20");
55 limit = appCache.getCacheLimit(TEST_CACHE_KEY);
56 Assert.assertEquals(limit, "20");
57 appCache.updateCacheLimit(TEST_CACHE_KEY, 99);