1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
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 |
|
@link |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (58) |
Complexity: 13 |
Complexity Density: 0.29 |
|
68 |
|
public class ImagingModuleVersionHandlerTest extends ModuleVersionHandlerTestCase { |
69 |
|
|
70 |
|
private Session userRolesSession; |
71 |
|
private Session configSession; |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
73 |
8 |
@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 |
|
|
89 |
8 |
setupConfigNode("/server/filters/servlets"); |
90 |
|
} |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
8 |
@Override... |
93 |
|
protected String getModuleDescriptorPath() { |
94 |
8 |
return "/META-INF/magnolia/imaging.xml"; |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
8 |
@Override... |
98 |
|
protected ModuleVersionHandler newModuleVersionHandlerForTests() { |
99 |
8 |
return new ImagingModuleVersionHandler(); |
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
8 |
@Override... |
103 |
|
protected List<String> getModuleDescriptorPathsForTests() { |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
8 |
return Arrays.asList( |
108 |
|
"/META-INF/magnolia/core.xml" |
109 |
|
); |
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
112 |
1 |
@Test... |
113 |
|
public void testUpdateFrom31AddsPermissionsForImagingBaseRole() throws Exception { |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("3.1")); |
118 |
|
|
119 |
|
|
120 |
1 |
assertThatRoleHasReadPermissionToItself(); |
121 |
|
} |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
123 |
1 |
@Test... |
124 |
|
public void testCleanInstallAddsPermissionsForImagingBaseRole() throws Exception { |
125 |
|
|
126 |
|
|
127 |
|
|
128 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null); |
129 |
|
|
130 |
|
|
131 |
1 |
assertThatRoleHasReadPermissionToItself(); |
132 |
|
} |
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
134 |
2 |
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
141 |
1 |
@Test... |
142 |
|
public void installationRegistersImagingTemplatingFunctionsAsFreemarkerRendererCtxAttribute() throws Exception { |
143 |
|
|
144 |
1 |
NodeUtil.createPath(configSession.getRootNode(), "/modules/rendering/renderers/freemarker", NodeTypes.ContentNode.NAME); |
145 |
|
|
146 |
|
|
147 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null); |
148 |
|
|
149 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
157 |
1 |
@Test... |
158 |
|
public void updateTo32RegistersImagingTemplatingFunctionsAsFreemarkerRendererCtxAttribute() throws Exception { |
159 |
|
|
160 |
1 |
NodeUtil.createPath(configSession.getRootNode(), "/modules/rendering/renderers/freemarker", NodeTypes.ContentNode.NAME); |
161 |
|
|
162 |
|
|
163 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("3.1.1")); |
164 |
|
|
165 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
173 |
1 |
@Test... |
174 |
|
public void updateTo32InstallsNewDefaultImageGenerator() throws Exception { |
175 |
|
|
176 |
1 |
NodeUtil.createPath(configSession.getRootNode(), "/modules/imaging/config/generators", NodeTypes.ContentNode.NAME); |
177 |
|
|
178 |
|
|
179 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("3.1.1")); |
180 |
|
|
181 |
|
|
182 |
1 |
assertTrue(configSession.nodeExists("/modules/imaging/config/generators/default")); |
183 |
|
} |
184 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
185 |
1 |
@Test... |
186 |
|
public void updateTo32InstallsTemplatingFunctions() throws Exception { |
187 |
|
|
188 |
1 |
setupConfigNode("/modules/rendering/renderers/freemarker/contextAttributes"); |
189 |
|
|
190 |
|
|
191 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("3.1.1")); |
192 |
|
|
193 |
|
|
194 |
1 |
assertThat(configSession.getNode("/modules/rendering/renderers/freemarker/contextAttributes"), hasNode("imgfn")); |
195 |
|
} |
196 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
197 |
1 |
@Test... |
198 |
|
public void updateTo32ExcludesImagingFromFlushCache() throws Exception { |
199 |
|
|
200 |
1 |
Node workspacesExcludedFromFlushCachePolicy = NodeUtil.createPath(configSession.getRootNode(), "/" + ExcludeWorkspacesFromFlushCachePolicy.CACHE_CONFIGURATION_PATH + "defaultPageCache/" + ExcludeWorkspacesFromFlushCachePolicy.EXCLUDED_WORKSPACES_CONFIG_PATH, NodeTypes.Content.NAME); |
201 |
|
|
202 |
|
|
203 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("3.1.1")); |
204 |
|
|
205 |
|
|
206 |
1 |
assertThat(workspacesExcludedFromFlushCachePolicy, hasProperty("imaging")); |
207 |
|
} |
208 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
209 |
1 |
@Test... |
210 |
|
public void cleanInstall() throws Exception { |
211 |
|
|
212 |
1 |
Node workspacesExcludedFromFlushCachePolicy = NodeUtil.createPath(configSession.getRootNode(), "/" + ExcludeWorkspacesFromFlushCachePolicy.CACHE_CONFIGURATION_PATH + "defaultPageCache/" + ExcludeWorkspacesFromFlushCachePolicy.EXCLUDED_WORKSPACES_CONFIG_PATH, NodeTypes.Content.NAME); |
213 |
|
|
214 |
|
|
215 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null); |
216 |
|
|
217 |
|
|
218 |
1 |
assertThat(workspacesExcludedFromFlushCachePolicy, hasProperty("imaging")); |
219 |
|
} |
220 |
|
|
221 |
|
} |