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.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 |
|
|
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 2 |
Complexity Density: 0.08 |
|
69 |
|
public class ServiceTestUtil extends SiteMapTestUtil { |
70 |
|
|
71 |
|
protected Session websiteSession; |
72 |
|
protected Session configSession; |
73 |
|
protected SiteMapService service; |
74 |
|
protected Node websiteNode; |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
|
76 |
13 |
@Override... |
77 |
|
public void setUp() throws Exception { |
78 |
13 |
super.setUp(); |
79 |
13 |
websiteSession = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE); |
80 |
|
|
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 |
|
|
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 |
|
|
92 |
|
|
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 |
|
|
101 |
13 |
assertTrue(googleSiteMapSession.nodeExists("/test1")); |
102 |
13 |
assertTrue(googleSiteMapSession.nodeExists("/test2")); |
103 |
13 |
assertTrue(websiteSession.nodeExists("/demo-site")); |
104 |
|
|
105 |
|
|
106 |
13 |
initService(); |
107 |
|
} |
108 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
109 |
13 |
protected void initService() throws RepositoryException {... |
110 |
|
|
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 |
|
} |