Clover icon

Google Sitemap Module 2.4.3

  1. Project Clover database Thu May 11 2017 16:52:32 CEST
  2. Package info.magnolia.module.googlesitemap.service

File SiteMapServiceTest.java

 

Code metrics

0
98
6
1
218
128
6
0.06
16.33
6
1

Classes

Class Line # Actions
SiteMapServiceTest 53 98 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 6 tests. .

Source view

1    /**
2    * This file Copyright (c) 2014-2017 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.*;
37   
38    import info.magnolia.module.googlesitemap.SiteMapNodeTypes;
39    import info.magnolia.module.googlesitemap.bean.SiteMapEntry;
40   
41    import java.util.Collections;
42    import java.util.List;
43   
44    import javax.jcr.Node;
45    import javax.jcr.RepositoryException;
46   
47    import org.apache.commons.collections4.IteratorUtils;
48    import org.junit.Test;
49   
50    /**
51    * Main test class for {@link SiteMapService}.
52    */
 
53    public class SiteMapServiceTest extends ServiceTestUtil {
54   
 
55  1 toggle @Test
56    public void testGetSiteMapBeansForPagesNotForEdit() throws RepositoryException {
57    // GIVEN
58  1 Node siteMapNode = googleSiteMapSession.getNode("/test1");
59    // WHEN
60  1 List<SiteMapEntry> res = service.getSiteMapBeans(siteMapNode, false, false);
61   
62    // THEN
63  1 assertNotNull(res);
64    // check amount of res
65  1 assertEquals(2, res.size());
66   
67  1 SiteMapEntry entry0 = res.get(0);
68  1 assertEquals("always", entry0.getChangefreq());
69  1 assertEquals("2014-01-08", entry0.getLastmod());
70  1 assertEquals("defaultBaseUrl/demo-site/article/article1", entry0.getLoc());
71  1 assertEquals("/demo-site/article/article1", entry0.getPath());
72  1 assertEquals(0.3d, entry0.getPriority(), 0);
73  1 assertEquals(1, entry0.getLevel());
74   
75  1 SiteMapEntry entry1 = res.get(1);
76  1 assertEquals("defaultBaseUrl/demo-site/article/articleSection", entry1.getLoc());
77  1 assertEquals("/demo-site/article/articleSection", entry1.getPath());
78   
79    }
80   
 
81  1 toggle @Test
82    public void testGetSiteMapBeansForPagesForEdit() throws RepositoryException {
83    // GIVEN
84  1 Node siteMapNode = googleSiteMapSession.getNode("/test1");
85    // WHEN
86  1 List<SiteMapEntry> res = service.getSiteMapBeans(siteMapNode, false, true);
87   
88    // THEN
89  1 assertNotNull(res);
90  1 assertEquals(4, res.size());
91   
92  1 SiteMapEntry entry0 = res.get(0);
93  1 assertEquals("always", entry0.getChangefreq());
94  1 assertEquals("2014-01-08", entry0.getLastmod());
95  1 assertEquals("defaultBaseUrl/demo-site/article/article1", entry0.getLoc());
96  1 assertEquals("/demo-site/article/article1", entry0.getPath());
97  1 assertEquals(0.3d, entry0.getPriority(), 0);
98  1 assertEquals(1, entry0.getLevel());
99  1 assertFalse(entry0.isStyleAlert());
100   
101  1 SiteMapEntry entry1 = res.get(1); // Second article is hidden
102  1 assertEquals("defaultBaseUrl/demo-site/article/article2", entry1.getLoc());
103  1 assertTrue(entry1.isStyleAlert());
104  1 assertEquals(0.8d, entry1.getPriority(), 0);
105  1 assertEquals(1, entry1.getLevel());
106   
107  1 SiteMapEntry entry2 = res.get(2);
108  1 assertEquals("/demo-site/article/articleSection", entry2.getPath());
109  1 assertFalse(entry2.isStyleAlert());
110  1 assertEquals(1, entry2.getLevel());
111   
112  1 SiteMapEntry entry3 = res.get(3); // Section is required to hide child
113  1 assertEquals("defaultBaseUrl/demo-site/article/articleSection/article3", entry3.getLoc());
114  1 assertTrue(entry3.isStyleAlert());
115  1 assertEquals(2, entry3.getLevel());
116    }
117   
 
118  1 toggle @Test
119    public void testGetSiteMapBeansForUirNotForEdit() throws RepositoryException {
120    // GIVEN
121  1 Node siteMapNode = googleSiteMapSession.getNode("/test1");
122    // WHEN
123  1 List<SiteMapEntry> res = service.getSiteMapBeans(siteMapNode, true, false);
124   
125    // THEN
126  1 assertNotNull(res);
127  1 assertEquals(2, res.size());
128   
129  1 SiteMapEntry entry0 = res.get(0);
130  1 assertEquals("always", entry0.getChangefreq());
131  1 assertEquals("2008-06-12", entry0.getLastmod());
132  1 assertEquals("null/\\.magnolia/pages/messages\\.(.*)\\.js", entry0.getLoc());
133  1 assertEquals("/modules/adminInterface/virtualURIMapping/messages", entry0.getPath());
134  1 assertEquals(0.8d, entry0.getPriority(), 0);
135  1 assertEquals(4, entry0.getLevel());
136  1 assertFalse(entry0.isStyleAlert());
137   
138  1 SiteMapEntry entry1 = res.get(1);
139  1 assertEquals("null/.magnolia/dialogs/fileThumbnail.jpg", entry1.getLoc());
140  1 assertEquals("/modules/adminInterface/virtualURIMapping/dialogsFileThumbnail", entry1.getPath());
141    }
142   
 
143  1 toggle @Test
144    public void testGetSiteMapBeansForUriNotForEdit() throws RepositoryException {
145    // GIVEN
146  1 Node siteMapNode = googleSiteMapSession.getNode("/test1");
147    // WHEN
148  1 List<SiteMapEntry> res = service.getSiteMapBeans(siteMapNode, true, false);
149   
150    // THEN
151  1 assertNotNull(res);
152  1 assertEquals(2, res.size());
153   
154  1 SiteMapEntry entry0 = res.get(0);
155  1 assertEquals("null/\\.magnolia/pages/messages\\.(.*)\\.js", entry0.getLoc());
156  1 assertEquals("/modules/adminInterface/virtualURIMapping/messages", entry0.getPath());
157  1 assertEquals(4, entry0.getLevel());
158  1 assertFalse(entry0.isStyleAlert());
159   
160  1 SiteMapEntry entry1 = res.get(1);
161  1 assertEquals("null/.magnolia/dialogs/fileThumbnail.jpg", entry1.getLoc());
162  1 assertEquals("/modules/adminInterface/virtualURIMapping/dialogsFileThumbnail", entry1.getPath());
163    }
164   
 
165  1 toggle @Test
166    public void testGetSiteMapBeansNotForEdit() throws RepositoryException {
167    // GIVEN
168  1 Node siteMapNode = googleSiteMapSession.getNode("/test1");
169    // WHEN
170  1 List<SiteMapEntry> res = IteratorUtils.toList(service.getSiteMapBeans(siteMapNode));
171  1 Collections.sort(res);
172   
173    // THEN
174  1 assertNotNull(res);
175  1 assertEquals(4, res.size());
176   
177  1 SiteMapEntry entry0 = res.get(0);
178  1 assertEquals("always", entry0.getChangefreq());
179  1 assertEquals("2008-06-12", entry0.getLastmod());
180  1 assertEquals("null/\\.magnolia/pages/messages\\.(.*)\\.js", entry0.getLoc());
181  1 assertEquals("/modules/adminInterface/virtualURIMapping/messages", entry0.getPath());
182  1 assertEquals(0.8d, entry0.getPriority(), 0);
183  1 assertEquals(4, entry0.getLevel());
184  1 assertFalse(entry0.isStyleAlert());
185   
186  1 SiteMapEntry entry1 = res.get(1);
187  1 assertEquals("null/.magnolia/dialogs/fileThumbnail.jpg", entry1.getLoc());
188  1 assertEquals("/modules/adminInterface/virtualURIMapping/dialogsFileThumbnail", entry1.getPath());
189   
190  1 SiteMapEntry entry2 = res.get(2);
191  1 assertEquals("defaultBaseUrl/demo-site/article/articleSection", entry2.getLoc());
192   
193  1 SiteMapEntry entry3 = res.get(3);
194  1 assertEquals("defaultBaseUrl/demo-site/article/article1", entry3.getLoc());
195    }
196   
 
197  1 toggle @Test
198    public void testUpdatePageNode() throws RepositoryException {
199    // GIVEN
200  1 SiteMapEntry entry = new SiteMapEntry();
201  1 entry.setPath("/demo-site/article/article1");
202  1 entry.setChangefreq("changefreq");
203  1 entry.setPriority(0.5d);
204  1 entry.setHide(true);
205  1 entry.setHideChildren(true);
206   
207    // WHEN
208  1 service.updatePageNode(entry);
209   
210    // THEN
211  1 Node node = websiteSession.getNode("/demo-site/article/article1");
212  1 assertTrue(SiteMapNodeTypes.GoogleSiteMap.isHide(node));
213  1 assertEquals("changefreq", SiteMapNodeTypes.GoogleSiteMap.getChangeFreq(node));
214  1 assertEquals(0.5d, SiteMapNodeTypes.GoogleSiteMap.getPriority(node), 0);
215  1 assertTrue(SiteMapNodeTypes.GoogleSiteMap.isHideChildren(node));
216    }
217   
218    }