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.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 |
|
|
|
|
| 0% |
Uncovered Elements: 63 (63) |
Complexity: 7 |
Complexity Density: 0.12 |
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 2 |
Complexity Density: 0.13 |
|
92 |
0 |
@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 |
|
|
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 |
|
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
121 |
0 |
@Override... |
122 |
|
protected String getRepositoryConfigFileName() { |
123 |
0 |
String repositoryFileName = "test-siteMap-repositories.xml"; |
124 |
0 |
setRepositoryConfigFileName(repositoryFileName); |
125 |
0 |
return repositoryFileName; |
126 |
|
} |
127 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 2 |
Complexity Density: 0.1 |
4-
|
|
128 |
0 |
@Test... |
129 |
|
@Ignore |
130 |
|
public void testDoExecuteRootDefinition() throws TaskExecutionException, RepositoryException { |
131 |
|
|
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 |
|
|
136 |
0 |
task.doExecute(installContext); |
137 |
|
|
138 |
|
|
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 |
|
|
158 |
|
|
159 |
0 |
assertFalse(websiteSession.nodeExists("/demoFeaturesSiteMap")); |
160 |
|
|
161 |
|
} |
162 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
4-
|
|
163 |
0 |
@Test... |
164 |
|
@Ignore |
165 |
|
public void testDoExecuteSubFolderDefinition() throws TaskExecutionException, RepositoryException { |
166 |
|
|
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 |
|
|
171 |
0 |
task.doExecute(installContext); |
172 |
|
|
173 |
|
|
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 |
|
|
179 |
|
|
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 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
0 |
assertFalse(websiteSession.nodeExists("/demo-project/demoProjectSiteMap")); |
196 |
|
|
197 |
|
} |
198 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
4-
|
|
199 |
0 |
@Test... |
200 |
|
@Ignore |
201 |
|
public void testDoExecuteConfiguredSearchPath() throws TaskExecutionException, RepositoryException { |
202 |
|
|
203 |
0 |
SiteMapDefinitionMigrationTask task = new SiteMapDefinitionMigrationTask("name", "description", RepositoryConstants.WEBSITE, "/demo-project"); |
204 |
|
|
205 |
|
|
206 |
0 |
task.doExecute(installContext); |
207 |
|
|
208 |
|
|
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 |
|
} |