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
61
62 public class UpdatePropertyNamesAndNodeStructureTest {
63
64 private Node googleSite;
65 private InstallContextImpl installContext;
66 private UpdatePropertyNamesAndNodeStructure task;
67 private MockSession session;
68
69 @Before
70 public void setUp() throws Exception {
71 MockUtil.initMockContext();
72 session = new MockSession(GoogleSiteMapConfiguration.WORKSPACE);
73 Node root = session.getRootNode();
74 googleSite = root.addNode("siteMap", SiteMapNodeTypes.SiteMap.NAME);
75 ((MockContext) MgnlContext.getInstance()).addSession(GoogleSiteMapConfiguration.WORKSPACE, session);
76 ((MockContext) MgnlContext.getSystemContext()).addSession(GoogleSiteMapConfiguration.WORKSPACE, session);
77
78 final ModuleRegistryImpl moduleRegistry = new ModuleRegistryImpl();
79 installContext = new InstallContextImpl(moduleRegistry);
80
81 task = new UpdatePropertyNamesAndNodeStructure("taskName", "taskDescription");
82
83 }
84
85 @After
86 public void tearDown() {
87 MgnlContext.setInstance(null);
88 }
89
90 @Test
91 public void testSitePagePropertyMigration() throws RepositoryException, TaskExecutionException {
92
93 googleSite.setProperty("displayName", "displayName");
94 googleSite.setProperty("type", "type");
95 googleSite.setProperty("url", "url");
96 googleSite.setProperty("includeVirtualURIMappings", "includeVirtualURIMappings");
97 googleSite.setProperty(SiteMap.DEFAULT_PRIORITY, 0.6d);
98 Node sites = googleSite.addNode("sites", NodeTypes.ContentNode.NAME);
99 sites.setProperty("0", "/site1");
100 sites.setProperty("1", "/site2");
101
102
103 task.execute(installContext);
104
105
106 googleSite = session.getNode("siteMap");
107 assertThat(googleSite, NodeMatchers.hasProperty(SiteMap.DISPLAY_NAME, "displayName"));
108 assertThat(googleSite, NodeMatchers.hasProperty(SiteMap.TYPE, "type"));
109 assertThat(googleSite, NodeMatchers.hasProperty(SiteMap.URL, "url"));
110 assertThat(googleSite, NodeMatchers.hasProperty(SiteMap.INCLUDE_VIRTUAL_URI, "includeVirtualURIMappings"));
111
112 assertThat(googleSite, NodeMatchers.hasProperty(SiteMap.DEFAULT_CHANGEFREQ, GoogleSiteMapConfiguration.DEFAULT_CHANGE_FREQUENCY));
113 assertThat(googleSite, NodeMatchers.hasProperty(SiteMap.DEFAULT_PRIORITY, 0.6d));
114
115 assertThat(googleSite, NodeMatchers.hasProperty(SiteMap.PAGES));
116 assertThat(googleSite.getProperty(SiteMap.PAGES).getValues()[0].getString(), is("/site1"));
117 assertThat(googleSite.getProperty(SiteMap.PAGES).getValues()[1].getString(), is("/site2"));
118 }
119
120 }