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 (104) |
Complexity: 17 |
Complexity Density: 0.19 |
|
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 |
9 |
@Override... |
78 |
|
protected String getModuleDescriptorPath() { |
79 |
9 |
return "/META-INF/magnolia/google-sitemap.xml"; |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
9 |
@Override... |
83 |
|
protected ModuleVersionHandler newModuleVersionHandlerForTests() { |
84 |
9 |
return new GoogleSiteMapVersionHandler(); |
85 |
|
} |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
87 |
9 |
@Override... |
88 |
|
protected String[] getExtraWorkspaces() { |
89 |
9 |
return new String[]{"templates", GoogleSiteMapConfiguration.WORKSPACE}; |
90 |
|
} |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
9 |
@Override... |
93 |
|
protected List<String> getModuleDescriptorPathsForTests() { |
94 |
9 |
return Arrays.asList("/META-INF/magnolia/core.xml"); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
9 |
@Override... |
98 |
|
protected String getExtraNodeTypes() { |
99 |
9 |
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 (12) |
Complexity: 2 |
Complexity Density: 0.17 |
|
107 |
9 |
@Override... |
108 |
|
public void setUp() throws Exception { |
109 |
9 |
super.setUp(); |
110 |
|
|
111 |
9 |
session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); |
112 |
|
|
113 |
9 |
addSupportForSetupModuleRepositoriesTask(null); |
114 |
|
|
115 |
|
|
116 |
9 |
try { |
117 |
9 |
Components.getComponent(RepositoryManager.class).getRepositoryProvider("magnolia").registerNodeTypes(ClasspathResourcesUtil.getResource(siteMapNodeTypeConfigFile).openStream()); |
118 |
|
} catch (RepositoryException e) { |
119 |
|
} |
120 |
|
|
121 |
9 |
this.setupConfigProperty("/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/tabSites/fields/sites/field", "workspace", "website"); |
122 |
9 |
this.setupConfigNode("/modules/google-sitemap/dialogs/generic/controls/googleSiteMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapPriority"); |
123 |
9 |
this.setupConfigNode("/modules/google-sitemap/dialogs/generic/controls/googleSiteMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapChangefreq"); |
124 |
9 |
this.setupConfigNode("/modules/google-sitemap/dialogs/generic/controls/googleVirtualUriMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapPriority"); |
125 |
9 |
this.setupConfigNode("/modules/google-sitemap/dialogs/generic/controls/googleVirtualUriMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapChangefreq"); |
126 |
9 |
this.setupConfigNode("/modules/google-sitemap/templates/pages/siteMapsConfiguration"); |
127 |
9 |
this.setupConfigNode("/modules/google-sitemap/apps/siteMaps/subApps/browser/actions/deactivate"); |
128 |
|
} |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
130 |
1 |
@Test... |
131 |
|
public void testUpdateTo20ReordersSitemapBeforeConfigApp() throws Exception { |
132 |
|
|
133 |
1 |
Node manageApps = NodeUtil.createPath(session.getRootNode(), "modules/ui-admincentral/config/appLauncherLayout/groups/manage/apps", NodeTypes.ContentNode.NAME); |
134 |
1 |
NodeUtil.createPath(manageApps, "rssAggregator", NodeTypes.ContentNode.NAME); |
135 |
1 |
NodeUtil.createPath(manageApps, "configuration", NodeTypes.ContentNode.NAME); |
136 |
|
|
137 |
|
|
138 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("1.2.3")); |
139 |
|
|
140 |
|
|
141 |
1 |
NodeIterator it = manageApps.getNodes(); |
142 |
1 |
assertTrue(manageApps.hasNode("siteMaps")); |
143 |
1 |
assertEquals("rssAggregator", it.nextNode().getName()); |
144 |
1 |
assertEquals("siteMaps", it.nextNode().getName()); |
145 |
1 |
assertEquals("configuration", it.nextNode().getName()); |
146 |
|
} |
147 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
148 |
1 |
@Test... |
149 |
|
public void testFreshInstallReordersSitemapBeforeConfigApp() throws Exception { |
150 |
|
|
151 |
1 |
Node manageApps = NodeUtil.createPath(session.getRootNode(), "modules/ui-admincentral/config/appLauncherLayout/groups/manage/apps", NodeTypes.ContentNode.NAME); |
152 |
1 |
NodeUtil.createPath(manageApps, "rssAggregator", NodeTypes.ContentNode.NAME); |
153 |
1 |
NodeUtil.createPath(manageApps, "configuration", NodeTypes.ContentNode.NAME); |
154 |
|
|
155 |
1 |
NodeUtil.createPath(manageApps, "siteMaps", NodeTypes.ContentNode.NAME); |
156 |
|
|
157 |
|
|
158 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null); |
159 |
|
|
160 |
|
|
161 |
1 |
NodeIterator it = manageApps.getNodes(); |
162 |
1 |
assertTrue(manageApps.hasNode("siteMaps")); |
163 |
1 |
assertEquals("rssAggregator", it.nextNode().getName()); |
164 |
1 |
assertEquals("siteMaps", it.nextNode().getName()); |
165 |
1 |
assertEquals("configuration", it.nextNode().getName()); |
166 |
|
} |
167 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
168 |
1 |
@Test... |
169 |
|
public void testUpdateTo22() throws RepositoryException, ModuleManagementException { |
170 |
|
|
171 |
1 |
this.setupConfigProperty("/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/siteMap", "property", "value"); |
172 |
1 |
this.setupConfigNode("/modules/google-sitemap/apps/siteMaps/subApps/browser"); |
173 |
1 |
this.setupConfigProperty("/modules/google-sitemap/apps/siteMaps/subApps/pages", "property", "value"); |
174 |
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"); |
175 |
|
|
176 |
|
|
177 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.0")); |
178 |
|
|
179 |
|
|
180 |
1 |
NodeIterator it = session.getNode("/modules/google-sitemap/apps/siteMaps/subApps").getNodes(); |
181 |
1 |
assertEquals("browser", it.nextNode().getName()); |
182 |
1 |
assertEquals("pages", it.nextNode().getName()); |
183 |
1 |
assertConfig(FolderNameColumnFormatter.class.getName(), "/modules/google-sitemap/apps/siteMaps/subApps/browser/workbench/contentViews/list/columns/name/formatterClass"); |
184 |
1 |
assertConfig("0.5", "/modules/google-sitemap/config/priority"); |
185 |
1 |
assertConfig("weekly", "/modules/google-sitemap/config/changeFrequency"); |
186 |
1 |
assertTrue(session.nodeExists("/modules/google-sitemap/fieldTypes/siteMapSelect")); |
187 |
|
} |
188 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
189 |
1 |
@Test... |
190 |
|
public void testUpdateTo22ConfigureActions() throws Exception { |
191 |
|
|
192 |
1 |
Session session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); |
193 |
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"); |
194 |
1 |
Node addSiteMapAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "addSiteMap", NodeTypes.ContentNode.NAME); |
195 |
1 |
Node deleteAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "delete", NodeTypes.ContentNode.NAME); |
196 |
1 |
Node editSiteMapAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "editSiteMap", NodeTypes.ContentNode.NAME); |
197 |
1 |
Node activateAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "activate", NodeTypes.ContentNode.NAME); |
198 |
1 |
Node deactivateAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "deactivate", NodeTypes.ContentNode.NAME); |
199 |
1 |
Node activateDeletedAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "activateDeleted", NodeTypes.ContentNode.NAME); |
200 |
|
|
201 |
|
|
202 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.1")); |
203 |
|
|
204 |
|
|
205 |
1 |
assertThat(addSiteMapAction, hasNode("availability")); |
206 |
1 |
assertThat(addSiteMapAction.getNode("availability"), hasProperty("writePermissionRequired", true)); |
207 |
1 |
assertThat(deleteAction, hasNode("availability")); |
208 |
1 |
assertThat(deleteAction.getNode("availability"), hasProperty("writePermissionRequired", true)); |
209 |
1 |
assertThat(editSiteMapAction, hasNode("availability")); |
210 |
1 |
assertThat(editSiteMapAction.getNode("availability"), hasProperty("writePermissionRequired", true)); |
211 |
1 |
assertThat(activateAction, hasNode("availability")); |
212 |
1 |
assertThat(activateAction.getNode("availability"), hasProperty("writePermissionRequired", true)); |
213 |
1 |
assertThat(deactivateAction, hasNode("availability")); |
214 |
1 |
assertThat(deactivateAction.getNode("availability"), hasProperty("writePermissionRequired", true)); |
215 |
1 |
assertThat(activateDeletedAction, hasNode("availability")); |
216 |
1 |
assertThat(activateDeletedAction.getNode("availability"), hasProperty("writePermissionRequired", true)); |
217 |
|
} |
218 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
219 |
1 |
@Test... |
220 |
|
public void testUpdateTo223NewCatalogProperty() throws RepositoryException, ModuleManagementException { |
221 |
|
|
222 |
|
|
223 |
|
|
224 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.2.2")); |
225 |
|
|
226 |
|
|
227 |
1 |
assertTrue(session.propertyExists("/modules/google-sitemap/apps/siteMaps/subApps/browser/actions/deactivate/catalog")); |
228 |
1 |
assertEquals("website", session.getProperty("/modules/google-sitemap/apps/siteMaps/subApps/browser/actions/deactivate/catalog").getString()); |
229 |
|
} |
230 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
231 |
1 |
@Test... |
232 |
|
public void updateFrom232RemovesHiddenProperty() throws Exception { |
233 |
|
|
234 |
1 |
setupConfigProperty("/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/siteMap/fields/template", "hidden", "true"); |
235 |
|
|
236 |
|
|
237 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.3.2")); |
238 |
|
|
239 |
|
|
240 |
1 |
assertThat(session.getNode("/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/siteMap/fields/template"), not(hasProperty("hidden"))); |
241 |
|
} |
242 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
243 |
1 |
@Test... |
244 |
|
public void updateFrom232ChangesBrokenTemplateOnExistingSites() throws Exception { |
245 |
|
|
246 |
1 |
final Session siteMapSession = MgnlContext.getJCRSession(GoogleSiteMapConfiguration.WORKSPACE); |
247 |
1 |
final Node siteMap = NodeUtil.createPath(siteMapSession.getRootNode(), "testSiteMap", SiteMapNodeTypes.SiteMap.NAME); |
248 |
1 |
siteMap.setProperty(NodeTypes.Renderable.TEMPLATE, "GoogleSiteMap"); |
249 |
|
|
250 |
1 |
Components.getComponent(VersionManager.class).addVersion(siteMap); |
251 |
|
|
252 |
|
|
253 |
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 |
|
254 |
1 |
@Override... |
255 |
|
public void evaluate() throws Exception { |
256 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.3.2")); |
257 |
|
} |
258 |
|
}, throwsNothing()); |
259 |
|
|
260 |
|
|
261 |
1 |
assertThat(siteMapSession.getNode("/testSiteMap"), hasProperty(NodeTypes.Renderable.TEMPLATE, "google-sitemap:pages/siteMapsConfiguration")); |
262 |
|
} |
263 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
264 |
1 |
@Test... |
265 |
|
public void updateFrom233SetsDefaultType() throws Exception { |
266 |
|
|
267 |
|
|
268 |
|
|
269 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.3.3")); |
270 |
|
|
271 |
|
|
272 |
1 |
assertThat(session.getNode("/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/siteMap/fields/mgnl:googleSiteMapType/options/standard"), hasProperty("selected", "true")); |
273 |
|
} |
274 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
275 |
1 |
@Test... |
276 |
|
public void updateFrom233AddsRendererAndUsage() throws Exception { |
277 |
|
|
278 |
1 |
setupConfigProperty("/modules/google-sitemap/templates/pages/siteMapsConfiguration", "renderType", "freemarker"); |
279 |
|
|
280 |
|
|
281 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.3.3")); |
282 |
|
|
283 |
|
|
284 |
1 |
assertThat(session.getNode("/modules/google-sitemap/renderers/sitemap"), hasProperty("contentType", "application/xml")); |
285 |
1 |
assertThat(session.getNode("/modules/google-sitemap/templates/pages/siteMapsConfiguration"), hasProperty("renderType", "sitemap")); |
286 |
|
} |
287 |
|
|
288 |
|
} |