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

File SaveSiteMapActionTest.java

 

Code metrics

0
55
5
1
156
88
5
0.09
11
5
1

Classes

Class Line # Actions
SaveSiteMapActionTest 55 55 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 4 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.actions;
35   
36    import static org.junit.Assert.*;
37   
38    import info.magnolia.module.googlesitemap.SiteMapNodeTypes;
39    import info.magnolia.module.googlesitemap.SiteMapTestUtil;
40    import info.magnolia.ui.api.action.ActionExecutionException;
41    import info.magnolia.ui.vaadin.integration.jcr.JcrNewNodeAdapter;
42    import info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter;
43   
44    import javax.jcr.Node;
45    import javax.jcr.RepositoryException;
46   
47    import org.junit.Before;
48    import org.junit.Test;
49   
50    import com.vaadin.data.util.ObjectProperty;
51   
52    /**
53    * Test class for {@link SaveSiteMapAction}.
54    */
 
55    public class SaveSiteMapActionTest extends SiteMapTestUtil {
56   
57    private GoogleMapEditorCallbackTest callback;
58    private GoogleMapEditorValidatorTest validator;
59    private SaveSiteMapActionDefinition definition;
60   
 
61  4 toggle @Override
62    @Before
63    public void setUp() throws Exception {
64  4 super.setUp();
65  4 callback = new GoogleMapEditorCallbackTest();
66  4 validator = new GoogleMapEditorValidatorTest();
67  4 definition = new SaveSiteMapActionDefinition();
68  4 definition.setName("save");
69  4 definition.setLabel("label");
70    }
71   
 
72  1 toggle @Test
73    public void executeSaveNewSiteMap() throws RepositoryException, ActionExecutionException {
74    // GIVEN
75  1 Node rootNode = googleSiteMapSession.getRootNode();
76  1 JcrNewNodeAdapter item = new JcrNewNodeAdapter(rootNode, SiteMapNodeTypes.SiteMap.NAME);
77  1 item.addItemProperty(SiteMapNodeTypes.SiteMap.DISPLAY_NAME, new ObjectProperty<String>("displayName"));
78  1 SaveSiteMapAction action = new SaveSiteMapAction(definition, item, validator, callback);
79   
80    // WHEN
81  1 action.execute();
82   
83    // THEN
84  1 assertEquals("onSuccess(save)", this.callback.getCallbackActionCalled());
85  1 assertTrue(googleSiteMapSession.getRootNode().hasNode("displayName"));
86    }
87   
 
88  1 toggle @Test
89    public void executeSaveExistingSiteMap() throws RepositoryException, ActionExecutionException {
90    // GIVEN
91  1 Node rootNode = googleSiteMapSession.getRootNode();
92  1 Node displayName = rootNode.addNode("display Name", SiteMapNodeTypes.SiteMap.NAME);
93  1 displayName.setProperty(SiteMapNodeTypes.SiteMap.URL, "initial_url");
94  1 displayName.setProperty(SiteMapNodeTypes.SiteMap.DISPLAY_NAME, "display Name");
95  1 JcrNodeAdapter item = new JcrNodeAdapter(displayName);
96  1 item.addItemProperty(SiteMapNodeTypes.SiteMap.URL, new ObjectProperty<String>("changed_url"));
97  1 SaveSiteMapAction action = new SaveSiteMapAction(definition, item, validator, callback);
98   
99    // WHEN
100  1 action.execute();
101   
102    // THEN
103  1 assertEquals("onSuccess(save)", this.callback.getCallbackActionCalled());
104  1 assertTrue(googleSiteMapSession.getRootNode().hasNode("display Name"));
105  1 assertEquals("changed_url", displayName.getProperty(SiteMapNodeTypes.SiteMap.URL).getString());
106    }
107   
 
108  1 toggle @Test
109    public void executeSaveExistingSiteMapWithNewName() throws RepositoryException, ActionExecutionException {
110    // GIVEN
111  1 Node rootNode = googleSiteMapSession.getRootNode();
112  1 Node displayName = rootNode.addNode("displayName", SiteMapNodeTypes.SiteMap.NAME);
113  1 displayName.setProperty(SiteMapNodeTypes.SiteMap.URL, "initial_url");
114  1 displayName.setProperty(SiteMapNodeTypes.SiteMap.TYPE, "initial_type");
115  1 JcrNodeAdapter item = new JcrNodeAdapter(displayName);
116  1 item.addItemProperty(SiteMapNodeTypes.SiteMap.URL, new ObjectProperty<String>("changed_url"));
117  1 item.addItemProperty(SiteMapNodeTypes.SiteMap.DISPLAY_NAME, new ObjectProperty<String>("new_displayName"));
118  1 SaveSiteMapAction action = new SaveSiteMapAction(definition, item, validator, callback);
119   
120    // WHEN
121  1 action.execute();
122   
123    // THEN
124  1 assertEquals("onSuccess(save)", this.callback.getCallbackActionCalled());
125  1 assertFalse(googleSiteMapSession.getRootNode().hasNode("displayName"));
126  1 assertTrue(googleSiteMapSession.getRootNode().hasNode("new_displayName"));
127  1 assertEquals("changed_url", displayName.getProperty(SiteMapNodeTypes.SiteMap.URL).getString());
128  1 assertEquals("initial_type", displayName.getProperty(SiteMapNodeTypes.SiteMap.TYPE).getString());
129    }
130   
 
131  1 toggle @Test
132    public void executeSaveExistingSiteMapWithExistingNewName() throws RepositoryException, ActionExecutionException {
133    // GIVEN
134  1 Node rootNode = googleSiteMapSession.getRootNode();
135  1 Node displayName = rootNode.addNode("displayName", SiteMapNodeTypes.SiteMap.NAME);
136  1 Node existingDisplayName = rootNode.addNode("new_displayName", SiteMapNodeTypes.SiteMap.NAME);
137  1 displayName.setProperty(SiteMapNodeTypes.SiteMap.URL, "initial_url");
138  1 displayName.setProperty(SiteMapNodeTypes.SiteMap.TYPE, "initial_type");
139  1 JcrNodeAdapter item = new JcrNodeAdapter(displayName);
140  1 item.addItemProperty(SiteMapNodeTypes.SiteMap.URL, new ObjectProperty<String>("changed_url"));
141  1 item.addItemProperty(SiteMapNodeTypes.SiteMap.DISPLAY_NAME, new ObjectProperty<String>("new_displayName"));
142  1 SaveSiteMapAction action = new SaveSiteMapAction(definition, item, validator, callback);
143   
144    // WHEN
145  1 action.execute();
146   
147    // THEN
148  1 assertEquals("onSuccess(save)", this.callback.getCallbackActionCalled());
149  1 assertFalse(googleSiteMapSession.getRootNode().hasNode("displayName"));
150  1 assertFalse(existingDisplayName.hasProperty(SiteMapNodeTypes.SiteMap.URL));
151  1 assertTrue(googleSiteMapSession.getRootNode().hasNode("new_displayName0"));
152  1 assertEquals("new_displayName0", displayName.getName());
153  1 assertEquals("changed_url", displayName.getProperty(SiteMapNodeTypes.SiteMap.URL).getString());
154  1 assertEquals("initial_type", displayName.getProperty(SiteMapNodeTypes.SiteMap.TYPE).getString());
155    }
156    }