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
38 import info.magnolia.context.MgnlContext;
39 import info.magnolia.jcr.util.NodeTypes;
40 import info.magnolia.module.InstallContextImpl;
41 import info.magnolia.module.ModuleRegistryImpl;
42 import info.magnolia.module.delta.TaskExecutionException;
43 import info.magnolia.module.googlesitemap.SiteMapNodeTypes.GoogleSiteMap;
44 import info.magnolia.repository.RepositoryConstants;
45 import info.magnolia.test.RepositoryTestCase;
46 import info.magnolia.test.hamcrest.NodeMatchers;
47
48 import javax.jcr.Node;
49 import javax.jcr.RepositoryException;
50 import javax.jcr.Session;
51
52 import org.junit.Before;
53 import org.junit.Test;
54
55
56
57
58 public class RenameSiteMapeSitePagesPropertyNameTest extends RepositoryTestCase {
59
60 private Session session;
61 private InstallContextImpl installContext;
62 private Node pageNode;
63 private RenameSiteMapeSitePagesPropertyName task;
64
65 @Override
66 @Before
67 public void setUp() throws Exception {
68 super.setUp();
69 session = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE);
70 Node root = session.getRootNode();
71 pageNode = root.addNode("page", NodeTypes.Page.NAME);
72
73 final ModuleRegistryImpl moduleRegistry = new ModuleRegistryImpl();
74 installContext = new InstallContextImpl(moduleRegistry);
75
76 task = new RenameSiteMapeSitePagesPropertyName("taskName", "taskDescription", RepositoryConstants.WEBSITE);
77
78 }
79
80
81 @Test
82 public void testSitePagePropertyUpdate() throws RepositoryException, TaskExecutionException {
83
84 pageNode.setProperty("googleSitemapChangefreq", "googleSitemapChangefreq");
85 pageNode.setProperty("googleSitemapHide", "googleSitemapHide");
86 pageNode.setProperty("googleSitemapPriority", "googleSitemapPriority");
87 pageNode.setProperty("googleSitemapHideChildren", "googleSitemapHideChildren");
88 pageNode.setProperty("tutu", "tutu");
89 session.save();
90
91
92 task.execute(installContext);
93
94
95 pageNode = session.getNode("/page");
96 assertThat(pageNode, NodeMatchers.hasProperty(GoogleSiteMap.SITEMAP_CHANGEFREQ, "googleSitemapChangefreq"));
97 assertThat(pageNode, NodeMatchers.hasProperty(GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP, "googleSitemapHide"));
98 assertThat(pageNode, NodeMatchers.hasProperty(GoogleSiteMap.SITEMAP_PRIORITY, "googleSitemapPriority"));
99 assertThat(pageNode, NodeMatchers.hasProperty(GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN, "googleSitemapHideChildren"));
100 assertThat(pageNode, NodeMatchers.hasProperty("tutu", "tutu"));
101 }
102
103 @Test
104 public void testNoUpdate() throws RepositoryException, TaskExecutionException {
105
106 Node contentNode = session.getRootNode().addNode("contentNode", NodeTypes.ContentNode.NAME);
107 contentNode.setProperty("googleSitemapChangefreq", "googleSitemapChangefreq");
108 contentNode.setProperty("tutu", "tutu");
109 session.save();
110
111
112 task.execute(installContext);
113
114
115 contentNode = session.getNode("/contentNode");
116 assertThat(contentNode, NodeMatchers.hasProperty("googleSitemapChangefreq", "googleSitemapChangefreq"));
117 assertThat(contentNode, NodeMatchers.hasProperty("tutu", "tutu"));
118 }
119 }