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.for2_1

File RenameSiteMapeSitePagesPropertyNameTest.java

 

Code metrics

0
28
3
1
119
60
3
0.11
9.33
3
1

Classes

Class Line # Actions
RenameSiteMapeSitePagesPropertyNameTest 58 28 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /**
2    * This file Copyright (c) 2014-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.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    * Main test class for {@link RenameSiteMapeSitePagesPropertyName}.
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  2 toggle @Override
66    @Before
67    public void setUp() throws Exception {
68  2 super.setUp();
69  2 session = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE);
70  2 Node root = session.getRootNode();
71  2 pageNode = root.addNode("page", NodeTypes.Page.NAME);
72   
73  2 final ModuleRegistryImpl moduleRegistry = new ModuleRegistryImpl();
74  2 installContext = new InstallContextImpl(moduleRegistry);
75   
76  2 task = new RenameSiteMapeSitePagesPropertyName("taskName", "taskDescription", RepositoryConstants.WEBSITE);
77   
78    }
79   
80   
 
81  1 toggle @Test
82    public void testSitePagePropertyUpdate() throws RepositoryException, TaskExecutionException {
83    // GIVEN
84  1 pageNode.setProperty("googleSitemapChangefreq", "googleSitemapChangefreq");
85  1 pageNode.setProperty("googleSitemapHide", "googleSitemapHide");
86  1 pageNode.setProperty("googleSitemapPriority", "googleSitemapPriority");
87  1 pageNode.setProperty("googleSitemapHideChildren", "googleSitemapHideChildren");
88  1 pageNode.setProperty("tutu", "tutu");
89  1 session.save();
90   
91    // WHEN
92  1 task.execute(installContext);
93   
94    // THEN
95  1 pageNode = session.getNode("/page");
96  1 assertThat(pageNode, NodeMatchers.hasProperty(GoogleSiteMap.SITEMAP_CHANGEFREQ, "googleSitemapChangefreq"));
97  1 assertThat(pageNode, NodeMatchers.hasProperty(GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP, "googleSitemapHide"));
98  1 assertThat(pageNode, NodeMatchers.hasProperty(GoogleSiteMap.SITEMAP_PRIORITY, "googleSitemapPriority"));
99  1 assertThat(pageNode, NodeMatchers.hasProperty(GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN, "googleSitemapHideChildren"));
100  1 assertThat(pageNode, NodeMatchers.hasProperty("tutu", "tutu"));
101    }
102   
 
103  1 toggle @Test
104    public void testNoUpdate() throws RepositoryException, TaskExecutionException {
105    // GIVEN
106  1 Node contentNode = session.getRootNode().addNode("contentNode", NodeTypes.ContentNode.NAME);
107  1 contentNode.setProperty("googleSitemapChangefreq", "googleSitemapChangefreq");
108  1 contentNode.setProperty("tutu", "tutu");
109  1 session.save();
110   
111    // WHEN
112  1 task.execute(installContext);
113   
114    // THEN
115  1 contentNode = session.getNode("/contentNode");
116  1 assertThat(contentNode, NodeMatchers.hasProperty("googleSitemapChangefreq", "googleSitemapChangefreq"));
117  1 assertThat(contentNode, NodeMatchers.hasProperty("tutu", "tutu"));
118    }
119    }