Clover icon

Google Sitemap Module 2.4.3

  1. Project Clover database Thu May 11 2017 16:52:32 CEST
  2. Package info.magnolia.module.googlesitemap.setup.migration

File SiteMapDefinitionMigrationTaskTest.java

 

Code metrics

2
56
5
1
215
125
7
0.12
11.2
5
1.4

Classes

Class Line # Actions
SiteMapDefinitionMigrationTaskTest 75 56 0% 7 63
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.migration;
35   
36    import static org.junit.Assert.*;
37   
38    import info.magnolia.context.MgnlContext;
39    import info.magnolia.importexport.DataTransporter;
40    import info.magnolia.jcr.wrapper.JCRMgnlPropertiesFilteringNodeWrapper;
41    import info.magnolia.module.InstallContextImpl;
42    import info.magnolia.module.ModuleRegistryImpl;
43    import info.magnolia.module.delta.TaskExecutionException;
44    import info.magnolia.module.googlesitemap.GoogleSiteMapConfiguration;
45    import info.magnolia.module.googlesitemap.SiteMapNodeTypes;
46    import info.magnolia.objectfactory.Components;
47    import info.magnolia.repository.RepositoryConstants;
48    import info.magnolia.repository.RepositoryManager;
49    import info.magnolia.test.RepositoryTestCase;
50   
51    import java.io.ByteArrayInputStream;
52    import java.io.File;
53    import java.io.FileInputStream;
54    import java.io.InputStream;
55    import java.util.Arrays;
56    import java.util.HashSet;
57    import java.util.Set;
58   
59    import javax.jcr.ImportUUIDBehavior;
60    import javax.jcr.Node;
61    import javax.jcr.Property;
62    import javax.jcr.PropertyIterator;
63    import javax.jcr.RepositoryException;
64    import javax.jcr.Session;
65   
66    import org.junit.Before;
67    import org.junit.Ignore;
68    import org.junit.Test;
69    import org.slf4j.Logger;
70    import org.slf4j.LoggerFactory;
71   
72    /**
73    * .
74    */
 
75    public class SiteMapDefinitionMigrationTaskTest extends RepositoryTestCase {
76   
77    private static final Logger log = LoggerFactory.getLogger(SiteMapDefinitionMigrationTaskTest.class);
78    private Session googleSiteMapSession;
79    private Session websiteSession;
80    protected InstallContextImpl installContext;
81   
82    protected String siteMapNodeType = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<nodeTypes" + " xmlns:rep=\"internal\""
83    + " xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\"" + " xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\""
84    + " xmlns:mgnl=\"http://www.magnolia.info/jcr/mgnl\"" + " xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + "<nodeType name=\"" + SiteMapNodeTypes.SiteMap.NAME + "\""
85    + " isMixin=\"false\" hasOrderableChildNodes=\"true\" primaryItemName=\"\">"
86    + "<supertypes>"
87    + "<supertype>mgnl:content</supertype>"
88    + "</supertypes>"
89    + "</nodeType>"
90    + "</nodeTypes>";
91   
 
92  0 toggle @Override
93    @Before
94    public void setUp() throws Exception {
95  0 super.setUp();
96   
97  0 googleSiteMapSession = MgnlContext.getJCRSession(GoogleSiteMapConfiguration.WORKSPACE);
98  0 websiteSession = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE);
99    // Register siteMap node type
100  0 RepositoryManager repositoryManager = Components.getComponent(RepositoryManager.class);
101  0 try {
102  0 repositoryManager.getRepositoryProvider("magnolia").registerNodeTypes(new ByteArrayInputStream(siteMapNodeType.getBytes()));
103    } catch (RepositoryException e) {
104  0 log.error("", e);
105    }
106   
107    // Import the sourrce definitions
108  0 File inputFile1 = new File(getClass().getResource("/website.demo-project.xml").getFile());
109  0 InputStream inputStream1 = new FileInputStream(inputFile1);
110  0 DataTransporter.importXmlStream(inputStream1, RepositoryConstants.WEBSITE, "/", "test-stream", false, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, true, false);
111   
112  0 File inputFile2 = new File(getClass().getResource("/website.demoFeaturesSiteMap.xml").getFile());
113  0 InputStream inputStream2 = new FileInputStream(inputFile2);
114  0 DataTransporter.importXmlStream(inputStream2, RepositoryConstants.WEBSITE, "/", "test-stream", false, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, true, false);
115   
116  0 final ModuleRegistryImpl moduleRegistry = new ModuleRegistryImpl();
117  0 installContext = new InstallContextImpl(moduleRegistry);
118   
119    }
120   
 
121  0 toggle @Override
122    protected String getRepositoryConfigFileName() {
123  0 String repositoryFileName = "test-siteMap-repositories.xml";
124  0 setRepositoryConfigFileName(repositoryFileName);
125  0 return repositoryFileName;
126    }
127   
 
128  0 toggle @Test
129    @Ignore
130    public void testDoExecuteRootDefinition() throws TaskExecutionException, RepositoryException {
131    // GIVEN
132  0 Set<String> siteDef = new HashSet<String>(Arrays.asList("/demo-features/content-templates", "/demo-features/special-templates/glossary", "/demo-features/content-structure"));
133  0 SiteMapDefinitionMigrationTask task = new SiteMapDefinitionMigrationTask("name", "description", RepositoryConstants.WEBSITE, null);
134  0 assertTrue(websiteSession.nodeExists("/demoFeaturesSiteMap"));
135    // WHEN
136  0 task.doExecute(installContext);
137   
138    // THEN
139  0 assertTrue("Should have a migrated SiteMapDefinition", googleSiteMapSession.nodeExists("/demoFeaturesSiteMap"));
140  0 Node siteMap = googleSiteMapSession.getNode("/demoFeaturesSiteMap");
141  0 assertTrue("Property should have been copied", siteMap.hasProperty("mgnl:template"));
142  0 assertEquals("google-sitemap:pages/siteMapsConfiguration", siteMap.getProperty("mgnl:template").getString());
143  0 assertEquals("/demoFeaturesSiteMap", siteMap.getProperty(SiteMapNodeTypes.SiteMap.URL).getString());
144  0 assertTrue("Property should have been copied", siteMap.hasProperty("mgnl:activationStatus"));
145  0 assertEquals(true, siteMap.getProperty("mgnl:activationStatus").getBoolean());
146  0 assertFalse(siteMap.hasNode("content"));
147  0 assertTrue(siteMap.hasNode(SiteMapNodeTypes.SiteMap.PAGES));
148  0 Node sites = siteMap.getNode(SiteMapNodeTypes.SiteMap.PAGES);
149   
150  0 Node filteredNode = new JCRMgnlPropertiesFilteringNodeWrapper(sites);
151  0 PropertyIterator iterator = filteredNode.getProperties();
152  0 while (iterator.hasNext()) {
153  0 Property property = iterator.nextProperty();
154  0 assertTrue("Migrated content should have this site mapp defined", siteDef.contains(property.getString()));
155    }
156   
157    // assertFalse("No virtual URI mapping should be defined", siteMap.getProperty(GoogleSiteMapConfiguration.INCLUDE_VIRTUAL_URI_MAPPINGS_PROPERTIES).getBoolean());
158   
159  0 assertFalse(websiteSession.nodeExists("/demoFeaturesSiteMap"));
160   
161    }
162   
 
163  0 toggle @Test
164    @Ignore
165    public void testDoExecuteSubFolderDefinition() throws TaskExecutionException, RepositoryException {
166    // GIVEN
167  0 Set<String> siteDef = new HashSet<String>(Arrays.asList("/demo-project/about/subsection-articles", "/demo-project/news-and-events/events-overview"));
168  0 SiteMapDefinitionMigrationTask task = new SiteMapDefinitionMigrationTask("name", "description", RepositoryConstants.WEBSITE, null);
169  0 assertTrue(websiteSession.nodeExists("/demo-project/demoProjectSiteMap"));
170    // WHEN
171  0 task.doExecute(installContext);
172   
173    // THEN
174  0 assertTrue("Should have a migrated SiteMapDefinition", googleSiteMapSession.nodeExists("/demo-project/demoProjectSiteMap"));
175  0 Node siteMap = googleSiteMapSession.getNode("/demo-project/demoProjectSiteMap");
176  0 assertTrue("Property should have been copied", siteMap.hasProperty("mgnl:template"));
177  0 assertEquals("google-sitemap:pages/siteMapsConfiguration", siteMap.getProperty("mgnl:template").getString());
178    // assertEquals("/demo-project/demoProjectSiteMap", siteMap.getProperty(GoogleSiteMapConfiguration.SITE_MAP_URL_PROPERTY_NAME).getString());
179    // assertEquals(SiteMapType.Standard.toString(), siteMap.getProperty(GoogleSiteMapConfiguration.SITE_MAP_TYPE_PROPERTY_NAME).getString());
180  0 assertTrue("Property should have been copied", siteMap.hasProperty("mgnl:activationStatus"));
181  0 assertEquals(true, siteMap.getProperty("mgnl:activationStatus").getBoolean());
182   
183  0 assertFalse(siteMap.hasNode("content"));
184    // assertTrue(siteMap.hasNode(GoogleSiteMapConfiguration.SITE_DIALOG_CONFIGURATION_NAME));
185    // Node sites = siteMap.getNode(GoogleSiteMapConfiguration.SITE_DIALOG_CONFIGURATION_NAME);
186   
187    // Node filteredNode = new JCRMgnlPropertiesFilteringNodeWrapper(sites);
188    // PropertyIterator iterator = filteredNode.getProperties();
189    // while (iterator.hasNext()) {
190    // Property property = iterator.nextProperty();
191    // assertTrue("Migrated content should have this site mapp defined", siteDef.contains(property.getString()));
192    // }
193    //
194    // assertTrue("Virtual URI mapping should be defined", siteMap.getProperty(GoogleSiteMapConfiguration.INCLUDE_VIRTUAL_URI_MAPPINGS_PROPERTIES).getBoolean());
195  0 assertFalse(websiteSession.nodeExists("/demo-project/demoProjectSiteMap"));
196   
197    }
198   
 
199  0 toggle @Test
200    @Ignore
201    public void testDoExecuteConfiguredSearchPath() throws TaskExecutionException, RepositoryException {
202    // GIVEN
203  0 SiteMapDefinitionMigrationTask task = new SiteMapDefinitionMigrationTask("name", "description", RepositoryConstants.WEBSITE, "/demo-project");
204   
205    // WHEN
206  0 task.doExecute(installContext);
207   
208    // THEN
209  0 assertTrue("Should have a migrated SiteMapDefinition", googleSiteMapSession.nodeExists("/demo-project/demoProjectSiteMap"));
210  0 assertFalse("Should not have a migrated SiteMapDefinition", googleSiteMapSession.nodeExists("/demoFeaturesSiteMap"));
211  0 assertFalse(websiteSession.nodeExists("/demo-project/demoProjectSiteMap"));
212  0 assertTrue(websiteSession.nodeExists("/demoFeaturesSiteMap"));
213    }
214   
215    }