@Test public void testPutSameItemTwice() throws CacheException { cacheService.store(TEST1, "sameItem", "value"); assertEquals("first element not added", 1, cacheService.getCacheSize(TEST1)); cacheService.store(TEST1, "sameItem", "value"); assertEquals("element added twice", 1, cacheService.getCacheSize(TEST1)); }
@Test public void testClearAllCache() throws CacheException { cacheService.store(TEST1, "test1", "test1"); assertTrue("cache was not empty", cacheService.getCacheSize(TEST1) > 0); cacheService.clearAll(); assertTrue("cache was not cleared", cacheService.getCacheSize(TEST1) == 0); }
@Test public void testPutSimpleObjectInCache() throws CacheException { final int cacheSize = cacheService.getCacheSize(TEST1); final String myObject = "testObject"; cacheService.store(TEST1, "test", myObject); assertEquals("cache size did not increased", cacheSize + 1, cacheService.getCacheSize(TEST1)); }
@Test public void testUpdateElementInCache() throws CacheException { cacheService.store(TEST1, "sameItem2", "value1"); assertEquals("first element not added", 1, cacheService.getCacheSize(TEST1)); cacheService.store(TEST1, "sameItem2", "value2"); assertEquals("element added 2 times", 1, cacheService.getCacheSize(TEST1)); assertEquals("element was not updated", "value2", cacheService.get(TEST1, "sameItem2")); }
@Test public void testPutComplexObjectInCache() throws CacheException { final int cacheSize = cacheService.getCacheSize(TEST1); final ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>(); final HashMap<String, String> map = new HashMap<String, String>(); map.put("bpm", "bonita"); list.add(map); cacheService.store(TEST1, "complex", list); assertEquals("cache size did not increased", cacheSize + 1, cacheService.getCacheSize(TEST1)); }
@Test public void testPutLotOfItemsWithOverflow() throws CacheException { final int cacheSize = cacheService.getCacheSize(TEST1); final int j = 20000; for (int i = 0; i < j; i++) { cacheService.store(TEST1, "testLotOfItems" + i, "value" + i); } assertEquals( "Not all elements were added with the overflow", cacheSize + j, cacheService.getCacheSize(TEST1)); }
@Test public void testPutLotOfItems() throws CacheException { cacheService.store(TEST2, "testLotOfItems0", "value0"); final int j = 20000; for (int i = 1; i <= j; i++) { cacheService.store(TEST2, "testLotOfItems" + i, "value" + i); } assertEquals("Not all elements were added", j + 1, cacheService.getCacheSize(TEST2)); }
@Test public void testPutInDifferentCache() throws CacheException { final int cacheSize = cacheService.getCacheSize(TEST1); cacheService.store(TEST2, "testdifferentCache", "value"); assertEquals("element added in the wrong cache", cacheSize, cacheService.getCacheSize(TEST1)); }
@Test public void testPutNullInCacheShouldWork() throws CacheException { cacheService.store(TEST1, "test2", null); assertEquals("Null should be added to the cache", 1, cacheService.getCacheSize(TEST1)); assertTrue("Null value can't be put", cacheService.get(TEST1, "test2") == null); }