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 ServiceTestUtil.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
26
2
1
119
63
2
0.08
13
2
1

Classes

Class Line # Actions
ServiceTestUtil 69 26 0% 2 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

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.assertTrue;
37    import static org.mockito.Matchers.any;
38    import static org.mockito.Mockito.*;
39   
40    import info.magnolia.cms.beans.config.ServerConfiguration;
41    import info.magnolia.cms.i18n.DefaultI18nContentSupport;
42    import info.magnolia.cms.i18n.I18nContentSupport;
43    import info.magnolia.context.MgnlContext;
44    import info.magnolia.importexport.DataTransporter;
45    import info.magnolia.jcr.util.NodeTypes;
46    import info.magnolia.jcr.util.NodeUtil;
47    import info.magnolia.module.googlesitemap.GoogleSiteMapConfiguration;
48    import info.magnolia.module.googlesitemap.SiteMapTestUtil;
49    import info.magnolia.module.googlesitemap.service.query.QueryUtil;
50    import info.magnolia.module.site.ConfiguredSite;
51    import info.magnolia.module.site.SiteManager;
52    import info.magnolia.repository.RepositoryConstants;
53    import info.magnolia.test.ComponentsTestUtil;
54   
55    import java.io.File;
56    import java.io.FileInputStream;
57    import java.io.InputStream;
58   
59    import javax.jcr.ImportUUIDBehavior;
60    import javax.jcr.Node;
61    import javax.jcr.RepositoryException;
62    import javax.jcr.Session;
63   
64    import org.apache.commons.io.IOUtils;
65   
66    /**
67    * Util test class used for initialization of a service.
68    */
 
69    public class ServiceTestUtil extends SiteMapTestUtil {
70   
71    protected Session websiteSession;
72    protected Session configSession;
73    protected SiteMapService service;
74    protected Node websiteNode;
75   
 
76  13 toggle @Override
77    public void setUp() throws Exception {
78  13 super.setUp();
79  13 websiteSession = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE);
80    // Register SiteMap
81  13 File file = new File(getClass().getResource("/googleSitemaps.xml").getFile());
82  13 InputStream inputStream = new FileInputStream(file);
83  13 DataTransporter.importXmlStream(inputStream, GoogleSiteMapConfiguration.WORKSPACE, "/", "test-stream", false, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, true, false);
84   
85    // Register Pages
86  13 file = new File(getClass().getResource("/website.demo-site.xml").getFile());
87  13 inputStream = new FileInputStream(file);
88  13 DataTransporter.importXmlStream(inputStream, RepositoryConstants.WEBSITE, "/", "test-stream", false, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, true, false);
89  13 websiteNode = websiteSession.getNode("/demo-site");
90   
91    // Register Config
92    // Initialize config tree
93  13 configSession = MgnlContext.getJCRSession(RepositoryConstants.CONFIG);
94  13 NodeUtil.createPath(configSession.getRootNode(), "/modules/adminInterface", NodeTypes.ContentNode.NAME);
95  13 file = new File(getClass().getResource("/config.modules.adminInterface.virtualURIMapping.xml").getFile());
96  13 inputStream = new FileInputStream(file);
97  13 DataTransporter.importXmlStream(inputStream, RepositoryConstants.CONFIG, "/modules/adminInterface", "test-stream", false, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, true, false);
98   
99  13 IOUtils.closeQuietly(inputStream);
100    // Initial check
101  13 assertTrue(googleSiteMapSession.nodeExists("/test1"));
102  13 assertTrue(googleSiteMapSession.nodeExists("/test2"));
103  13 assertTrue(websiteSession.nodeExists("/demo-site"));
104   
105    // Init service
106  13 initService();
107    }
108   
 
109  13 toggle protected void initService() throws RepositoryException {
110    // Init Site
111  13 ConfiguredSite site = new ConfiguredSite();
112  13 site.setEnabled(true);
113  13 SiteManager siteManager = mock(SiteManager.class);
114  13 when(siteManager.getAssignedSite((Node) any())).thenReturn(site);
115  13 ComponentsTestUtil.setInstance(I18nContentSupport.class, new DefaultI18nContentSupport());
116  13 ServerConfiguration.getInstance().setDefaultBaseUrl("defaultBaseUrl");
117  13 service = new SiteMapService(siteManager, new GoogleSiteMapConfiguration(), new QueryUtil());
118    }
119    }