View Javadoc
1   /**
2    * This file Copyright (c) 2013-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.module.googlesitemap.setup;
35  
36  import static info.magnolia.test.hamcrest.NodeMatchers.*;
37  import static org.hamcrest.MatcherAssert.assertThat;
38  import static org.junit.Assert.*;
39  
40  import info.magnolia.context.MgnlContext;
41  import info.magnolia.jcr.util.NodeTypes;
42  import info.magnolia.jcr.util.NodeUtil;
43  import info.magnolia.module.ModuleManagementException;
44  import info.magnolia.module.ModuleVersionHandler;
45  import info.magnolia.module.ModuleVersionHandlerTestCase;
46  import info.magnolia.module.googlesitemap.GoogleSiteMapConfiguration;
47  import info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.contentviews.formatter.FolderNameColumnFormatter;
48  import info.magnolia.module.model.Version;
49  import info.magnolia.repository.RepositoryConstants;
50  
51  import java.util.Arrays;
52  import java.util.List;
53  
54  import javax.jcr.Node;
55  import javax.jcr.NodeIterator;
56  import javax.jcr.RepositoryException;
57  import javax.jcr.Session;
58  
59  import org.junit.Test;
60  
61  /**
62   * Tests for {@link GoogleSiteMapVersionHandler}.
63   */
64  public class GoogleSiteMapVersionHandlerTest extends ModuleVersionHandlerTestCase {
65      private Session session;
66      @Override
67      protected String getModuleDescriptorPath() {
68          return "/META-INF/magnolia/google-sitemap.xml";
69      }
70  
71      @Override
72      protected ModuleVersionHandler newModuleVersionHandlerForTests() {
73          return new GoogleSiteMapVersionHandler();
74      }
75  
76      @Override
77      protected String[] getExtraWorkspaces() {
78          return new String[] { "templates" };
79      }
80  
81      @Override
82      protected List<String> getModuleDescriptorPathsForTests() {
83          return Arrays.asList("/META-INF/magnolia/core.xml");
84      }
85  
86      @Override
87      public void setUp() throws Exception {
88          super.setUp();
89          session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG);
90          addSupportForSetupModuleRepositoriesTask(GoogleSiteMapConfiguration.WORKSPACE);
91          this.setupConfigProperty("/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/tabSites/fields/sites/field", "workspace", "website");
92          this.setupConfigNode("/modules/google-sitemap/dialogs/generic/controls/googleSiteMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapPriority");
93          this.setupConfigNode("/modules/google-sitemap/dialogs/generic/controls/googleSiteMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapChangefreq");
94          this.setupConfigNode("/modules/google-sitemap/dialogs/generic/controls/googleVirtualUriMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapPriority");
95          this.setupConfigNode("/modules/google-sitemap/dialogs/generic/controls/googleVirtualUriMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapChangefreq");
96          this.setupConfigNode("/modules/google-sitemap/templates/pages/siteMapsConfiguration");
97          this.setupConfigNode("/modules/google-sitemap/apps/siteMaps/subApps/browser/actions/deactivate");
98      }
99  
100     @Test
101     public void testUpdateTo20ReordersSitemapBeforeConfigApp() throws Exception {
102         // GIVEN
103         Node manageApps = NodeUtil.createPath(session.getRootNode(), "modules/ui-admincentral/config/appLauncherLayout/groups/manage/apps", NodeTypes.ContentNode.NAME);
104         NodeUtil.createPath(manageApps, "rssAggregator", NodeTypes.ContentNode.NAME);
105         NodeUtil.createPath(manageApps, "configuration", NodeTypes.ContentNode.NAME);
106 
107         // WHEN
108         executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("1.2.3"));
109 
110         // THEN
111         NodeIterator it = manageApps.getNodes();
112         assertTrue(manageApps.hasNode("siteMaps"));
113         assertEquals("rssAggregator", it.nextNode().getName());
114         assertEquals("siteMaps", it.nextNode().getName());
115         assertEquals("configuration", it.nextNode().getName());
116     }
117 
118     @Test
119     public void testFreshInstallReordersSitemapBeforeConfigApp() throws Exception {
120         // GIVEN
121         Node manageApps = NodeUtil.createPath(session.getRootNode(), "modules/ui-admincentral/config/appLauncherLayout/groups/manage/apps", NodeTypes.ContentNode.NAME);
122         NodeUtil.createPath(manageApps, "rssAggregator", NodeTypes.ContentNode.NAME);
123         NodeUtil.createPath(manageApps, "configuration", NodeTypes.ContentNode.NAME);
124         // we have to create the siteMaps node artificially before bootstrapping, otherwise test would fail in maven
125         NodeUtil.createPath(manageApps, "siteMaps", NodeTypes.ContentNode.NAME);
126 
127         // WHEN
128         executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null);
129 
130         // THEN
131         NodeIterator it = manageApps.getNodes();
132         assertTrue(manageApps.hasNode("siteMaps"));
133         assertEquals("rssAggregator", it.nextNode().getName());
134         assertEquals("siteMaps", it.nextNode().getName());
135         assertEquals("configuration", it.nextNode().getName());
136     }
137 
138     @Test
139     public void testUpdateTo22() throws RepositoryException, ModuleManagementException {
140         // GIVEN
141         this.setupConfigProperty("/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/siteMap", "property", "value");
142         this.setupConfigNode("/modules/google-sitemap/apps/siteMaps/subApps/browser");
143         this.setupConfigProperty("/modules/google-sitemap/apps/siteMaps/subApps/pages", "property", "value");
144         this.setupConfigProperty("/modules/google-sitemap/apps/siteMaps/subApps/browser/workbench/contentViews/list/columns/name", "formatterClass", "info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.formatter.FolderNameColumnFormatter");
145 
146         // WHEN
147         executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.0"));
148 
149         // THEN
150         NodeIterator it = session.getNode("/modules/google-sitemap/apps/siteMaps/subApps").getNodes();
151         assertEquals("browser", it.nextNode().getName());
152         assertEquals("pages", it.nextNode().getName());
153         assertConfig(FolderNameColumnFormatter.class.getName(), "/modules/google-sitemap/apps/siteMaps/subApps/browser/workbench/contentViews/list/columns/name/formatterClass");
154         assertConfig("0.5", "/modules/google-sitemap/config/priority");
155         assertConfig("weekly", "/modules/google-sitemap/config/changeFrequency");
156         assertTrue(session.nodeExists("/modules/google-sitemap/fieldTypes/siteMapSelect"));
157     }
158 
159     @Test
160     public void testUpdateTo22ConfigureActions() throws Exception {
161         // GIVEN
162         Session session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG);
163         this.setupConfigProperty("/modules/google-sitemap/apps/siteMaps/subApps/browser/workbench/contentViews/list/columns/name", "formatterClass", "info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.formatter.FolderNameColumnFormatter");
164         Node addSiteMapAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "addSiteMap", NodeTypes.ContentNode.NAME);
165         Node deleteAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "delete", NodeTypes.ContentNode.NAME);
166         Node editSiteMapAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "editSiteMap", NodeTypes.ContentNode.NAME);
167         Node activateAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "activate", NodeTypes.ContentNode.NAME);
168         Node deactivateAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "deactivate", NodeTypes.ContentNode.NAME);
169         Node activateDeletedAction = NodeUtil.createPath(session.getRootNode(), GoogleSiteMapVersionHandler.GOOGLESITEMAP_APP_BROWSER_ACTIONS + "activateDeleted", NodeTypes.ContentNode.NAME);
170 
171         // WHEN
172         executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.1"));
173 
174         // THEN
175         assertThat(addSiteMapAction, hasNode("availability"));
176         assertThat(addSiteMapAction.getNode("availability"), hasProperty("writePermissionRequired", true));
177         assertThat(deleteAction, hasNode("availability"));
178         assertThat(deleteAction.getNode("availability"), hasProperty("writePermissionRequired", true));
179         assertThat(editSiteMapAction, hasNode("availability"));
180         assertThat(editSiteMapAction.getNode("availability"), hasProperty("writePermissionRequired", true));
181         assertThat(activateAction, hasNode("availability"));
182         assertThat(activateAction.getNode("availability"), hasProperty("writePermissionRequired", true));
183         assertThat(deactivateAction, hasNode("availability"));
184         assertThat(deactivateAction.getNode("availability"), hasProperty("writePermissionRequired", true));
185         assertThat(activateDeletedAction, hasNode("availability"));
186         assertThat(activateDeletedAction.getNode("availability"), hasProperty("writePermissionRequired", true));
187     }
188 
189     @Test
190     public void testUpdateTo223NewCatalogProperty() throws RepositoryException, ModuleManagementException {
191         // GIVEN
192 
193         // WHEN
194         executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("2.2.2"));
195 
196         // THEN
197         assertTrue(session.propertyExists("/modules/google-sitemap/apps/siteMaps/subApps/browser/actions/deactivate/catalog"));
198         assertEquals("website",session.getProperty("/modules/google-sitemap/apps/siteMaps/subApps/browser/actions/deactivate/catalog").getString());
199     }
200 }