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.for2_1; |
35 |
|
|
36 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
37 |
|
import static org.hamcrest.core.Is.is; |
38 |
|
|
39 |
|
import info.magnolia.context.MgnlContext; |
40 |
|
import info.magnolia.jcr.util.NodeTypes; |
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.module.googlesitemap.SiteMapNodeTypes.SiteMap; |
47 |
|
import info.magnolia.test.hamcrest.NodeMatchers; |
48 |
|
import info.magnolia.test.mock.MockContext; |
49 |
|
import info.magnolia.test.mock.MockUtil; |
50 |
|
import info.magnolia.test.mock.jcr.MockSession; |
51 |
|
|
52 |
|
import javax.jcr.Node; |
53 |
|
import javax.jcr.RepositoryException; |
54 |
|
|
55 |
|
import org.junit.After; |
56 |
|
import org.junit.Before; |
57 |
|
import org.junit.Test; |
58 |
|
|
59 |
|
|
60 |
|
@link |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 3 |
Complexity Density: 0.1 |
|
62 |
|
public class UpdatePropertyNamesAndNodeStructureTest { |
63 |
|
|
64 |
|
private Node googleSite; |
65 |
|
private InstallContextImpl installContext; |
66 |
|
private UpdatePropertyNamesAndNodeStructure task; |
67 |
|
private MockSession session; |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
69 |
1 |
@Before... |
70 |
|
public void setUp() throws Exception { |
71 |
1 |
MockUtil.initMockContext(); |
72 |
1 |
session = new MockSession(GoogleSiteMapConfiguration.WORKSPACE); |
73 |
1 |
Node root = session.getRootNode(); |
74 |
1 |
googleSite = root.addNode("siteMap", SiteMapNodeTypes.SiteMap.NAME); |
75 |
1 |
((MockContext) MgnlContext.getInstance()).addSession(GoogleSiteMapConfiguration.WORKSPACE, session); |
76 |
1 |
((MockContext) MgnlContext.getSystemContext()).addSession(GoogleSiteMapConfiguration.WORKSPACE, session); |
77 |
|
|
78 |
1 |
final ModuleRegistryImpl moduleRegistry = new ModuleRegistryImpl(); |
79 |
1 |
installContext = new InstallContextImpl(moduleRegistry); |
80 |
|
|
81 |
1 |
task = new UpdatePropertyNamesAndNodeStructure("taskName", "taskDescription"); |
82 |
|
|
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
1 |
@After... |
86 |
|
public void tearDown() { |
87 |
1 |
MgnlContext.setInstance(null); |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
90 |
1 |
@Test... |
91 |
|
public void testSitePagePropertyMigration() throws RepositoryException, TaskExecutionException { |
92 |
|
|
93 |
1 |
googleSite.setProperty("displayName", "displayName"); |
94 |
1 |
googleSite.setProperty("type", "type"); |
95 |
1 |
googleSite.setProperty("url", "url"); |
96 |
1 |
googleSite.setProperty("includeVirtualURIMappings", "includeVirtualURIMappings"); |
97 |
1 |
googleSite.setProperty(SiteMap.DEFAULT_PRIORITY, 0.6d); |
98 |
1 |
Node sites = googleSite.addNode("sites", NodeTypes.ContentNode.NAME); |
99 |
1 |
sites.setProperty("0", "/site1"); |
100 |
1 |
sites.setProperty("1", "/site2"); |
101 |
|
|
102 |
|
|
103 |
1 |
task.execute(installContext); |
104 |
|
|
105 |
|
|
106 |
1 |
googleSite = session.getNode("siteMap"); |
107 |
1 |
assertThat(googleSite, NodeMatchers.hasProperty(SiteMap.DISPLAY_NAME, "displayName")); |
108 |
1 |
assertThat(googleSite, NodeMatchers.hasProperty(SiteMap.TYPE, "type")); |
109 |
1 |
assertThat(googleSite, NodeMatchers.hasProperty(SiteMap.URL, "url")); |
110 |
1 |
assertThat(googleSite, NodeMatchers.hasProperty(SiteMap.INCLUDE_VIRTUAL_URI, "includeVirtualURIMappings")); |
111 |
|
|
112 |
1 |
assertThat(googleSite, NodeMatchers.hasProperty(SiteMap.DEFAULT_CHANGEFREQ, GoogleSiteMapConfiguration.DEFAULT_CHANGE_FREQUENCY)); |
113 |
1 |
assertThat(googleSite, NodeMatchers.hasProperty(SiteMap.DEFAULT_PRIORITY, 0.6d)); |
114 |
|
|
115 |
1 |
assertThat(googleSite, NodeMatchers.hasProperty(SiteMap.PAGES)); |
116 |
1 |
assertThat(googleSite.getProperty(SiteMap.PAGES).getValues()[0].getString(), is("/site1")); |
117 |
1 |
assertThat(googleSite.getProperty(SiteMap.PAGES).getValues()[1].getString(), is("/site2")); |
118 |
|
} |
119 |
|
|
120 |
|
} |