2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.io.cache;
23 import java.util.LinkedHashSet;
25 import org.testng.Assert;
26 import org.testng.annotations.BeforeClass;
27 import org.testng.annotations.Test;
29 public class AppCacheTest
31 private AppCache appCache;
33 private static final String TEST_CACHE_KEY = "CACHE.UNIT_TEST";
35 private static final String TEST_FAKE_CACHE_KEY = "CACHE.UNIT_TEST_FAKE";
37 @BeforeClass(alwaysRun = true)
38 public void setUpCache()
40 appCache = AppCache.getInstance();
43 public void generateTestCacheItems()
45 LinkedHashSet<String> testCacheItems = new LinkedHashSet<String>();
46 for (int x = 0; x < 10; x++)
48 testCacheItems.add("TestCache" + x);
50 appCache.putCache(TEST_CACHE_KEY, testCacheItems);
51 appCache.persistCache(TEST_CACHE_KEY);
54 @Test(groups = { "Functional" })
55 public void appCacheTest()
57 LinkedHashSet<String> cacheItems = appCache
58 .getAllCachedItemsFor(TEST_FAKE_CACHE_KEY);
59 Assert.assertEquals(cacheItems.size(), 0);
60 generateTestCacheItems();
61 cacheItems = appCache.getAllCachedItemsFor(TEST_CACHE_KEY);
62 Assert.assertEquals(cacheItems.size(), 10);
63 appCache.deleteCacheItems(TEST_CACHE_KEY);
64 cacheItems = appCache.getAllCachedItemsFor(TEST_CACHE_KEY);
65 Assert.assertEquals(cacheItems.size(), 0);
68 @Test(groups = { "Functional" })
69 public void appCacheLimitTest()
71 String limit = appCache.getCacheLimit(TEST_CACHE_KEY);
72 Assert.assertEquals(limit, "99");
73 limit = String.valueOf(appCache.updateCacheLimit(TEST_CACHE_KEY, 20));
74 Assert.assertEquals(limit, "20");
75 limit = appCache.getCacheLimit(TEST_CACHE_KEY);
76 Assert.assertEquals(limit, "20");
77 appCache.updateCacheLimit(TEST_CACHE_KEY, 99);