View Javadoc

1   /**
2    * This file Copyright (c) 2012 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
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   * Main Service Test class.
50   * @version $Id$
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          // GIVEN
66  
67          // WHEN
68          List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, false);
69  
70          // THEN
71          assertEquals("res should have a size of zero", 0, res.size());
72      }
73  
74      @Test
75      public void testSiteMapBeanForSiteNotForEdit() throws RepositoryException {
76          // GIVEN
77          setMetaData(page_1_1, null);
78  
79          // WHEN
80          List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, false);
81  
82          // THEN
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          // GIVEN
92          setMetaData(page_1_1, null);
93          setMetaData(page_1_1_1, null);
94  
95          // WHEN
96          List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, false);
97  
98          // THEN
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         // GIVEN
114         setMetaData(page_1_1, null);
115         page_1_1.setProperty("googleSitemapHideChildren", Boolean.TRUE);
116         setMetaData(page_1_1_1, null);
117 
118         // WHEN
119         List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, false);
120 
121         // THEN
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         // GIVEN
131         setMetaData(page_1_1, null);
132         page_1_1.setProperty("googleSitemapHide", Boolean.TRUE);
133         setMetaData(page_1_1_1, null);
134 
135         // WHEN
136         List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, false);
137 
138         // THEN
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         // GIVEN
149         setMetaData(page_1_1, null);
150         setMetaData(page_1_1_1, null);
151 
152         // WHEN
153         List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, true);
154 
155         // THEN
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         // GIVEN
167         setMetaData(page_1_1, null);
168         page_1_1.setProperty("googleSitemapHideChildren", Boolean.TRUE);
169         setMetaData(page_1_1_1, null);
170 
171         // WHEN
172         List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, true);
173 
174         // THEN
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         // GIVEN
185         setMetaData(page_1_1, null);
186         page_1_1.setProperty("googleSitemapHide", Boolean.TRUE);
187         setMetaData(page_1_1_1, null);
188 
189         // WHEN
190         List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, true);
191 
192         // THEN
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         // GIVEN
204 
205         // WHEN
206         List<SiteMapEntry> res =  service.getSiteMapBeanForVirtualUri(false);
207 
208         // THEN
209         assertEquals("res should have a size of zero", 0, res.size());
210     }
211 
212     @Test
213     public void testSiteMapBeanForVirtualUriNotForEdit() throws RepositoryException {
214         // GIVEN
215         setMetaData(virtualUri_2_1, null);
216         virtualUri_2_1.setProperty("fromURI", "/fromURI*");
217         virtualUri_2_1.setProperty("toURI", "toURI");
218 
219         // WHEN
220         List<SiteMapEntry> res =  service.getSiteMapBeanForVirtualUri(false);
221 
222         // THEN
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         // GIVEN
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         // WHEN
243         List<SiteMapEntry> res =  service.getSiteMapBeanForVirtualUri(false);
244 
245         // THEN
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         // GIVEN
258         setMetaData(virtualUri_2_1, null);
259         virtualUri_2_1.setProperty("fromURI", "/fromURI*");
260         virtualUri_2_1.setProperty("toURI", "/toURI");
261 
262         // WHEN
263         List<SiteMapEntry> res =  service.getSiteMapBeanForVirtualUri(true);
264 
265         // THEN
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         // GIVEN
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         // WHEN
290         List<SiteMapEntry> res =  service.getSiteMapBeanForVirtualUri(true);
291 
292         // THEN
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 }