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.app.subapp.sitemapdetail.actions

File SaveSiteMapEntryDialogActionTest.java

 

Code metrics

0
54
4
1
160
93
4
0.07
13.5
4
1

Classes

Class Line # Actions
SaveSiteMapEntryDialogActionTest 61 54 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /**
2    * This file Copyright (c) 2013-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.app.subapp.sitemapdetail.actions;
35   
36    import static org.junit.Assert.*;
37    import static org.mockito.Mockito.*;
38   
39    import info.magnolia.context.MgnlContext;
40    import info.magnolia.jcr.util.NodeTypes;
41    import info.magnolia.module.googlesitemap.GoogleSiteMapConfiguration;
42    import info.magnolia.module.googlesitemap.SiteMapNodeTypes;
43    import info.magnolia.module.googlesitemap.SiteMapTestUtil;
44    import info.magnolia.module.googlesitemap.bean.SiteMapEntry;
45    import info.magnolia.module.googlesitemap.service.SiteMapService;
46    import info.magnolia.repository.RepositoryConstants;
47    import info.magnolia.ui.api.action.ActionExecutionException;
48   
49    import javax.jcr.Node;
50    import javax.jcr.RepositoryException;
51    import javax.jcr.Session;
52   
53    import org.junit.Before;
54    import org.junit.Test;
55   
56    import com.vaadin.data.util.BeanItem;
57   
58    /**
59    * test class for {@link SaveSiteMapEntryDialogAction}.
60    */
 
61    public class SaveSiteMapEntryDialogActionTest extends SiteMapTestUtil {
62    private GoogleMapEditorCallbackTest callback;
63    private GoogleMapEditorValidatorTest validator;
64    private SaveSiteMapEntryDialogActionDefinition definition;
65    private SiteMapService service;
66   
67    private Node page;
68    private SiteMapEntry entry;
69   
 
70  3 toggle @Override
71    @Before
72    public void setUp() throws Exception {
73  3 super.setUp();
74  3 callback = new GoogleMapEditorCallbackTest();
75  3 validator = new GoogleMapEditorValidatorTest();
76  3 definition = new SaveSiteMapEntryDialogActionDefinition();
77  3 definition.setName("save");
78  3 definition.setLabel("label");
79   
80    // Init page
81  3 Session webSiteSession = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE);
82  3 this.page = webSiteSession.getRootNode().addNode("page", NodeTypes.Page.NAME);
83  3 NodeTypes.LastModified.update(page);
84  3 this.entry = new SiteMapEntry(new GoogleSiteMapConfiguration(), null, this.page, 1, "weekly", 0.5d);
85   
86  3 service = mock(SiteMapService.class);
87  3 when(service.updatePageNode(entry)).thenCallRealMethod();
88    }
89   
 
90  1 toggle @Test
91    public void executeSaveEmptyNode() throws RepositoryException, ActionExecutionException {
92    // GIVEN
93  1 BeanItem<SiteMapEntry> item = new BeanItem<SiteMapEntry>(entry);
94  1 entry.setChangefreq("Daly");
95  1 entry.setPriority(0.2d);
96  1 entry.setHide(true);
97   
98  1 SaveSiteMapEntryDialogAction action = new SaveSiteMapEntryDialogAction(definition, item, validator, callback, service);
99    // WHEN
100  1 action.execute();
101   
102    // THEN
103  1 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_CHANGEFREQ));
104  1 assertEquals("Daly", page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_CHANGEFREQ).getString());
105  1 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_PRIORITY));
106  1 assertEquals(0.2d, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_PRIORITY).getDouble(), 0);
107  1 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP));
108  1 assertEquals(true, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP).getBoolean());
109  1 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN));
110  1 assertEquals(false, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN).getBoolean());
111    }
112   
 
113  1 toggle @Test
114    public void executeSaveExistingNode() throws RepositoryException, ActionExecutionException {
115    // GIVEN
116  1 page.setProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_CHANGEFREQ, "Monthly");
117  1 page.setProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_PRIORITY, 0.9d);
118  1 page.setProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN, true);
119  1 page.getSession().save();
120  1 BeanItem<SiteMapEntry> item = new BeanItem<SiteMapEntry>(entry);
121  1 entry.setChangefreq("Daly");
122  1 entry.setPriority(0.2d);
123  1 entry.setHide(true);
124   
125  1 SaveSiteMapEntryDialogAction action = new SaveSiteMapEntryDialogAction(definition, item, validator, callback, service);
126   
127    // WHEN
128  1 action.execute();
129   
130    // THEN
131  1 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_CHANGEFREQ));
132  1 assertEquals("Daly", page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_CHANGEFREQ).getString());
133  1 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_PRIORITY));
134  1 assertEquals(0.2d, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_PRIORITY).getDouble(), 0);
135  1 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP));
136  1 assertEquals(true, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP).getBoolean());
137  1 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN));
138    }
139   
 
140  1 toggle @Test
141    public void executeSaveDefaultValue() throws RepositoryException, ActionExecutionException {
142    // GIVEN
143  1 BeanItem<SiteMapEntry> item = new BeanItem<SiteMapEntry>(entry);
144   
145  1 SaveSiteMapEntryDialogAction action = new SaveSiteMapEntryDialogAction(definition, item, validator, callback, service);
146   
147    // WHEN
148  1 action.execute();
149   
150    // THEN
151  1 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_CHANGEFREQ));
152  1 assertEquals("weekly", page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_CHANGEFREQ).getString());
153  1 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_PRIORITY));
154  1 assertEquals(0.5d, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_PRIORITY).getDouble(), 0);
155  1 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP));
156  1 assertEquals(false, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP).getBoolean());
157  1 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN));
158  1 assertEquals(false, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN).getBoolean());
159    }
160    }