Clover icon

Magnolia Resources Module 2.4.2

  1. Project Clover database Fri Nov 6 2015 16:15:26 CET
  2. Package info.magnolia.module.resources.setup

File ResourcesModuleVersionHandlerTest.java

 

Code metrics

0
46
14
1
214
112
14
0.3
3.29
14
1

Classes

Class Line # Actions
ResourcesModuleVersionHandlerTest 56 46 0% 14 0
1.0100%
 

Contributing tests

This file is covered by 9 tests. .

Source view

1    /**
2    * This file Copyright (c) 2014-2015 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.resources.setup;
35   
36    import static info.magnolia.test.hamcrest.NodeMatchers.hasProperty;
37    import static org.hamcrest.core.AllOf.allOf;
38    import static org.hamcrest.core.Is.is;
39    import static org.junit.Assert.*;
40   
41    import info.magnolia.context.MgnlContext;
42    import info.magnolia.module.ModuleVersionHandler;
43    import info.magnolia.module.ModuleVersionHandlerTestCase;
44    import info.magnolia.module.model.Version;
45    import info.magnolia.repository.RepositoryConstants;
46   
47    import java.util.Arrays;
48    import java.util.List;
49   
50    import javax.jcr.Node;
51    import javax.jcr.Session;
52   
53    import org.junit.Before;
54    import org.junit.Test;
55   
 
56    public class ResourcesModuleVersionHandlerTest extends ModuleVersionHandlerTestCase {
57   
58    private Session configSession;
59   
 
60  9 toggle @Before
61    @Override
62    public void setUp() throws Exception {
63  9 super.setUp();
64  9 this.configSession = MgnlContext.getJCRSession(RepositoryConstants.CONFIG);
65  9 setupConfigNode("/server/filters");
66  9 setupConfigNode("/server/filters/servlets");
67    }
68   
 
69  9 toggle @Override
70    protected String getModuleDescriptorPath() {
71  9 return "/META-INF/magnolia/resources.xml";
72    }
73   
 
74  9 toggle @Override
75    protected List<String> getModuleDescriptorPathsForTests() {
76  9 return Arrays.asList("/META-INF/magnolia/core.xml", "/META-INF/magnolia/resource-loader.xml");
77    }
78   
 
79  9 toggle @Override
80    protected String[] getExtraWorkspaces() {
81  9 return new String[] { "resources" };
82    }
83   
 
84  9 toggle @Override
85    protected ModuleVersionHandler newModuleVersionHandlerForTests() {
86  9 return new ResourcesModuleVersionHandler();
87    }
88   
 
89  1 toggle @Test
90    public void testUpgradeTo201BootstrapsCommands() throws Exception {
91    // GIVEN
92  1 setupConfigNode("/modules/resources");
93   
94    // WHEN
95  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.0.0"));
96   
97    // THEN
98  1 assertTrue(configSession.nodeExists("/modules/resources/commands/resources"));
99    }
100   
 
101  1 toggle @Test
102    public void testUpgradeTo201RemovesVersionCommand() throws Exception {
103    // GIVEN
104  1 setupConfigNode("/modules/resources/commands/resources/versionResources/version");
105   
106    // WHEN
107  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.0.0"));
108   
109    // THEN
110  1 assertFalse(configSession.nodeExists("/modules/resources/commands/resources/versionResources/version"));
111    }
112   
 
113  1 toggle @Test
114    public void testUpgradeFrom201WhenExtractCommentCommandClassIsInResources() throws Exception {
115    // GIVEN
116  1 setupConfigProperty("/modules/resources/commands/resources/versionResources/extractComment", "class", "info.magnolia.module.resources.commands.ExtractCommentCommand");
117   
118    // WHEN
119  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.0.1"));
120   
121    // THEN
122  1 final String commandClass = configSession.getNode("/modules/resources/commands/resources/versionResources/extractComment").getProperty("class").getString();
123  1 assertEquals("info.magnolia.commands.impl.ExtractCommentCommand", commandClass);
124    }
125   
 
126  1 toggle @Test
127    public void testUpgradeFrom201WhenExtractCommentCommandClassIsInAdmininterface() throws Exception {
128    // GIVEN
129  1 setupConfigProperty("/modules/resources/commands/resources/versionResources/extractComment", "class", "info.magnolia.module.admininterface.commands.ExtractCommentCommand");
130   
131    // WHEN
132  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.0.1"));
133   
134    // THEN
135  1 final String commandClass = configSession.getNode("/modules/resources/commands/resources/versionResources/extractComment").getProperty("class").getString();
136  1 assertEquals("info.magnolia.commands.impl.ExtractCommentCommand", commandClass);
137    }
138   
 
139  1 toggle @Test
140    public void testUpgradeFrom201WhenCustomExtractCommentCommandClass() throws Exception {
141    // GIVEN
142  1 final String customCommand = "my.package.name.CustomExtractCommentCommand";
143  1 setupConfigProperty("/modules/resources/commands/resources/versionResources/extractComment", "class", customCommand);
144   
145    // WHEN
146  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.0.1"));
147   
148    // THEN
149  1 final String commandClass = configSession.getNode("/modules/resources/commands/resources/versionResources/extractComment").getProperty("class").getString();
150  1 assertEquals(customCommand, commandClass);
151    }
152   
 
153  1 toggle @Test
154    public void testUpgradeFrom15() throws Exception {
155    // GIVEN
156  1 this.setupConfigNode("/modules/resources/renderers/textResource/contextAttributes/cms/");
157   
158    // WHEN
159  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("1.5"));
160   
161    // THEN no errors
162    }
163   
 
164  1 toggle @Test
165    public void upgradeTo24InstallsMappingForNewResourceServlet() throws Exception {
166    // GIVEN
167  1 this.setupConfigNode("/server/filters/servlets/ClasspathSpoolServlet");
168   
169    // WHEN
170  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.3"));
171   
172    // THEN
173  1 assertFalse(configSession.itemExists("/server/filters/servlets/ClasspathSpoolServlet"));
174  1 assertTrue(configSession.itemExists("/server/filters/servlets/ResourcesServlet"));
175  1 assertTrue(configSession.itemExists("/server/filters/servlets/ResourcesServlet/mappings/-.resources--"));
176   
177  1 Node servletNode = configSession.getNode("/server/filters/servlets/ResourcesServlet");
178  1 assertThat(servletNode, allOf(
179    hasProperty("class", "info.magnolia.cms.filters.ServletDispatchingFilter"),
180    hasProperty("enabled", is(true)),
181    hasProperty("servletClass", "info.magnolia.module.resources.ResourcesServlet"),
182    hasProperty("servletName", "ResourcesServlet")));
183   
184  1 Node mappingNode = configSession.getNode("/server/filters/servlets/ResourcesServlet/mappings/-.resources--");
185  1 assertThat(mappingNode, hasProperty("pattern", "/.resources/*"));
186    }
187   
 
188  1 toggle @Test
189    public void upgradeTo242ChangesJavascriptContentType() throws Exception {
190    // GIVEN
191  1 this.setupConfigProperty("/modules/resources/templates/js", "contentType", "application/x-javascript");
192  1 this.setupConfigProperty("/modules/resources/templates/processedJs", "contentType", "application/x-javascript");
193   
194    // WHEN
195  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.4"));
196   
197    // THEN
198  1 assertEquals("application/javascript", configSession.getNode("/modules/resources/templates/js").getProperty("contentType").getString());
199  1 assertEquals("application/javascript", configSession.getNode("/modules/resources/templates/processedJs").getProperty("contentType").getString());
200    }
201   
 
202  1 toggle @Test
203    public void upgradeFrom241RemoveAppLauncherConfigForInPlaceTemplating() throws Exception {
204    // GIVEN
205  1 setupConfigNode(ResourcesModuleVersionHandler.INPLACE_TEMPLATING_APP_LAUNCHER_CONFIG);
206   
207    // WHEN
208  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.4.1"));
209   
210    // THEN
211  1 assertFalse(configSession.itemExists(ResourcesModuleVersionHandler.INPLACE_TEMPLATING_APP_LAUNCHER_CONFIG));
212    }
213   
214    }