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 UpdatePropertyNamesAndNodeStructureTest.java

 

Code metrics

0
29
3
1
120
64
3
0.1
9.67
3
1

Classes

Class Line # Actions
UpdatePropertyNamesAndNodeStructureTest 62 29 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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    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    * Main test class for {@link UpdatePropertyNamesAndNodeStructure}.
61    */
 
62    public class UpdatePropertyNamesAndNodeStructureTest {
63   
64    private Node googleSite;
65    private InstallContextImpl installContext;
66    private UpdatePropertyNamesAndNodeStructure task;
67    private MockSession session;
68   
 
69  1 toggle @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   
 
85  1 toggle @After
86    public void tearDown() {
87  1 MgnlContext.setInstance(null);
88    }
89   
 
90  1 toggle @Test
91    public void testSitePagePropertyMigration() throws RepositoryException, TaskExecutionException {
92    // GIVEN
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    // WHEN
103  1 task.execute(installContext);
104   
105    // THEN
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    }