Clover icon

Magnolia Module EhCache 5.5.9

  1. Project Clover database Mon Nov 25 2019 16:52:57 CET
  2. Package info.magnolia.module.cache.setup

File EhCacheModuleVersionHandlerTest.java

 

Code metrics

0
43
6
1
152
87
6
0.14
7.17
6
1

Classes

Class Line # Actions
EhCacheModuleVersionHandlerTest 63 43 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /**
2    * This file Copyright (c) 2015-2018 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.module.cache.setup;
35   
36    import static info.magnolia.test.hamcrest.NodeMatchers.*;
37    import static org.hamcrest.CoreMatchers.not;
38    import static org.junit.Assert.assertEquals;
39    import static org.junit.Assert.assertThat;
40   
41    import info.magnolia.context.MgnlContext;
42    import info.magnolia.jcr.util.NodeTypes;
43    import info.magnolia.jcr.util.NodeUtil;
44    import info.magnolia.module.InstallContext;
45    import info.magnolia.module.ModuleVersionHandler;
46    import info.magnolia.module.ModuleVersionHandlerTestCase;
47    import info.magnolia.module.cache.ehcache.EhCacheFactory;
48    import info.magnolia.repository.RepositoryConstants;
49   
50    import java.util.Arrays;
51    import java.util.List;
52   
53    import javax.jcr.Node;
54    import javax.jcr.NodeIterator;
55    import javax.jcr.Session;
56   
57    import org.junit.Before;
58    import org.junit.Test;
59   
60    /**
61    * Test class for {@link EhCacheModuleVersionHandler}.
62    */
 
63    public class EhCacheModuleVersionHandlerTest extends ModuleVersionHandlerTestCase {
64   
65    private Session session;
66   
 
67  2 toggle @Override
68    protected String getModuleDescriptorPath() {
69  2 return "/META-INF/magnolia/ehcache.xml";
70    }
71   
 
72  2 toggle @Override
73    protected ModuleVersionHandler newModuleVersionHandlerForTests() {
74  2 return new EhCacheModuleVersionHandler();
75    }
76   
 
77  2 toggle @Override
78    protected List<String> getModuleDescriptorPathsForTests() {
79  2 return Arrays.asList(
80    "/META-INF/magnolia/core.xml"
81    );
82    }
83   
 
84  2 toggle @Override
85    @Before
86    public void setUp() throws Exception {
87  2 super.setUp();
88  2 session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG);
89    }
90   
 
91  1 toggle @Test
92    public void upgradeFromCacheModule53() throws Exception {
93    // GIVEN
94  1 Node moduleCfgNode = NodeUtil.createPath(session.getRootNode(), "/modules/cache/config/", NodeTypes.ContentNode.NAME);
95  1 final Node cacheFactory = NodeUtil.createPath(session.getRootNode(), EhCacheModuleVersionHandler.EHCACHE_FACTORY_NODE, NodeTypes.ContentNode.NAME);
96  1 cacheFactory.setProperty("class", EhCacheFactory.class.getName());
97  1 final Node defaultCacheConfiguration = cacheFactory.addNode("defaultCacheConfiguration", NodeTypes.ContentNode.NAME);
98  1 defaultCacheConfiguration.setProperty("overflowToDisk", true);
99  1 defaultCacheConfiguration.setProperty("diskPersistent", false); // TODO MGNLCACHE-67 this should convert to localTempSwap
100  1 defaultCacheConfiguration.setProperty("diskSpoolBufferSizeMB", "50"); // not default, on purpose
101   
102  1 final Node cacheContent = NodeUtil.createPath(moduleCfgNode, "configurations/default/executors/store/cacheContent/", NodeTypes.ContentNode.NAME);
103  1 cacheContent.addNode("isCacheableVoters", NodeTypes.ContentNode.NAME);
104   
105    // WHEN
106  1 InstallContext installContext = executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null);
107   
108    // THEN
109    // ehcache default cache settings
110  1 assertThat(cacheFactory, not(hasNode("defaultCacheConfiguration")));
111  1 assertThat(cacheFactory, hasNode("caches"));
112  1 assertThat(cacheFactory.getNode("caches"), hasNode("default"));
113  1 final Node newDefaultCacheCfg = cacheFactory.getNode("caches").getNode("default");
114  1 assertThat(newDefaultCacheCfg, hasProperty("diskSpoolBufferSizeMB", "50"));
115  1 assertThat(newDefaultCacheCfg, not(hasProperty("diskPersistent")));
116  1 assertThat(newDefaultCacheCfg, not(hasProperty("overflowToDisk")));
117  1 assertThat(newDefaultCacheCfg, hasNode("persistence"));
118  1 assertThat(newDefaultCacheCfg.getNode("persistence"), hasProperty("strategy", "localTempSwap"));
119  1 assertThat(newDefaultCacheCfg.getNode("persistence"), hasProperty("synchronousWrites", "false"));
120   
121  1 assertNoMessages(installContext);
122    }
123   
 
124  1 toggle @Test
125    public void cleanInstall() throws Exception {
126    // GIVEN
127  1 setupConfigNode("modules/cache/config/cacheFactory/delegateFactories/memcached");
128   
129    // WHEN
130  1 InstallContext installContext = executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null);
131   
132    // THEN
133    // ehcache default settings
134  1 assertThat(session.getRootNode(), hasNode("modules/cache/config/cacheFactory/delegateFactories/ehcache"));
135  1 final Node cacheFactory = session.getNode("/modules/cache/config/cacheFactory/delegateFactories/ehcache");
136  1 assertThat(cacheFactory, not(hasNode("defaultCacheConfiguration")));
137  1 assertThat(cacheFactory, hasNode("caches"));
138  1 assertThat(cacheFactory.getNode("caches"), hasNode("default"));
139  1 final Node newDefaultCacheCfg = cacheFactory.getNode("caches").getNode("default");
140  1 assertThat(newDefaultCacheCfg, hasProperty("diskSpoolBufferSizeMB", "30"));
141  1 assertThat(newDefaultCacheCfg, hasProperty("diskExpiryThreadIntervalSeconds", "120"));
142  1 assertThat(newDefaultCacheCfg, hasProperty("maxElementsInMemory", "10000"));
143  1 assertThat(newDefaultCacheCfg, hasNode("persistence"));
144  1 assertThat(newDefaultCacheCfg.getNode("persistence"), hasProperty("strategy", "localTempSwap"));
145  1 assertThat(newDefaultCacheCfg.getNode("persistence"), hasProperty("synchronousWrites", "false"));
146   
147  1 final NodeIterator delegateFactories = session.getNode("/modules/cache/config/cacheFactory/delegateFactories/").getNodes();
148  1 assertEquals("memcached", delegateFactories.nextNode().getName());
149   
150  1 assertNoMessages(installContext);
151    }
152    }