JAL-3746 apply copyright to tests
[jalview.git] / test / jalview / io / cache / AppCacheTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.io.cache;
22
23 import java.util.LinkedHashSet;
24
25 import org.testng.Assert;
26 import org.testng.annotations.BeforeClass;
27 import org.testng.annotations.Test;
28
29 public class AppCacheTest
30 {
31   private AppCache appCache;
32
33   private static final String TEST_CACHE_KEY = "CACHE.UNIT_TEST";
34
35   private static final String TEST_FAKE_CACHE_KEY = "CACHE.UNIT_TEST_FAKE";
36
37   @BeforeClass(alwaysRun = true)
38   public void setUpCache()
39   {
40     appCache = AppCache.getInstance();
41   }
42
43   public void generateTestCacheItems()
44   {
45     LinkedHashSet<String> testCacheItems = new LinkedHashSet<String>();
46     for (int x = 0; x < 10; x++)
47     {
48       testCacheItems.add("TestCache" + x);
49     }
50     appCache.putCache(TEST_CACHE_KEY, testCacheItems);
51     appCache.persistCache(TEST_CACHE_KEY);
52   }
53
54   @Test(groups = { "Functional" })
55   public void appCacheTest()
56   {
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);
66   }
67
68   @Test(groups = { "Functional" })
69   public void appCacheLimitTest()
70   {
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);
78   }
79
80 }