View Javadoc
1   /**
2    * This file Copyright (c) 2014-2018 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      @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          // GIVEN
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          // WHEN
92          task.execute(installContext);
93  
94          // THEN
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         // GIVEN
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         // WHEN
112         task.execute(installContext);
113 
114         // THEN
115         contentNode = session.getNode("/contentNode");
116         assertThat(contentNode, NodeMatchers.hasProperty("googleSitemapChangefreq", "googleSitemapChangefreq"));
117         assertThat(contentNode, NodeMatchers.hasProperty("tutu", "tutu"));
118     }
119 }