Clover icon

Magnolia Imaging Module 3.2.3

  1. Project Clover database Fri Nov 6 2015 14:54:03 CET
  2. Package info.magnolia.imaging.setup

File ImagingModuleVersionHandlerTest.java

 

Code metrics

0
45
13
1
221
115
13
0.29
3.46
13
1

Classes

Class Line # Actions
ImagingModuleVersionHandlerTest 68 45 0% 13 0
1.0100%
 

Contributing tests

This file is covered by 8 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.imaging.setup;
35   
36    import static info.magnolia.test.hamcrest.NodeMatchers.*;
37    import static org.hamcrest.CoreMatchers.is;
38    import static org.hamcrest.MatcherAssert.assertThat;
39    import static org.junit.Assert.assertTrue;
40   
41    import info.magnolia.cms.security.MgnlRoleManager;
42    import info.magnolia.cms.security.Permission;
43    import info.magnolia.cms.security.SecuritySupport;
44    import info.magnolia.cms.security.SecuritySupportImpl;
45    import info.magnolia.context.MgnlContext;
46    import info.magnolia.imaging.functions.ImagingTemplatingFunctions;
47    import info.magnolia.jcr.util.NodeTypes;
48    import info.magnolia.jcr.util.NodeUtil;
49    import info.magnolia.module.ModuleVersionHandler;
50    import info.magnolia.module.ModuleVersionHandlerTestCase;
51    import info.magnolia.module.model.Version;
52    import info.magnolia.repository.RepositoryConstants;
53    import info.magnolia.test.ComponentsTestUtil;
54   
55    import java.util.Arrays;
56    import java.util.List;
57   
58    import javax.jcr.Node;
59    import javax.jcr.RepositoryException;
60    import javax.jcr.Session;
61   
62    import org.junit.Before;
63    import org.junit.Test;
64   
65    /**
66    * Tests for {@link ImagingModuleVersionHandler}.
67    */
 
68    public class ImagingModuleVersionHandlerTest extends ModuleVersionHandlerTestCase {
69   
70    private Session userRolesSession;
71    private Session configSession;
72   
 
73  8 toggle @Override
74    @Before
75    public void setUp() throws Exception {
76  8 super.setUp();
77  8 SecuritySupportImpl securitySupport = new SecuritySupportImpl();
78  8 ComponentsTestUtil.setInstance(SecuritySupport.class, securitySupport);
79  8 MgnlRoleManager roleManager = new MgnlRoleManager();
80  8 securitySupport.setRoleManager(roleManager);
81  8 roleManager.createRole("imaging-base");
82   
83  8 userRolesSession = MgnlContext.getJCRSession(RepositoryConstants.USER_ROLES);
84  8 configSession = MgnlContext.getJCRSession(RepositoryConstants.CONFIG);
85   
86  8 addSupportForSetupModuleRepositoriesTask("imaging");
87   
88    // Setup the filters node to prevent error msg
89  8 setupConfigNode("/server/filters/servlets");
90    }
91   
 
92  8 toggle @Override
93    protected String getModuleDescriptorPath() {
94  8 return "/META-INF/magnolia/imaging.xml";
95    }
96   
 
97  8 toggle @Override
98    protected ModuleVersionHandler newModuleVersionHandlerForTests() {
99  8 return new ImagingModuleVersionHandler();
100    }
101   
 
102  8 toggle @Override
103    protected List<String> getModuleDescriptorPathsForTests() {
104    // Super implementation returns this module's descriptor.
105    // We override this because version-handler logic doesn't depend on the whole module dependency cascade
106    // (only needs to be a non-empty list of existing module descriptors, so we pick the most basic one).
107  8 return Arrays.asList(
108    "/META-INF/magnolia/core.xml"
109    );
110    }
111   
 
112  1 toggle @Test
113    public void testUpdateFrom31AddsPermissionsForImagingBaseRole() throws Exception {
114    // GIVEN
115   
116    // WHEN
117  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("3.1"));
118   
119    // THEN
120  1 assertThatRoleHasReadPermissionToItself();
121    }
122   
 
123  1 toggle @Test
124    public void testCleanInstallAddsPermissionsForImagingBaseRole() throws Exception {
125    // GIVEN
126   
127    // WHEN
128  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null);
129   
130    // THEN
131  1 assertThatRoleHasReadPermissionToItself();
132    }
133   
 
134  2 toggle private void assertThatRoleHasReadPermissionToItself() throws RepositoryException {
135  2 assertThat(userRolesSession.itemExists("/imaging-base/acl_userroles/0"), is(true));
136  2 Node role = userRolesSession.getNode("/imaging-base/acl_userroles/0");
137  2 assertThat(role, hasProperty("path", "/imaging-base"));
138  2 assertThat(role, hasProperty("permissions", Permission.READ));
139    }
140   
 
141  1 toggle @Test
142    public void installationRegistersImagingTemplatingFunctionsAsFreemarkerRendererCtxAttribute() throws Exception {
143    // GIVEN
144  1 NodeUtil.createPath(configSession.getRootNode(), "/modules/rendering/renderers/freemarker", NodeTypes.ContentNode.NAME);
145   
146    // WHEN
147  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null);
148   
149    // THEN
150  1 assertTrue(configSession.nodeExists("/modules/rendering/renderers/freemarker/contextAttributes/imgfn"));
151   
152  1 Node imagingFunctionsNode = configSession.getNode("/modules/rendering/renderers/freemarker/contextAttributes/imgfn");
153  1 assertThat(imagingFunctionsNode, hasProperty("componentClass", ImagingTemplatingFunctions.class.getName()));
154  1 assertThat(imagingFunctionsNode, hasProperty("name", "imgfn"));
155    }
156   
 
157  1 toggle @Test
158    public void updateTo32RegistersImagingTemplatingFunctionsAsFreemarkerRendererCtxAttribute() throws Exception {
159    // GIVEN
160  1 NodeUtil.createPath(configSession.getRootNode(), "/modules/rendering/renderers/freemarker", NodeTypes.ContentNode.NAME);
161   
162    // WHEN
163  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("3.1.1"));
164   
165    // THEN
166  1 assertTrue(configSession.nodeExists("/modules/rendering/renderers/freemarker/contextAttributes/imgfn"));
167   
168  1 Node imagingFunctionsNode = configSession.getNode("/modules/rendering/renderers/freemarker/contextAttributes/imgfn");
169  1 assertThat(imagingFunctionsNode, hasProperty("componentClass", ImagingTemplatingFunctions.class.getName()));
170  1 assertThat(imagingFunctionsNode, hasProperty("name", "imgfn"));
171    }
172   
 
173  1 toggle @Test
174    public void updateTo32InstallsNewDefaultImageGenerator() throws Exception {
175    // GIVEN
176  1 NodeUtil.createPath(configSession.getRootNode(), "/modules/imaging/config/generators", NodeTypes.ContentNode.NAME);
177   
178    // WHEN
179  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("3.1.1"));
180   
181    // THEN
182  1 assertTrue(configSession.nodeExists("/modules/imaging/config/generators/default"));
183    }
184   
 
185  1 toggle @Test
186    public void updateTo32InstallsTemplatingFunctions() throws Exception {
187    // GIVEN
188  1 setupConfigNode("/modules/rendering/renderers/freemarker/contextAttributes");
189   
190    // WHEN
191  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("3.1.1"));
192   
193    // THEN
194  1 assertThat(configSession.getNode("/modules/rendering/renderers/freemarker/contextAttributes"), hasNode("imgfn"));
195    }
196   
 
197  1 toggle @Test
198    public void updateTo32ExcludesImagingFromFlushCache() throws Exception {
199    // GIVEN
200  1 Node workspacesExcludedFromFlushCachePolicy = NodeUtil.createPath(configSession.getRootNode(), "/" + ExcludeWorkspacesFromFlushCachePolicy.CACHE_CONFIGURATION_PATH + "defaultPageCache/" + ExcludeWorkspacesFromFlushCachePolicy.EXCLUDED_WORKSPACES_CONFIG_PATH, NodeTypes.Content.NAME);
201   
202    // WHEN
203  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("3.1.1"));
204   
205    // THEN
206  1 assertThat(workspacesExcludedFromFlushCachePolicy, hasProperty("imaging"));
207    }
208   
 
209  1 toggle @Test
210    public void cleanInstall() throws Exception {
211    // GIVEN
212  1 Node workspacesExcludedFromFlushCachePolicy = NodeUtil.createPath(configSession.getRootNode(), "/" + ExcludeWorkspacesFromFlushCachePolicy.CACHE_CONFIGURATION_PATH + "defaultPageCache/" + ExcludeWorkspacesFromFlushCachePolicy.EXCLUDED_WORKSPACES_CONFIG_PATH, NodeTypes.Content.NAME);
213   
214    // WHEN
215  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null);
216   
217    // THEN
218  1 assertThat(workspacesExcludedFromFlushCachePolicy, hasProperty("imaging"));
219    }
220   
221    }