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