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.model; |
35 |
|
|
36 |
|
import static org.junit.Assert.*; |
37 |
|
|
38 |
|
import info.magnolia.module.googlesitemap.bean.SiteMapEntry; |
39 |
|
import info.magnolia.module.googlesitemap.service.ServiceTestUtil; |
40 |
|
import info.magnolia.module.googlesitemap.service.SiteMapService; |
41 |
|
import info.magnolia.module.googlesitemap.service.SiteMapXMLUtilImpl; |
42 |
|
import info.magnolia.rendering.model.RenderingModel; |
43 |
|
import info.magnolia.rendering.template.RenderableDefinition; |
44 |
|
|
45 |
|
import java.util.Collections; |
46 |
|
import java.util.List; |
47 |
|
|
48 |
|
import javax.inject.Provider; |
49 |
|
import javax.jcr.Node; |
50 |
|
import javax.jcr.RepositoryException; |
51 |
|
|
52 |
|
import org.apache.commons.collections.IteratorUtils; |
53 |
|
import org.apache.commons.lang.StringUtils; |
54 |
|
import org.junit.Test; |
55 |
|
|
56 |
|
|
57 |
|
@link |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.5 |
|
59 |
|
public class SiteMapModelTest extends ServiceTestUtil { |
60 |
|
|
61 |
|
private SiteMapModel<RenderableDefinition> model; |
62 |
|
private SiteMapXMLUtilImpl xmlUtil; |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
64 |
2 |
@Override... |
65 |
|
public void setUp() throws Exception { |
66 |
2 |
super.setUp(); |
67 |
2 |
xmlUtil = new SiteMapXMLUtilImpl(new Provider<SiteMapService>() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
1 |
@Override... |
69 |
|
public SiteMapService get() { |
70 |
1 |
return service; |
71 |
|
} |
72 |
|
}); |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
75 |
2 |
private void initModel(Node contentNode) {... |
76 |
2 |
RenderingModel<RenderableDefinition> parent = null; |
77 |
2 |
RenderableDefinition definition = null; |
78 |
2 |
model = new SiteMapModel<RenderableDefinition>(contentNode, definition, parent, service, xmlUtil); |
79 |
|
} |
80 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
81 |
|
@Test... |
82 |
|
public void getSiteMapBeans() throws RepositoryException { |
83 |
|
|
84 |
|
Node siteMapNode = googleSiteMapSession.getNode("/test1"); |
85 |
|
initModel(siteMapNode); |
86 |
|
|
87 |
|
|
88 |
|
List<SiteMapEntry> res = IteratorUtils.toList(model.getSiteMapBeans()); |
89 |
|
Collections.sort(res); |
90 |
|
|
91 |
|
|
92 |
|
assertNotNull(res); |
93 |
|
assertEquals(4, res.size()); |
94 |
|
SiteMapEntry entry0 = res.get(0); |
95 |
|
assertEquals("/modules/adminInterface/virtualURIMapping/messages", entry0.getPath()); |
96 |
|
|
97 |
|
SiteMapEntry entry1 = res.get(1); |
98 |
|
assertEquals("/modules/adminInterface/virtualURIMapping/dialogsFileThumbnail", entry1.getPath()); |
99 |
|
|
100 |
|
SiteMapEntry entry2 = res.get(2); |
101 |
|
assertEquals("defaultBaseUrl/demo-site/article/articleSection", entry2.getLoc()); |
102 |
|
|
103 |
|
SiteMapEntry entry3 = res.get(3); |
104 |
|
assertEquals("defaultBaseUrl/demo-site/article/article1", entry3.getLoc()); |
105 |
|
} |
106 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
107 |
|
@Test... |
108 |
|
public void getXmlBeans() throws RepositoryException { |
109 |
|
|
110 |
|
Node siteMapNode = googleSiteMapSession.getNode("/test3"); |
111 |
|
initModel(siteMapNode); |
112 |
|
|
113 |
|
|
114 |
|
String res = model.getXML(); |
115 |
|
|
116 |
|
|
117 |
|
assertNotNull(res); |
118 |
|
assertTrue("Contains a url def for Pages", StringUtils.contains(res, "<url><mobile:mobile/><changefreq>hourly</changefreq><lastmod>2014-01-08</lastmod><loc>defaultBaseUrl/demo-site/news/subNewsSection2/news2</loc><priority>0.7</priority></url>")); |
119 |
|
|
120 |
|
} |
121 |
|
} |