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.service;
35
36 import static org.junit.Assert.assertEquals;
37 import info.magnolia.module.googlesitemap.SiteMapTestUtil;
38 import info.magnolia.module.googlesitemap.bean.SiteMapEntry;
39
40 import java.util.List;
41
42 import javax.jcr.RepositoryException;
43
44 import org.junit.Before;
45 import org.junit.Test;
46
47
48
49
50
51
52
53 public class SiteMapServiceTest extends SiteMapTestUtil {
54
55 @Override
56 @Before
57 public void setUp() throws RepositoryException{
58 super.setUp();
59 initService();
60 }
61
62
63 @Test
64 public void testSiteMapBeanForSiteNotForEdit_NoCreationDate() throws RepositoryException {
65
66
67
68 List<SiteMapEntry> res = service.getSiteMapBeanForSite(rootPageWebsite, false);
69
70
71 assertEquals("res should have a size of zero", 0, res.size());
72 }
73
74 @Test
75 public void testSiteMapBeanForSiteNotForEdit() throws RepositoryException {
76
77 setMetaData(page_1_1, null);
78
79
80 List<SiteMapEntry> res = service.getSiteMapBeanForSite(rootPageWebsite, false);
81
82
83 assertEquals("res should have a size of one", 1, res.size());
84 assertEquals("",DEFAULT_URL+page_1_1.getPath(), res.get(0).getLoc());
85 assertEquals("","weekly", res.get(0).getChangefreq());
86 assertEquals("","0.5", res.get(0).getPriority());
87 }
88
89 @Test
90 public void testSiteMapBeanForSiteNotForEdit_With_Child() throws RepositoryException {
91
92 setMetaData(page_1_1, null);
93 setMetaData(page_1_1_1, null);
94
95
96 List<SiteMapEntry> res = service.getSiteMapBeanForSite(rootPageWebsite, false);
97
98
99 assertEquals("res should have a size of two", 2, res.size());
100 assertEquals("",DEFAULT_URL+page_1_1.getPath(), res.get(0).getLoc());
101 assertEquals("","weekly", res.get(0).getChangefreq());
102 assertEquals("","0.5", res.get(0).getPriority());
103 assertEquals("",2, res.get(0).getLevel());
104 assertEquals("",DEFAULT_URL+page_1_1_1.getPath(), res.get(1).getLoc());
105 assertEquals("","weekly", res.get(1).getChangefreq());
106 assertEquals("","0.5", res.get(1).getPriority());
107 assertEquals("",3, res.get(1).getLevel());
108
109 }
110
111 @Test
112 public void testSiteMapBeanForSiteNotForEdit_With_Child_Do_Not_Display_Child() throws RepositoryException {
113
114 setMetaData(page_1_1, null);
115 page_1_1.setProperty("googleSitemapHideChildren", Boolean.TRUE);
116 setMetaData(page_1_1_1, null);
117
118
119 List<SiteMapEntry> res = service.getSiteMapBeanForSite(rootPageWebsite, false);
120
121
122 assertEquals("res should have a size of one", 1, res.size());
123 assertEquals("",DEFAULT_URL+page_1_1.getPath(), res.get(0).getLoc());
124 assertEquals("","weekly", res.get(0).getChangefreq());
125 assertEquals("","0.5", res.get(0).getPriority());
126 }
127
128 @Test
129 public void testSiteMapBeanForSiteNotForEdit_With_Child_Do_Not_Display_Parent() throws RepositoryException {
130
131 setMetaData(page_1_1, null);
132 page_1_1.setProperty("googleSitemapHide", Boolean.TRUE);
133 setMetaData(page_1_1_1, null);
134
135
136 List<SiteMapEntry> res = service.getSiteMapBeanForSite(rootPageWebsite, false);
137
138
139 assertEquals("res should have a size of one", 1, res.size());
140 assertEquals("",DEFAULT_URL+page_1_1_1.getPath(), res.get(0).getLoc());
141 assertEquals("","weekly", res.get(0).getChangefreq());
142 assertEquals("","0.5", res.get(0).getPriority());
143 }
144
145
146 @Test
147 public void testSiteMapBeanForSiteForEdit_With_Child() throws RepositoryException {
148
149 setMetaData(page_1_1, null);
150 setMetaData(page_1_1_1, null);
151
152
153 List<SiteMapEntry> res = service.getSiteMapBeanForSite(rootPageWebsite, true);
154
155
156 assertEquals("res should have a size of two", 2, res.size());
157 assertEquals("",DEFAULT_URL+page_1_1.getPath(), res.get(0).getLoc());
158 assertEquals("",false, res.get(0).isStyleAlert());
159 assertEquals("",DEFAULT_URL+page_1_1_1.getPath(), res.get(1).getLoc());
160 assertEquals("",false, res.get(1).isStyleAlert());
161
162 }
163
164 @Test
165 public void testSiteMapBeanForSiteForEdit_With_Child_Do_Not_Display_Child() throws RepositoryException {
166
167 setMetaData(page_1_1, null);
168 page_1_1.setProperty("googleSitemapHideChildren", Boolean.TRUE);
169 setMetaData(page_1_1_1, null);
170
171
172 List<SiteMapEntry> res = service.getSiteMapBeanForSite(rootPageWebsite, true);
173
174
175 assertEquals("res should have a size of two", 2, res.size());
176 assertEquals("",DEFAULT_URL+page_1_1.getPath(), res.get(0).getLoc());
177 assertEquals("",false, res.get(0).isStyleAlert());
178 assertEquals("",DEFAULT_URL+page_1_1_1.getPath(), res.get(1).getLoc());
179 assertEquals("",true, res.get(1).isStyleAlert());
180 }
181
182 @Test
183 public void testSiteMapBeanForSiteForEdit_With_Child_Do_Not_Display_Parent() throws RepositoryException {
184
185 setMetaData(page_1_1, null);
186 page_1_1.setProperty("googleSitemapHide", Boolean.TRUE);
187 setMetaData(page_1_1_1, null);
188
189
190 List<SiteMapEntry> res = service.getSiteMapBeanForSite(rootPageWebsite, true);
191
192
193 assertEquals("res should have a size of two", 2, res.size());
194 assertEquals("",DEFAULT_URL+page_1_1.getPath(), res.get(0).getLoc());
195 assertEquals("",true, res.get(0).isStyleAlert());
196 assertEquals("",DEFAULT_URL+page_1_1_1.getPath(), res.get(1).getLoc());
197 assertEquals("",false, res.get(1).isStyleAlert());
198 }
199
200
201 @Test
202 public void testSiteMapBeanForVirtualUriNotForEdit_NoCreationDate() throws RepositoryException {
203
204
205
206 List<SiteMapEntry> res = service.getSiteMapBeanForVirtualUri(false);
207
208
209 assertEquals("res should have a size of zero", 0, res.size());
210 }
211
212 @Test
213 public void testSiteMapBeanForVirtualUriNotForEdit() throws RepositoryException {
214
215 setMetaData(virtualUri_2_1, null);
216 virtualUri_2_1.setProperty("fromURI", "/fromURI*");
217 virtualUri_2_1.setProperty("toURI", "toURI");
218
219
220 List<SiteMapEntry> res = service.getSiteMapBeanForVirtualUri(false);
221
222
223 assertEquals("res should have a size of one", 1, res.size());
224 assertEquals("",CONTEXT_PATH+"/fromURI*", res.get(0).getLoc());
225 assertEquals("","weekly", res.get(0).getChangefreq());
226 assertEquals("","0.5", res.get(0).getPriority());
227 assertEquals("",null, res.get(0).getTo());
228
229 }
230
231 @Test
232 public void testSiteMapBeanForVirtualUriNotForEdit_Dont_Display_VirtualUri_2_2() throws RepositoryException {
233
234 setMetaData(virtualUri_2_1, null);
235 virtualUri_2_1.setProperty("fromURI", "/fromURI*");
236 virtualUri_2_1.setProperty("toURI", "toURI");
237 setMetaData(virtualUri_2_2, null);
238 virtualUri_2_2.setProperty("fromURI", "/fromURI22*");
239 virtualUri_2_2.setProperty("toURI", "toURI22");
240 virtualUri_2_2.setProperty("googleSitemapHide", Boolean.TRUE);
241
242
243 List<SiteMapEntry> res = service.getSiteMapBeanForVirtualUri(false);
244
245
246 assertEquals("res should have a size of one", 1, res.size());
247 assertEquals("",CONTEXT_PATH+"/fromURI*", res.get(0).getLoc());
248 assertEquals("","weekly", res.get(0).getChangefreq());
249 assertEquals("","0.5", res.get(0).getPriority());
250 assertEquals("",null, res.get(0).getTo());
251
252 }
253
254
255 @Test
256 public void testSiteMapBeanForVirtualUriForEdit() throws RepositoryException {
257
258 setMetaData(virtualUri_2_1, null);
259 virtualUri_2_1.setProperty("fromURI", "/fromURI*");
260 virtualUri_2_1.setProperty("toURI", "/toURI");
261
262
263 List<SiteMapEntry> res = service.getSiteMapBeanForVirtualUri(true);
264
265
266 assertEquals("res should have a size of one", 1, res.size());
267 assertEquals("",CONTEXT_PATH+"/fromURI*", res.get(0).getLoc());
268 assertEquals("","weekly", res.get(0).getChangefreq());
269 assertEquals("","0.5", res.get(0).getPriority());
270 assertEquals("",3, res.get(0).getLevel());
271 assertEquals("","/fromURI*", res.get(0).getFrom());
272 assertEquals("","/toURI", res.get(0).getTo());
273 assertEquals("","/rootPage/virtualURIMapping/virtualUri_2_1", res.get(0).getPath());
274 assertEquals("",false, res.get(0).isStyleAlert());
275 }
276
277 @Test
278 public void testSiteMapBeanForVirtualUriForEdit_Dont_Display_VirtualUri_2_2() throws RepositoryException {
279
280 setMetaData(virtualUri_2_1, null);
281 virtualUri_2_1.setProperty("fromURI", "/fromURI*");
282 virtualUri_2_1.setProperty("toURI", "toURI");
283 setMetaData(virtualUri_2_2, null);
284 virtualUri_2_2.setProperty("fromURI", "/fromURI22*");
285 virtualUri_2_2.setProperty("toURI", "toURI22");
286 virtualUri_2_2.setProperty("googleSitemapHide", Boolean.TRUE);
287
288
289
290 List<SiteMapEntry> res = service.getSiteMapBeanForVirtualUri(true);
291
292
293 assertEquals("res should have a size of one", 2, res.size());
294 assertEquals("",CONTEXT_PATH+"/fromURI*", res.get(0).getLoc());
295 assertEquals("",false, res.get(0).isStyleAlert());
296 assertEquals("",CONTEXT_PATH+"/fromURI22*", res.get(1).getLoc());
297 assertEquals("",true, res.get(1).isStyleAlert());
298
299 }
300 }