41ac176ebb216e8bcda03b2db901b6d4c54a5fd7
[jalview.git] / test / jalview / io / cache / AppCacheTest.java
1 package jalview.io.cache;
2
3 import java.util.LinkedHashSet;
4
5 import org.testng.Assert;
6 import org.testng.annotations.BeforeClass;
7 import org.testng.annotations.Test;
8
9 public class AppCacheTest
10 {
11   private AppCache appCache;
12
13   private static final String TEST_CACHE_KEY = "CACHE.UNIT_TEST";
14
15   private static final String TEST_FAKE_CACHE_KEY = "CACHE.UNIT_TEST_FAKE";
16
17   @BeforeClass(alwaysRun = true)
18   public void setUpCache()
19   {
20     appCache = AppCache.getInstance();
21   }
22
23   public void generateTestCacheItems()
24   {
25     LinkedHashSet<String> testCacheItems = new LinkedHashSet<String>();
26     for (int x = 0; x < 10; x++)
27     {
28       testCacheItems.add("TestCache" + x);
29     }
30     appCache.putCache(TEST_CACHE_KEY, testCacheItems);
31     appCache.persistCache(TEST_CACHE_KEY);
32   }
33
34   @Test(groups = { "Functional" })
35   public void appCacheTest()
36   {
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);
46   }
47
48   @Test(groups = { "Functional" })
49   public void appCacheLimitTest()
50   {
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);
58   }
59
60 }