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.config.nonstop;
18
19 import java.util.Arrays;
20 import java.util.List;
21
22 import junit.framework.Assert;
23 import junit.framework.TestCase;
24 import net.sf.ehcache.CacheManager;
25 import net.sf.ehcache.Ehcache;
26 import net.sf.ehcache.config.TerracottaConfiguration;
27 import net.sf.ehcache.terracotta.ClusteredInstanceFactory;
28 import net.sf.ehcache.terracotta.TerracottaUnitTesting;
29
30 import org.mockito.Mockito;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class NonstopInheritsDefaultConfigTest extends TestCase {
35
36 private static final Logger LOGGER = LoggerFactory.getLogger(NonstopInheritsDefaultConfigTest.class);
37
38 public void testNonstopConfigInheritsDefaultConfig() throws Exception {
39 if (Boolean.valueOf("true")) {
40 LOGGER.warn("THIS TEST IS CURRENTLY DISABLED");
41 return;
42 }
43 ClusteredInstanceFactory mockFactory = Mockito.mock(ClusteredInstanceFactory.class);
44 TerracottaUnitTesting.setupTerracottaTesting(mockFactory);
45
46 CacheManager cacheManager = new CacheManager(NonstopInheritsDefaultConfigTest.class
47 .getResourceAsStream("/nonstop/nonstop-inherits-default-config-test.xml"));
48
49 List<String> cacheNames = Arrays.asList(cacheManager.getCacheNames());
50 LOGGER.info(cacheNames.toString());
51 Assert.assertEquals(2, cacheNames.size());
52 Assert.assertTrue(cacheNames.contains("defaultConfigCache"));
53 Assert.assertTrue(cacheNames.contains("overridesDefaultConfigCache"));
54
55 Ehcache defaultConfigCache = cacheManager.getEhcache("defaultConfigCache");
56 Ehcache overridesDefaultConfigCache = cacheManager.getEhcache("overridesDefaultConfigCache");
57
58 TerracottaConfiguration defaultTC = defaultConfigCache.getCacheConfiguration().getTerracottaConfiguration();
59 Assert.assertNotNull(defaultTC);
60 Assert.assertEquals(false, defaultTC.isClustered());
61 Assert.assertNotNull(defaultTC.getNonstopConfiguration());
62 Assert.assertEquals(12345, defaultTC.getNonstopConfiguration().getTimeoutMillis());
63
64 }
65
66 }