Clover icon

Google Sitemap Module 2.4.1

  1. Project Clover database Thu Jan 12 2017 12:35:51 CET
  2. Package info.magnolia.module.googlesitemap.setup

File GoogleSiteMapVersionHandlerTest.java

 

Code metrics

0
103
17
1
311
194
18
0.17
6.06
17
1.06
1.6% of code in this file is excluded from these metrics.

Classes

Class Line # Actions
GoogleSiteMapVersionHandlerTest 72 103 1.6% 18 0
1.0100%
 

Contributing tests

This file is covered by 10 tests. .

Source view

1    /**
2    * This file Copyright (c) 2013-2017 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.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    * Tests for {@link GoogleSiteMapVersionHandler}.
71    */
 
72    public class GoogleSiteMapVersionHandlerTest extends ModuleVersionHandlerTestCase {
73   
74    private Session session;
75    private final String siteMapNodeTypeConfigFile = "/test-google-sitemap-nodetypes.xml";
76   
 
77  10 toggle @Override
78    protected String getModuleDescriptorPath() {
79  10 return "/META-INF/magnolia/google-sitemap.xml";
80    }
81   
 
82  10 toggle @Override
83    protected ModuleVersionHandler newModuleVersionHandlerForTests() {
84  10 return new GoogleSiteMapVersionHandler();
85    }
86   
 
87  10 toggle @Override
88    protected String[] getExtraWorkspaces() {
89  10 return new String[]{"templates", GoogleSiteMapConfiguration.WORKSPACE};
90    }
91   
 
92  10 toggle @Override
93    protected List<String> getModuleDescriptorPathsForTests() {
94  10 return Arrays.asList("/META-INF/magnolia/core.xml");
95    }
96   
 
97  10 toggle @Override
98    protected String getExtraNodeTypes() {
99  10 return siteMapNodeTypeConfigFile;
100    }
101   
 
102    toggle @Override
103    public String getRepositoryConfigFileName() {
104    return "/test-siteMap-repositories.xml";
105    }
106   
 
107  10 toggle @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    // Register Google SiteMap node type
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   
 
132  1 toggle @Test
133    public void testUpdateTo20ReordersSitemapBeforeConfigApp() throws Exception {
134    // GIVEN
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    // WHEN
140  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("1.2.3"));
141   
142    // THEN
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   
 
150  1 toggle @Test
151    public void testFreshInstallReordersSitemapBeforeConfigApp() throws Exception {
152    // GIVEN
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    // we have to create the siteMaps node artificially before bootstrapping, otherwise test would fail in maven
157  1 NodeUtil.createPath(manageApps, "siteMaps", NodeTypes.ContentNode.NAME);
158   
159    // WHEN
160  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null);
161   
162    // THEN
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   
 
170  1 toggle @Test
171    public void testUpdateTo22() throws RepositoryException, ModuleManagementException {
172    // GIVEN
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    // WHEN
179  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.0"));
180   
181    // THEN
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   
 
191  1 toggle @Test
192    public void testUpdateTo22ConfigureActions() throws Exception {
193    // GIVEN
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    // WHEN
204  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.1"));
205   
206    // THEN
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   
 
221  1 toggle @Test
222    public void testUpdateTo223NewCatalogProperty() throws RepositoryException, ModuleManagementException {
223    // GIVEN
224   
225    // WHEN
226  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.2.2"));
227   
228    // THEN
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   
 
233  1 toggle @Test
234    public void updateFrom232RemovesHiddenProperty() throws Exception {
235    // GIVEN
236  1 setupConfigProperty("/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/siteMap/fields/template", "hidden", "true");
237   
238    // WHEN
239  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.3.2"));
240   
241    // THEN
242  1 assertThat(session.getNode("/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/siteMap/fields/template"), not(hasProperty("hidden")));
243    }
244   
 
245  1 toggle @Test
246    public void updateFrom232ChangesBrokenTemplateOnExistingSites() throws Exception {
247    // GIVEN
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    // WHEN
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() {
 
256  1 toggle @Override
257    public void evaluate() throws Exception {
258  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.3.2"));
259    }
260    }, throwsNothing());
261   
262    // THEN
263  1 assertThat(siteMapSession.getNode("/testSiteMap"), hasProperty(NodeTypes.Renderable.TEMPLATE, "google-sitemap:pages/siteMapsConfiguration"));
264    }
265   
 
266  1 toggle @Test
267    public void updateFrom233SetsDefaultType() throws Exception {
268    // GIVEN
269   
270    // WHEN
271  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.3.3"));
272   
273    // THEN
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   
 
277  1 toggle @Test
278    public void updateFrom233AddsRendererAndUsage() throws Exception {
279    // GIVEN
280  1 setupConfigProperty("/modules/google-sitemap/templates/pages/siteMapsConfiguration", "renderType", "freemarker");
281   
282    // WHEN
283  1 executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.3.3"));
284   
285    // THEN
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   
 
290  1 toggle @Test
291    public void updateFrom24RemovesInvalidProperties() throws Exception {
292    // GIVEN
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    // WHEN
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    // THEN
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    }