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      @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          // GIVEN
65  
66          // WHEN
67          List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, false);
68  
69          // THEN
70          assertEquals("res should have a size of zero", 0, res.size());
71      }
72  
73      @Test
74      public void testSiteMapBeanForSiteNotForEdit() throws RepositoryException {
75          // GIVEN
76          setMetaData(page_1_1, null);
77  
78          // WHEN
79          List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, false);
80  
81          // THEN
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          // GIVEN
91          setMetaData(page_1_1, null);
92          setMetaData(page_1_1_1, null);
93  
94          // WHEN
95          List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, false);
96  
97          // THEN
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         // GIVEN
113         setMetaData(page_1_1, null);
114         page_1_1.setProperty("googleSitemapHideChildren", Boolean.TRUE);
115         setMetaData(page_1_1_1, null);
116 
117         // WHEN
118         List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, false);
119 
120         // THEN
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         // GIVEN
130         setMetaData(page_1_1, null);
131         page_1_1.setProperty("googleSitemapHide", Boolean.TRUE);
132         setMetaData(page_1_1_1, null);
133 
134         // WHEN
135         List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, false);
136 
137         // THEN
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         // GIVEN
148         setMetaData(page_1_1, null);
149         setMetaData(page_1_1_1, null);
150 
151         // WHEN
152         List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, true);
153 
154         // THEN
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         // GIVEN
166         setMetaData(page_1_1, null);
167         page_1_1.setProperty("googleSitemapHideChildren", Boolean.TRUE);
168         setMetaData(page_1_1_1, null);
169 
170         // WHEN
171         List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, true);
172 
173         // THEN
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         // GIVEN
184         setMetaData(page_1_1, null);
185         page_1_1.setProperty("googleSitemapHide", Boolean.TRUE);
186         setMetaData(page_1_1_1, null);
187 
188         // WHEN
189         List<SiteMapEntry> res =  service.getSiteMapBeanForSite(rootPageWebsite, true);
190 
191         // THEN
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         // GIVEN
203 
204         // WHEN
205         List<SiteMapEntry> res =  service.getSiteMapBeanForVirtualUri(false);
206 
207         // THEN
208         assertEquals("res should have a size of zero", 0, res.size());
209     }
210 
211     @Test
212     public void testSiteMapBeanForVirtualUriNotForEdit() throws RepositoryException {
213         // GIVEN
214         setMetaData(virtualUri_2_1, null);
215         virtualUri_2_1.setProperty("fromURI", "/fromURI*");
216         virtualUri_2_1.setProperty("toURI", "toURI");
217 
218         // WHEN
219         List<SiteMapEntry> res =  service.getSiteMapBeanForVirtualUri(false);
220 
221         // THEN
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         // GIVEN
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         // WHEN
242         List<SiteMapEntry> res =  service.getSiteMapBeanForVirtualUri(false);
243 
244         // THEN
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         // GIVEN
257         setMetaData(virtualUri_2_1, null);
258         virtualUri_2_1.setProperty("fromURI", "/fromURI*");
259         virtualUri_2_1.setProperty("toURI", "/toURI");
260 
261         // WHEN
262         List<SiteMapEntry> res =  service.getSiteMapBeanForVirtualUri(true);
263 
264         // THEN
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         // GIVEN
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         // WHEN
289         List<SiteMapEntry> res =  service.getSiteMapBeanForVirtualUri(true);
290 
291         // THEN
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 }