1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package org.devacfr.maven.skins.reflow; |
20 |
|
|
21 |
|
import java.io.InputStream; |
22 |
|
|
23 |
|
import com.google.common.collect.ImmutableMap; |
24 |
|
import org.apache.maven.doxia.site.SiteModel; |
25 |
|
import org.apache.maven.doxia.site.io.xpp3.SiteXpp3Reader; |
26 |
|
import org.apache.maven.project.MavenProject; |
27 |
|
import org.apache.velocity.tools.ToolContext; |
28 |
|
import org.apache.velocity.tools.generic.RenderTool; |
29 |
|
import org.apache.velocity.tools.generic.ValueParser; |
30 |
|
import org.devacfr.testing.jupiter.MockitoTestCase; |
31 |
|
import org.junit.jupiter.api.BeforeEach; |
32 |
|
import org.junit.jupiter.api.Test; |
33 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (47) |
Complexity: 9 |
Complexity Density: 0,22 |
|
34 |
|
public class SkinConfigToolTest extends MockitoTestCase { |
35 |
|
|
36 |
|
private ToolContext velocityContext; |
37 |
|
|
38 |
|
private ValueParser valueParser; |
39 |
|
|
40 |
|
private SkinConfigTool skinConfig; |
41 |
|
|
42 |
|
private SiteModel siteModel; |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 3 |
Complexity Density: 0,19 |
|
44 |
6 |
@BeforeEach... |
45 |
|
public void setup() throws Exception { |
46 |
6 |
velocityContext = new ToolContext(); |
47 |
6 |
final SiteXpp3Reader reader = new SiteXpp3Reader(); |
48 |
|
|
49 |
6 |
try (final InputStream in = getResource("default.site.xml").openBufferedStream()) { |
50 |
6 |
siteModel = reader.read(in); |
51 |
|
} |
52 |
6 |
valueParser = new ValueParser( |
53 |
|
ImmutableMap.<String, Object> builder().put("velocityContext", velocityContext).build()); |
54 |
|
|
55 |
6 |
final MavenProject maven = new MavenProject(); |
56 |
6 |
maven.setArtifactId("maven-reflow-plugin"); |
57 |
6 |
maven.setUrl("https://devacfr.github.io/reflow-maven-skin/"); |
58 |
|
|
59 |
6 |
velocityContext.put("project", maven); |
60 |
6 |
velocityContext.put("site", siteModel); |
61 |
6 |
velocityContext.put("render", new RenderTool()); |
62 |
6 |
velocityContext.put("currentFileName", "summary.html"); |
63 |
6 |
velocityContext.put("alignedFileName", "summary.html"); |
64 |
6 |
skinConfig = new SkinConfigTool(); |
65 |
6 |
skinConfig.configure(valueParser); |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
1PASS
|
|
68 |
1 |
@Test... |
69 |
|
public void testIs() { |
70 |
1 |
assertEquals(true, skinConfig.is("localResources")); |
71 |
1 |
assertEquals(false, skinConfig.is("markPageHeader")); |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
1PASS
|
|
74 |
1 |
@Test... |
75 |
|
public void testNot() { |
76 |
1 |
assertEquals(true, skinConfig.not("markPageHeader")); |
77 |
1 |
assertEquals(false, skinConfig.not("localResources")); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
1PASS
|
|
80 |
1 |
@Test... |
81 |
|
public void testIsValue() { |
82 |
1 |
assertEquals(true, skinConfig.isValue("localResources", "true")); |
83 |
1 |
assertEquals(false, skinConfig.isValue("localResources", "value")); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
1PASS
|
|
86 |
1 |
@Test... |
87 |
|
public void testIsActiveLink() { |
88 |
|
|
89 |
1 |
velocityContext.put("alignedFileName", "index.html"); |
90 |
1 |
assertEquals(true, skinConfig.isActiveLink("."), "should be active"); |
91 |
1 |
assertEquals(true, skinConfig.isActiveLink(""), "should be active"); |
92 |
|
|
93 |
1 |
velocityContext.put("alignedFileName", "summary.html"); |
94 |
1 |
assertEquals(false, skinConfig.isActiveLink(null), "should be note active"); |
95 |
1 |
assertEquals(false, skinConfig.isActiveLink("."), "should be note active"); |
96 |
1 |
assertEquals(false, skinConfig.isActiveLink("index.html"), "should be note active"); |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
1PASS
|
|
99 |
1 |
@Test... |
100 |
|
public void testIsExternalLink() { |
101 |
|
|
102 |
1 |
assertEquals(true, skinConfig.isExternalLink("http://foo.com"), "should be external"); |
103 |
1 |
assertEquals(true, skinConfig.isExternalLink("https://foo.com"), "should be external"); |
104 |
1 |
assertEquals(true, skinConfig.isExternalLink("ftp://foo.com"), "should be external"); |
105 |
1 |
assertEquals(true, skinConfig.isExternalLink("mailto:john@foo.com"), "should be external"); |
106 |
1 |
assertEquals(true, skinConfig.isExternalLink("file://foo.com"), "should be external"); |
107 |
|
|
108 |
1 |
assertEquals(false, skinConfig.isExternalLink(null), "should be internal"); |
109 |
1 |
assertEquals(false, skinConfig.isExternalLink("summary.html"), "should be internal"); |
110 |
1 |
assertEquals(false, |
111 |
|
skinConfig.isExternalLink("https://devacfr.github.io/reflow-maven-skin/dev/summary.html"), |
112 |
|
"should be internal"); |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
1PASS
|
|
115 |
1 |
@Test... |
116 |
|
public void testSlugFilename() { |
117 |
1 |
assertEquals("dev-release-management", SkinConfigTool.slugFilename("dev/release-management.html")); |
118 |
1 |
assertEquals("dev-develop_guide", SkinConfigTool.slugFilename("dev/develop_guide.html")); |
119 |
1 |
assertEquals("dev-develop_guide", SkinConfigTool.slugFilename("dev/develop_guide")); |
120 |
|
} |
121 |
|
} |