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
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 @Override
71 @Before
72 public void setUp() throws Exception {
73 super.setUp();
74 callback = new GoogleMapEditorCallbackTest();
75 validator = new GoogleMapEditorValidatorTest();
76 definition = new SaveSiteMapEntryDialogActionDefinition();
77 definition.setName("save");
78 definition.setLabel("label");
79
80
81 Session webSiteSession = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE);
82 this.page = webSiteSession.getRootNode().addNode("page", NodeTypes.Page.NAME);
83 NodeTypes.LastModified.update(page);
84 this.entry = new SiteMapEntry(new GoogleSiteMapConfiguration(), null, this.page, 1, "weekly", 0.5d);
85
86 service = mock(SiteMapService.class);
87 when(service.updatePageNode(entry)).thenCallRealMethod();
88 }
89
90 @Test
91 public void executeSaveEmptyNode() throws RepositoryException, ActionExecutionException {
92
93 BeanItem<SiteMapEntry> item = new BeanItem<SiteMapEntry>(entry);
94 entry.setChangefreq("Daly");
95 entry.setPriority(0.2d);
96 entry.setHide(true);
97
98 SaveSiteMapEntryDialogAction action = new SaveSiteMapEntryDialogAction(definition, item, validator, callback, service);
99
100 action.execute();
101
102
103 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_CHANGEFREQ));
104 assertEquals("Daly", page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_CHANGEFREQ).getString());
105 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_PRIORITY));
106 assertEquals(0.2d, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_PRIORITY).getDouble(), 0);
107 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP));
108 assertEquals(true, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP).getBoolean());
109 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN));
110 assertEquals(false, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN).getBoolean());
111 }
112
113 @Test
114 public void executeSaveExistingNode() throws RepositoryException, ActionExecutionException {
115
116 page.setProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_CHANGEFREQ, "Monthly");
117 page.setProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_PRIORITY, 0.9d);
118 page.setProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN, true);
119 page.getSession().save();
120 BeanItem<SiteMapEntry> item = new BeanItem<SiteMapEntry>(entry);
121 entry.setChangefreq("Daly");
122 entry.setPriority(0.2d);
123 entry.setHide(true);
124
125 SaveSiteMapEntryDialogAction action = new SaveSiteMapEntryDialogAction(definition, item, validator, callback, service);
126
127
128 action.execute();
129
130
131 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_CHANGEFREQ));
132 assertEquals("Daly", page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_CHANGEFREQ).getString());
133 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_PRIORITY));
134 assertEquals(0.2d, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_PRIORITY).getDouble(), 0);
135 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP));
136 assertEquals(true, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP).getBoolean());
137 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN));
138 }
139
140 @Test
141 public void executeSaveDefaultValue() throws RepositoryException, ActionExecutionException {
142
143 BeanItem<SiteMapEntry> item = new BeanItem<SiteMapEntry>(entry);
144
145 SaveSiteMapEntryDialogAction action = new SaveSiteMapEntryDialogAction(definition, item, validator, callback, service);
146
147
148 action.execute();
149
150
151 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_CHANGEFREQ));
152 assertEquals("weekly", page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_CHANGEFREQ).getString());
153 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_PRIORITY));
154 assertEquals(0.5d, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_PRIORITY).getDouble(), 0);
155 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP));
156 assertEquals(false, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP).getBoolean());
157 assertTrue(page.hasProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN));
158 assertEquals(false, page.getProperty(SiteMapNodeTypes.GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN).getBoolean());
159 }
160 }