| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.devacfr.maven.skins.reflow; |
| 17 |
|
|
| 18 |
|
import com.google.common.collect.ImmutableMap; |
| 19 |
|
import java.io.InputStream; |
| 20 |
|
import lombok.Builder; |
| 21 |
|
import lombok.Data; |
| 22 |
|
import org.apache.maven.doxia.site.SiteModel; |
| 23 |
|
import org.apache.maven.doxia.site.io.xpp3.SiteXpp3Reader; |
| 24 |
|
import org.apache.maven.project.MavenProject; |
| 25 |
|
import org.apache.velocity.tools.Scope; |
| 26 |
|
import org.apache.velocity.tools.ToolContext; |
| 27 |
|
import org.apache.velocity.tools.ToolManager; |
| 28 |
|
import org.apache.velocity.tools.config.EasyFactoryConfiguration; |
| 29 |
|
import org.apache.velocity.tools.generic.RenderTool; |
| 30 |
|
import org.apache.velocity.tools.generic.ValueParser; |
| 31 |
|
import org.devacfr.testing.jupiter.MockitoTestCase; |
| 32 |
|
import org.junit.jupiter.api.Test; |
| 33 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (97) |
Complexity: 15 |
Complexity Density: 0,18 |
|
| 34 |
|
public class SkinConfigToolTest extends MockitoTestCase { |
| 35 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
1PASS
|
|
| 36 |
1 |
@Test... |
| 37 |
|
public void testIs() throws Exception { |
| 38 |
1 |
ReflowContext context = createSkinConfig(); |
| 39 |
1 |
assertEquals(true, context.getSkinConfig().is("localResources")); |
| 40 |
1 |
assertEquals(false, context.getSkinConfig().is("markPageHeader")); |
| 41 |
|
} |
| 42 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
1PASS
|
|
| 43 |
1 |
@Test... |
| 44 |
|
public void testNot() throws Exception { |
| 45 |
1 |
ReflowContext context = createSkinConfig(); |
| 46 |
1 |
SkinConfigTool skinConfig = context.getSkinConfig(); |
| 47 |
1 |
assertEquals(true, skinConfig.not("markPageHeader")); |
| 48 |
1 |
assertEquals(false, skinConfig.not("localResources")); |
| 49 |
|
} |
| 50 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
1PASS
|
|
| 51 |
1 |
@Test... |
| 52 |
|
public void testIsValue() throws Exception { |
| 53 |
1 |
ReflowContext context = createSkinConfig(); |
| 54 |
1 |
SkinConfigTool skinConfig = context.getSkinConfig(); |
| 55 |
1 |
assertEquals(true, skinConfig.isValue("localResources", "true")); |
| 56 |
1 |
assertEquals(false, skinConfig.isValue("localResources", "value")); |
| 57 |
|
} |
| 58 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
1PASS
|
|
| 59 |
1 |
@Test... |
| 60 |
|
public void testIsActiveLink() throws Exception { |
| 61 |
1 |
ReflowContext context = createSkinConfig(); |
| 62 |
1 |
SkinConfigTool skinConfig = context.getSkinConfig(); |
| 63 |
1 |
ToolContext velocityContext = context.getVelocityContext(); |
| 64 |
1 |
velocityContext.put("alignedFileName", "index.html"); |
| 65 |
1 |
assertEquals(true, skinConfig.isActiveLink("."), "should be active"); |
| 66 |
1 |
assertEquals(true, skinConfig.isActiveLink(""), "should be active"); |
| 67 |
|
|
| 68 |
1 |
velocityContext.put("alignedFileName", "summary.html"); |
| 69 |
1 |
assertEquals(false, skinConfig.isActiveLink(null), "should be not active"); |
| 70 |
1 |
assertEquals(false, skinConfig.isActiveLink("."), "should be not active"); |
| 71 |
1 |
assertEquals(false, skinConfig.isActiveLink("index.html"), "should be not active"); |
| 72 |
|
} |
| 73 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
1PASS
|
|
| 74 |
1 |
@Test... |
| 75 |
|
public void testIsExternalLink() throws Exception { |
| 76 |
1 |
ReflowContext context = createSkinConfig(); |
| 77 |
1 |
SkinConfigTool skinConfig = context.getSkinConfig(); |
| 78 |
1 |
assertEquals(true, skinConfig.isExternalLink("http://foo.com"), "should be external"); |
| 79 |
1 |
assertEquals(true, skinConfig.isExternalLink("https://foo.com"), "should be external"); |
| 80 |
1 |
assertEquals(true, skinConfig.isExternalLink("ftp://foo.com"), "should be external"); |
| 81 |
1 |
assertEquals(true, skinConfig.isExternalLink("mailto:john@foo.com"), "should be external"); |
| 82 |
1 |
assertEquals(true, skinConfig.isExternalLink("file://foo.com"), "should be external"); |
| 83 |
|
|
| 84 |
1 |
assertEquals(false, skinConfig.isExternalLink(null), "should be internal"); |
| 85 |
1 |
assertEquals(false, skinConfig.isExternalLink("summary.html"), "should be internal"); |
| 86 |
1 |
assertEquals(false, |
| 87 |
|
skinConfig.isExternalLink("https://devacfr.github.io/reflow-maven-skin/dev/summary.html"), |
| 88 |
|
"should be internal"); |
| 89 |
|
} |
| 90 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
1PASS
|
|
| 91 |
1 |
@Test... |
| 92 |
|
public void testSlugFilename() throws Exception { |
| 93 |
1 |
assertEquals("dev-release-management", SkinConfigTool.slugFilename("dev/release-management.html")); |
| 94 |
1 |
assertEquals("dev-develop_guide", SkinConfigTool.slugFilename("dev/develop_guide.html")); |
| 95 |
1 |
assertEquals("dev-develop_guide", SkinConfigTool.slugFilename("dev/develop_guide")); |
| 96 |
|
} |
| 97 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
1PASS
|
|
| 98 |
1 |
@Test... |
| 99 |
|
public void shouldReturnProjectLocationNotNull() throws Exception { |
| 100 |
1 |
ReflowContext context = createSkinConfig(); |
| 101 |
1 |
SkinConfigTool skinConfig = context.getSkinConfig(); |
| 102 |
1 |
context.getMaven().setUrl(null); |
| 103 |
1 |
assertEquals("https://localhost/", skinConfig.getProjectLocation()); |
| 104 |
|
} |
| 105 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
1PASS
|
|
| 106 |
1 |
@Test... |
| 107 |
|
public void shouldRenderSnippet() throws Exception { |
| 108 |
1 |
ReflowContext context = createSkinConfig(); |
| 109 |
|
|
| 110 |
1 |
assertEquals("<span class=\"badge badge-success\">INFO</span>", |
| 111 |
|
context.skinConfig.renderSnippet("<badge color=\"success\" text=\"INFO\" />")); |
| 112 |
|
} |
| 113 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
1PASS
|
|
| 114 |
1 |
@Test... |
| 115 |
|
public void shouldGetTitle() throws Exception { |
| 116 |
1 |
ReflowContext context = createSkinConfig(); |
| 117 |
1 |
context.getVelocityContext().put("title", "Maven Reflow Plugin"); |
| 118 |
1 |
context.getVelocityContext().put("shortTitle", "Maven Reflow Plugin"); |
| 119 |
1 |
SkinConfigTool skinConfig = context.getSkinConfig(); |
| 120 |
1 |
assertEquals("Maven Reflow Plugin | Maven Reflow Plugin", skinConfig.getTitle()); |
| 121 |
|
} |
| 122 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
1PASS
|
|
| 123 |
1 |
@Test... |
| 124 |
|
public void shouldGetTitleWithoutTitleTemplate() throws Exception { |
| 125 |
1 |
ReflowContext context = createSkinConfig(); |
| 126 |
1 |
context.getVelocityContext().put("title", "Maven Reflow Plugin"); |
| 127 |
1 |
context.getVelocityContext().put("shortTitle", "Maven Reflow Plugin"); |
| 128 |
1 |
SkinConfigTool skinConfig = context.getSkinConfig(); |
| 129 |
1 |
skinConfig.getGlobalProperties().removeChild(skinConfig.get("titleTemplate")); |
| 130 |
1 |
assertEquals("Maven Reflow Plugin - Maven Reflow Plugin", skinConfig.getTitle()); |
| 131 |
|
} |
| 132 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
1PASS
|
|
| 133 |
1 |
@Test... |
| 134 |
|
public void shouldGetTitleUsingModelName() throws Exception { |
| 135 |
1 |
ReflowContext context = createSkinConfig(); |
| 136 |
1 |
context.getVelocityContext().put("shortTitle", "Maven Reflow Plugin"); |
| 137 |
1 |
SkinConfigTool skinConfig = context.getSkinConfig(); |
| 138 |
1 |
assertEquals("Maven Reflow Plugin | Reflow Maven Skin", skinConfig.getTitle()); |
| 139 |
|
} |
| 140 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
1PASS
|
|
| 141 |
1 |
@Test... |
| 142 |
|
public void shouldGetTitleUsingProjectName() throws Exception { |
| 143 |
1 |
ReflowContext context = createSkinConfig(); |
| 144 |
1 |
context.getVelocityContext().put("shortTitle", "Maven Reflow Plugin"); |
| 145 |
1 |
SkinConfigTool skinConfig = context.getSkinConfig(); |
| 146 |
1 |
context.getSiteModel().setName(null); |
| 147 |
1 |
assertEquals("Maven Reflow Plugin | Reflow Maven Skin Project", skinConfig.getTitle()); |
| 148 |
|
} |
| 149 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 3 |
Complexity Density: 0,12 |
|
| 150 |
11 |
private ReflowContext createSkinConfig() throws Exception {... |
| 151 |
11 |
SkinConfigTool skinConfig; |
| 152 |
11 |
final EasyFactoryConfiguration config = new EasyFactoryConfiguration(false); |
| 153 |
11 |
config.toolbox(Scope.APPLICATION).tool(HtmlTool.class); |
| 154 |
|
|
| 155 |
11 |
final ToolManager manager = new ToolManager(false, false); |
| 156 |
11 |
manager.configure(config); |
| 157 |
11 |
ToolContext velocityContext = manager.createContext(); |
| 158 |
11 |
final SiteXpp3Reader reader = new SiteXpp3Reader(); |
| 159 |
11 |
SiteModel siteModel = null; |
| 160 |
11 |
try (final InputStream in = getResource("default.site.xml").openBufferedStream()) { |
| 161 |
11 |
siteModel = reader.read(in); |
| 162 |
|
} |
| 163 |
11 |
ValueParser valueParser = new ValueParser( |
| 164 |
|
ImmutableMap.<String, Object> builder().put("velocityContext", velocityContext).build()); |
| 165 |
|
|
| 166 |
11 |
final MavenProject maven = new MavenProject(); |
| 167 |
11 |
maven.setArtifactId("maven-reflow-plugin"); |
| 168 |
11 |
maven.setName("Reflow Maven Skin Project"); |
| 169 |
11 |
maven.setUrl("https://devacfr.github.io/reflow-maven-skin/"); |
| 170 |
|
|
| 171 |
11 |
velocityContext.put("project", maven); |
| 172 |
11 |
velocityContext.put("site", siteModel); |
| 173 |
11 |
velocityContext.put("render", new RenderTool()); |
| 174 |
11 |
velocityContext.put("currentFileName", "summary.html"); |
| 175 |
11 |
velocityContext.put("alignedFileName", "summary.html"); |
| 176 |
11 |
skinConfig = new SkinConfigTool(); |
| 177 |
11 |
skinConfig.configure(valueParser); |
| 178 |
11 |
return ReflowContext.builder() |
| 179 |
|
.maven(maven) |
| 180 |
|
.velocityContext(velocityContext) |
| 181 |
|
.skinConfig(skinConfig) |
| 182 |
|
.siteModel(siteModel) |
| 183 |
|
.build(); |
| 184 |
|
} |
| 185 |
|
|
| 186 |
|
@Data |
| 187 |
|
@Builder |
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 188 |
|
private static class ReflowContext { |
| 189 |
|
|
| 190 |
|
private ToolContext velocityContext; |
| 191 |
|
|
| 192 |
|
private SkinConfigTool skinConfig; |
| 193 |
|
|
| 194 |
|
private MavenProject maven; |
| 195 |
|
|
| 196 |
|
private SiteModel siteModel; |
| 197 |
|
|
| 198 |
|
} |
| 199 |
|
} |