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.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.v7.data.util.BeanItem; |
57 |
|
|
58 |
|
|
59 |
|
@link |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (58) |
Complexity: 4 |
Complexity Density: 0.07 |
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
70 |
3 |
@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 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
90 |
1 |
@Test... |
91 |
|
public void executeSaveEmptyNode() throws RepositoryException, ActionExecutionException { |
92 |
|
|
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 |
|
|
100 |
1 |
action.execute(); |
101 |
|
|
102 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
113 |
1 |
@Test... |
114 |
|
public void executeSaveExistingNode() throws RepositoryException, ActionExecutionException { |
115 |
|
|
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 |
|
|
128 |
1 |
action.execute(); |
129 |
|
|
130 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
140 |
1 |
@Test... |
141 |
|
public void executeSaveDefaultValue() throws RepositoryException, ActionExecutionException { |
142 |
|
|
143 |
1 |
BeanItem<SiteMapEntry> item = new BeanItem<SiteMapEntry>(entry); |
144 |
|
|
145 |
1 |
SaveSiteMapEntryDialogAction action = new SaveSiteMapEntryDialogAction(definition, item, validator, callback, service); |
146 |
|
|
147 |
|
|
148 |
1 |
action.execute(); |
149 |
|
|
150 |
|
|
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 |
|
} |