1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
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 |
|
@link |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (60) |
Complexity: 5 |
Complexity Density: 0.09 |
|
55 |
|
public class SaveSiteMapActionTest extends SiteMapTestUtil { |
56 |
|
|
57 |
|
private GoogleMapEditorCallbackTest callback; |
58 |
|
private GoogleMapEditorValidatorTest validator; |
59 |
|
private SaveSiteMapActionDefinition definition; |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
61 |
4 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
72 |
1 |
@Test... |
73 |
|
public void executeSaveNewSiteMap() throws RepositoryException, ActionExecutionException { |
74 |
|
|
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 |
|
|
81 |
1 |
action.execute(); |
82 |
|
|
83 |
|
|
84 |
1 |
assertEquals("onSuccess(save)", this.callback.getCallbackActionCalled()); |
85 |
1 |
assertTrue(googleSiteMapSession.getRootNode().hasNode("displayName")); |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
88 |
1 |
@Test... |
89 |
|
public void executeSaveExistingSiteMap() throws RepositoryException, ActionExecutionException { |
90 |
|
|
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 |
|
|
100 |
1 |
action.execute(); |
101 |
|
|
102 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
108 |
1 |
@Test... |
109 |
|
public void executeSaveExistingSiteMapWithNewName() throws RepositoryException, ActionExecutionException { |
110 |
|
|
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 |
|
|
121 |
1 |
action.execute(); |
122 |
|
|
123 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
131 |
1 |
@Test... |
132 |
|
public void executeSaveExistingSiteMapWithExistingNewName() throws RepositoryException, ActionExecutionException { |
133 |
|
|
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 |
|
|
145 |
1 |
action.execute(); |
146 |
|
|
147 |
|
|
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 |
|
} |