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.module.googlesitemap.setup; |
35 |
|
|
36 |
|
import static info.magnolia.test.hamcrest.ExecutionMatcher.throwsNothing; |
37 |
|
import static info.magnolia.test.hamcrest.NodeMatchers.*; |
38 |
|
import static org.hamcrest.CoreMatchers.not; |
39 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
40 |
|
import static org.junit.Assert.*; |
41 |
|
|
42 |
|
import info.magnolia.cms.core.version.VersionManager; |
43 |
|
import info.magnolia.cms.util.ClasspathResourcesUtil; |
44 |
|
import info.magnolia.context.MgnlContext; |
45 |
|
import info.magnolia.jcr.util.NodeTypes; |
46 |
|
import info.magnolia.jcr.util.NodeUtil; |
47 |
|
import info.magnolia.module.ModuleManagementException; |
48 |
|
import info.magnolia.module.ModuleVersionHandler; |
49 |
|
import info.magnolia.module.ModuleVersionHandlerTestCase; |
50 |
|
import info.magnolia.module.googlesitemap.GoogleSiteMapConfiguration; |
51 |
|
import info.magnolia.module.googlesitemap.SiteMapNodeTypes; |
52 |
|
import info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.contentviews.formatter.FolderNameColumnFormatter; |
53 |
|
import info.magnolia.module.model.Version; |
54 |
|
import info.magnolia.objectfactory.Components; |
55 |
|
import info.magnolia.repository.RepositoryConstants; |
56 |
|
import info.magnolia.repository.RepositoryManager; |
57 |
|
import info.magnolia.test.hamcrest.Execution; |
58 |
|
|
59 |
|
import java.util.Arrays; |
60 |
|
import java.util.List; |
61 |
|
|
62 |
|
import javax.jcr.Node; |
63 |
|
import javax.jcr.NodeIterator; |
64 |
|
import javax.jcr.RepositoryException; |
65 |
|
import javax.jcr.Session; |
66 |
|
|
67 |
|
import org.junit.Test; |
68 |
|
|
69 |
|
|
70 |
|
@link |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (120) |
Complexity: 18 |
Complexity Density: 0.17 |
|
72 |
|
public class GoogleSiteMapVersionHandlerTest extends ModuleVersionHandlerTestCase { |
73 |
|
|
74 |
|
private Session session; |
75 |
|
private final String siteMapNodeTypeConfigFile = "/test-google-sitemap-nodetypes.xml"; |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
10 |
@Override... |
78 |
|
protected String getModuleDescriptorPath() { |
79 |
10 |
return "/META-INF/magnolia/google-sitemap.xml"; |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
10 |
@Override... |
83 |
|
protected ModuleVersionHandler newModuleVersionHandlerForTests() { |
84 |
10 |
return new GoogleSiteMapVersionHandler(); |
85 |
|
} |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
87 |
10 |
@Override... |
88 |
|
protected String[] getExtraWorkspaces() { |
89 |
10 |
return new String[]{"templates", GoogleSiteMapConfiguration.WORKSPACE}; |
90 |
|
} |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
10 |
@Override... |
93 |
|
protected List<String> getModuleDescriptorPathsForTests() { |
94 |
10 |
return Arrays.asList("/META-INF/magnolia/core.xml"); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
10 |
@Override... |
98 |
|
protected String getExtraNodeTypes() { |
99 |
10 |
return siteMapNodeTypeConfigFile; |
100 |
|
} |
101 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
102 |
|
@Override... |
103 |
|
public String getRepositoryConfigFileName() { |
104 |
|
return "/test-siteMap-repositories.xml"; |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 2 |
Complexity Density: 0.14 |
|
107 |
10 |
@Override... |
108 |
|
public void setUp() throws Exception { |
109 |
10 |
super.setUp(); |
110 |
|
|
111 |
10 |
session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); |
112 |
|
|
113 |
10 |
addSupportForSetupModuleRepositoriesTask(null); |
114 |
|
|
115 |
|
|
116 |
10 |
try { |
117 |
10 |
Components.getComponent(RepositoryManager.class).getRepositoryProvider("magnolia").registerNodeTypes(ClasspathResourcesUtil.getResource(siteMapNodeTypeConfigFile).openStream()); |
118 |
|
} catch (RepositoryException e) { |
119 |
|
} |
120 |
|
|
121 |
10 |
this.setupConfigProperty("/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/tabSites/fields/sites/field", "workspace", "website"); |
122 |
10 |
this.setupConfigNode("/modules/google-sitemap/dialogs/generic/controls/googleSiteMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapPriority"); |
123 |
10 |
this.setupConfigNode("/modules/google-sitemap/dialogs/generic/controls/googleSiteMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapChangefreq"); |
124 |
10 |
this.setupConfigNode("/modules/google-sitemap/dialogs/generic/controls/googleVirtualUriMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapPriority"); |
125 |
10 |
this.setupConfigNode("/modules/google-sitemap/dialogs/generic/controls/googleVirtualUriMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapChangefreq"); |
126 |
10 |
this.setupConfigNode("/modules/google-sitemap/templates/pages/siteMapsConfiguration"); |
127 |
10 |
this.setupConfigNode("/modules/google-sitemap/apps/siteMaps/subApps/browser/actions/deactivate"); |
128 |
10 |
this.setupConfigNode("/modules/google-sitemap/apps/siteMaps/subApps/browser/actions/export"); |
129 |
10 |
this.setupConfigNode("/modules/google-sitemap/apps/siteMaps/subApps/browser/actions/editSiteMap"); |
130 |
|
} |
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
132 |
1 |
@Test... |
133 |
|
public void testUpdateTo20ReordersSitemapBeforeConfigApp() throws Exception { |
134 |
|
|
135 |
1 |
Node manageApps = NodeUtil.createPath(session.getRootNode(), "modules/ui-admincentral/config/appLauncherLayout/groups/manage/apps", NodeTypes.ContentNode.NAME); |
136 |
1 |
NodeUtil.createPath(manageApps, "rssAggregator", NodeTypes.ContentNode.NAME); |
137 |
1 |
NodeUtil.createPath(manageApps, "configuration", NodeTypes.ContentNode.NAME); |
138 |
|
|
139 |
|
|
140 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("1.2.3")); |
141 |
|
|
142 |
|
|
143 |
1 |
NodeIterator it = manageApps.getNodes(); |
144 |
1 |
assertTrue(manageApps.hasNode("siteMaps")); |
145 |
1 |
assertEquals("rssAggregator", it.nextNode().getName()); |
146 |
1 |
assertEquals("siteMaps", it.nextNode().getName()); |
147 |
1 |
assertEquals("configuration", it.nextNode().getName()); |
148 |
|
} |
149 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
150 |
1 |
@Test... |
151 |
|
public void testFreshInstallReordersSitemapBeforeConfigApp() throws Exception { |
152 |
|
|
153 |
1 |
Node manageApps = NodeUtil.createPath(session.getRootNode(), "modules/ui-admincentral/config/appLauncherLayout/groups/manage/apps", NodeTypes.ContentNode.NAME); |
154 |
1 |
NodeUtil.createPath(manageApps, "rssAggregator", NodeTypes.ContentNode.NAME); |
155 |
1 |
NodeUtil.createPath(manageApps, "configuration", NodeTypes.ContentNode.NAME); |
156 |
|
|
157 |
1 |
NodeUtil.createPath(manageApps, "siteMaps", NodeTypes.ContentNode.NAME); |
158 |
|
|
159 |
|
|
160 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null); |
161 |
|
|
162 |
|
|
163 |
1 |
NodeIterator it = manageApps.getNodes(); |
164 |
1 |
assertTrue(manageApps.hasNode("siteMaps")); |
165 |
1 |
assertEquals("rssAggregator", it.nextNode().getName()); |
166 |
1 |
assertEquals("siteMaps", it.nextNode().getName()); |
167 |
1 |
assertEquals("configuration", it.nextNode().getName()); |
168 |
|
} |
169 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
170 |
1 |
@Test... |
171 |
|
public void testUpdateTo22() throws RepositoryException, ModuleManagementException { |
172 |
|
|
173 |
1 |
this.setupConfigProperty("/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/siteMap", "property", "value"); |
174 |
1 |
this.setupConfigNode("/modules/google-sitemap/apps/siteMaps/subApps/browser"); |
175 |
1 |
this.setupConfigProperty("/modules/google-sitemap/apps/siteMaps/subApps/pages", "property", "value"); |
176 |
1 |
this.setupConfigProperty("/modules/google-sitemap/apps/siteMaps/subApps/browser/workbench/contentViews/list/columns/name", "formatterClass", "info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.formatter.FolderNameColumnFormatter"); |
177 |
|
|
178 |
|
|
179 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.0")); |
180 |
|
|
181 |
|
|
182 |
1 |
NodeIterator it = session.getNode("/modules/google-sitemap/apps/siteMaps/subApps").getNodes(); |
183 |
1 |
assertEquals("browser", it.nextNode().getName()); |
184 |
1 |
assertEquals("pages", it.nextNode().getName()); |
185 |
1 |
assertConfig(FolderNameColumnFormatter.class.getName(), "/modules/google-sitemap/apps/siteMaps/subApps/browser/workbench/contentViews/list/columns/name/formatterClass"); |
186 |
1 |
assertConfig("0.5", "/modules/google-sitemap/config/priority"); |
187 |
1 |
assertConfig("weekly", "/modules/google-sitemap/config/changeFrequency"); |
188 |
1 |
assertTrue(session.nodeExists("/modules/google-sitemap/fieldTypes/siteMapSelect")); |
189 |
|
} |
190 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
191 |
1 |
@Test... |
192 |
|
public void testUpdateTo22ConfigureActions() throws Exception { |
193 |
|
|
194 |
1 |
Session session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); |
195 |
1 |
this.setupConfigProperty("/modules/google-sitemap/apps/siteMaps/subApps/browser/workbench/contentViews/list/columns/name", "formatterClass", "info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.formatter.FolderNameColumnFormatter"); |
196 |
1 |
Node addSiteMapAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "addSiteMap", NodeTypes.ContentNode.NAME); |
197 |
1 |
Node deleteAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "delete", NodeTypes.ContentNode.NAME); |
198 |
1 |
Node editSiteMapAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "editSiteMap", NodeTypes.ContentNode.NAME); |
199 |
1 |
Node activateAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "activate", NodeTypes.ContentNode.NAME); |
200 |
1 |
Node deactivateAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "deactivate", NodeTypes.ContentNode.NAME); |
201 |
1 |
Node activateDeletedAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "activateDeleted", NodeTypes.ContentNode.NAME); |
202 |
|
|
203 |
|
|
204 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.1")); |
205 |
|
|
206 |
|
|
207 |
1 |
assertThat(addSiteMapAction, hasNode("availability")); |
208 |
1 |
assertThat(addSiteMapAction.getNode("availability"), hasProperty("writePermissionRequired", true)); |
209 |
1 |
assertThat(deleteAction, hasNode("availability")); |
210 |
1 |
assertThat(deleteAction.getNode("availability"), hasProperty("writePermissionRequired", true)); |
211 |
1 |
assertThat(editSiteMapAction, hasNode("availability")); |
212 |
1 |
assertThat(editSiteMapAction.getNode("availability"), hasProperty("writePermissionRequired", true)); |
213 |
1 |
assertThat(activateAction, hasNode("availability")); |
214 |
1 |
assertThat(activateAction.getNode("availability"), hasProperty("writePermissionRequired", true)); |
215 |
1 |
assertThat(deactivateAction, hasNode("availability")); |
216 |
1 |
assertThat(deactivateAction.getNode("availability"), hasProperty("writePermissionRequired", true)); |
217 |
1 |
assertThat(activateDeletedAction, hasNode("availability")); |
218 |
1 |
assertThat(activateDeletedAction.getNode("availability"), hasProperty("writePermissionRequired", true)); |
219 |
|
} |
220 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
221 |
1 |
@Test... |
222 |
|
public void testUpdateTo223NewCatalogProperty() throws RepositoryException, ModuleManagementException { |
223 |
|
|
224 |
|
|
225 |
|
|
226 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.2.2")); |
227 |
|
|
228 |
|
|
229 |
1 |
assertTrue(session.propertyExists("/modules/google-sitemap/apps/siteMaps/subApps/browser/actions/deactivate/catalog")); |
230 |
1 |
assertEquals("website", session.getProperty("/modules/google-sitemap/apps/siteMaps/subApps/browser/actions/deactivate/catalog").getString()); |
231 |
|
} |
232 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
233 |
1 |
@Test... |
234 |
|
public void updateFrom232RemovesHiddenProperty() throws Exception { |
235 |
|
|
236 |
1 |
setupConfigProperty("/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/siteMap/fields/template", "hidden", "true"); |
237 |
|
|
238 |
|
|
239 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.3.2")); |
240 |
|
|
241 |
|
|
242 |
1 |
assertThat(session.getNode("/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/siteMap/fields/template"), not(hasProperty("hidden"))); |
243 |
|
} |
244 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
245 |
1 |
@Test... |
246 |
|
public void updateFrom232ChangesBrokenTemplateOnExistingSites() throws Exception { |
247 |
|
|
248 |
1 |
final Session siteMapSession = MgnlContext.getJCRSession(GoogleSiteMapConfiguration.WORKSPACE); |
249 |
1 |
final Node siteMap = NodeUtil.createPath(siteMapSession.getRootNode(), "testSiteMap", SiteMapNodeTypes.SiteMap.NAME); |
250 |
1 |
siteMap.setProperty(NodeTypes.Renderable.TEMPLATE, "GoogleSiteMap"); |
251 |
|
|
252 |
1 |
Components.getComponent(VersionManager.class).addVersion(siteMap); |
253 |
|
|
254 |
|
|
255 |
1 |
assertThat("We want to make sure that the update task is not executed on jcr:system nodes (modifying a property would result in exception)", new Execution() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
256 |
1 |
@Override... |
257 |
|
public void evaluate() throws Exception { |
258 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.3.2")); |
259 |
|
} |
260 |
|
}, throwsNothing()); |
261 |
|
|
262 |
|
|
263 |
1 |
assertThat(siteMapSession.getNode("/testSiteMap"), hasProperty(NodeTypes.Renderable.TEMPLATE, "google-sitemap:pages/siteMapsConfiguration")); |
264 |
|
} |
265 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
266 |
1 |
@Test... |
267 |
|
public void updateFrom233SetsDefaultType() throws Exception { |
268 |
|
|
269 |
|
|
270 |
|
|
271 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.3.3")); |
272 |
|
|
273 |
|
|
274 |
1 |
assertThat(session.getNode("/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/siteMap/fields/mgnl-googleSiteMapType/options/standard"), hasProperty("selected", "true")); |
275 |
|
} |
276 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
277 |
1 |
@Test... |
278 |
|
public void updateFrom233AddsRendererAndUsage() throws Exception { |
279 |
|
|
280 |
1 |
setupConfigProperty("/modules/google-sitemap/templates/pages/siteMapsConfiguration", "renderType", "freemarker"); |
281 |
|
|
282 |
|
|
283 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.3.3")); |
284 |
|
|
285 |
|
|
286 |
1 |
assertThat(session.getNode("/modules/google-sitemap/renderers/sitemap"), hasProperty("contentType", "application/xml")); |
287 |
1 |
assertThat(session.getNode("/modules/google-sitemap/templates/pages/siteMapsConfiguration"), hasProperty("renderType", "sitemap")); |
288 |
|
} |
289 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
290 |
1 |
@Test... |
291 |
|
public void updateFrom24RemovesInvalidProperties() throws Exception { |
292 |
|
|
293 |
1 |
Node exportAction = session.getNode("/modules/google-sitemap/apps/siteMaps/subApps/browser/actions/export"); |
294 |
1 |
Node editSiteMapAction = session.getNode("/modules/google-sitemap/apps/siteMaps/subApps/browser/actions/editSiteMap"); |
295 |
1 |
Node siteMapPagesField = NodeUtil.createPath(session.getRootNode(), "modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/tabSites/fields/mgnl:googleSiteMapPages", NodeTypes.ContentNode.NAME); |
296 |
1 |
exportAction.setProperty("extends", ""); |
297 |
1 |
editSiteMapAction.setProperty("nodeType", ""); |
298 |
1 |
siteMapPagesField.setProperty("chooseOnClick", ""); |
299 |
|
|
300 |
|
|
301 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.4")); |
302 |
1 |
siteMapPagesField = session.getNode("/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/tabSites/fields/mgnl-googleSiteMapPages"); |
303 |
|
|
304 |
|
|
305 |
1 |
assertThat(exportAction, not(hasProperty("export"))); |
306 |
1 |
assertThat(exportAction, hasProperty("icon")); |
307 |
1 |
assertThat(editSiteMapAction, not(hasProperty("nodeType"))); |
308 |
1 |
assertThat(siteMapPagesField, not(hasProperty("chooseOnClick"))); |
309 |
1 |
assertThat(siteMapPagesField, hasProperty("name", "mgnl:googleSiteMapPages")); |
310 |
|
} |
311 |
|
} |