1 /***
2 * Copyright 2003-2010 Terracotta, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package net.sf.ehcache.constructs;
18
19 import java.util.Arrays;
20 import java.util.List;
21
22 import org.junit.Test;
23
24 import junit.framework.TestCase;
25 import net.sf.ehcache.CacheManager;
26 import net.sf.ehcache.constructs.MockDecoratorFactory.MockDecoratorFactoryCache;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /***
31 * @author Abhishek Sanoujam
32 */
33 public class CacheDecoratorFactoryTest extends TestCase {
34
35 private static final Logger LOG = LoggerFactory.getLogger(CacheDecoratorFactoryTest.class);
36
37 @Test
38 public void testCacheDecoratorFactory() {
39 CacheManager cacheManager = new CacheManager(getClass().getResourceAsStream("/ehcache-decorator-test.xml"));
40 List<String> cacheNames = Arrays.asList(cacheManager.getCacheNames());
41 LOG.info("" + cacheNames);
42
43 assertEquals(12, cacheNames.size());
44
45 assertTrue(cacheNames.contains("noDecoratorCache"));
46 assertTrue(cacheNames.contains("oneDecoratorCache"));
47 assertTrue(cacheNames.contains("oneDecoratorFirst"));
48 assertTrue(cacheNames.contains("twoDecoratorCache"));
49 assertTrue(cacheNames.contains("twoDecoratorFirst"));
50 assertTrue(cacheNames.contains("twoDecoratorSecond"));
51 assertTrue(cacheNames.contains("fiveDecoratorCache"));
52 assertTrue(cacheNames.contains("fiveDecoratorFirst"));
53 assertTrue(cacheNames.contains("fiveDecoratorSecond"));
54 assertTrue(cacheNames.contains("fiveDecoratorThird"));
55 assertTrue(cacheNames.contains("fiveDecoratorFourth"));
56 assertTrue(cacheNames.contains("fiveDecoratorFifth"));
57
58 }
59
60 @Test
61 public void testCacheDecoratorFactoryProperties() {
62 CacheManager cacheManager = new CacheManager(getClass().getResourceAsStream("/ehcache-decorator-test.xml"));
63 List<String> cacheNames = Arrays.asList(cacheManager.getCacheNames());
64 assertEquals(12, cacheNames.size());
65
66 MockDecoratorFactoryCache cache = (MockDecoratorFactoryCache) cacheManager.getEhcache("oneDecoratorFirst");
67 assertEquals("oneFirst", cache.getProperties().getProperty("someKey"));
68
69 cache = (MockDecoratorFactoryCache) cacheManager.getEhcache("twoDecoratorFirst");
70 assertEquals("twoFirst", cache.getProperties().getProperty("someKey"));
71
72 cache = (MockDecoratorFactoryCache) cacheManager.getEhcache("twoDecoratorSecond");
73 assertEquals("twoSecond", cache.getProperties().getProperty("someKey"));
74
75 cache = (MockDecoratorFactoryCache) cacheManager.getEhcache("fiveDecoratorFirst");
76 assertEquals("fiveFirst", cache.getProperties().getProperty("someKey"));
77
78 cache = (MockDecoratorFactoryCache) cacheManager.getEhcache("fiveDecoratorSecond");
79 assertEquals("fiveSecond", cache.getProperties().getProperty("someKey"));
80
81 cache = (MockDecoratorFactoryCache) cacheManager.getEhcache("fiveDecoratorThird");
82 assertEquals("fiveThird", cache.getProperties().getProperty("someKey"));
83
84 cache = (MockDecoratorFactoryCache) cacheManager.getEhcache("fiveDecoratorFourth");
85 assertEquals("fiveFourth", cache.getProperties().getProperty("someKey"));
86
87 cache = (MockDecoratorFactoryCache) cacheManager.getEhcache("fiveDecoratorFifth");
88 assertEquals("fiveFifth", cache.getProperties().getProperty("someKey"));
89
90 }
91 }