1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package org.apache.maven.doxia.siterenderer; |
20 |
|
|
21 |
|
import static org.apache.commons.io.IOUtils.closeQuietly; |
22 |
|
import static org.apache.commons.io.IOUtils.copy; |
23 |
|
import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; |
24 |
|
import static org.codehaus.plexus.testing.PlexusExtension.getTestFile; |
25 |
|
|
26 |
|
import java.io.ByteArrayInputStream; |
27 |
|
import java.io.File; |
28 |
|
import java.io.FileInputStream; |
29 |
|
import java.io.FileOutputStream; |
30 |
|
import java.io.IOException; |
31 |
|
import java.io.InputStream; |
32 |
|
import java.nio.charset.StandardCharsets; |
33 |
|
import java.nio.file.Path; |
34 |
|
import java.util.HashMap; |
35 |
|
import java.util.Locale; |
36 |
|
import java.util.Map; |
37 |
|
import java.util.jar.JarOutputStream; |
38 |
|
import java.util.zip.ZipEntry; |
39 |
|
|
40 |
|
import javax.inject.Inject; |
41 |
|
|
42 |
|
import org.apache.maven.artifact.Artifact; |
43 |
|
import org.apache.maven.artifact.DefaultArtifact; |
44 |
|
import org.apache.maven.artifact.versioning.VersionRange; |
45 |
|
import org.apache.maven.doxia.site.SiteModel; |
46 |
|
import org.apache.maven.doxia.site.io.xpp3.SiteXpp3Reader; |
47 |
|
import org.codehaus.plexus.PlexusContainer; |
48 |
|
import org.codehaus.plexus.testing.PlexusTest; |
49 |
|
import org.codehaus.plexus.util.FileUtils; |
50 |
|
import org.devacfr.testing.jupiter.TestCase; |
51 |
|
import org.junit.jupiter.api.AfterEach; |
52 |
|
import org.junit.jupiter.api.BeforeEach; |
53 |
|
import org.junit.jupiter.api.Disabled; |
54 |
|
import org.junit.jupiter.api.Test; |
55 |
|
|
56 |
|
|
57 |
|
@author |
58 |
|
@author |
59 |
|
|
60 |
|
@PlexusTest |
61 |
|
@Disabled("not work when clover report is enabled") |
|
|
| 0% |
Uncovered Elements: 42 (42) |
Complexity: 4 |
Complexity Density: 0,11 |
|
62 |
|
public class DefaultSiteRendererTest extends TestCase { |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
private static final String OUTPUT = "target/output"; |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
private Renderer renderer; |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
private Locale oldLocale; |
78 |
|
|
79 |
|
@Inject |
80 |
|
private PlexusContainer container; |
81 |
|
|
82 |
|
private final File skinJar = new File(getBasedir(), "target/test-classes/skin.jar"); |
83 |
|
|
84 |
|
private final File minimalSkinJar = new File(getBasedir(), "target/test-classes/minimal-skin.jar"); |
85 |
|
|
86 |
|
|
87 |
|
@throws |
88 |
|
|
89 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 1 |
Complexity Density: 0,05 |
|
90 |
0 |
@BeforeEach... |
91 |
|
protected void setUp() throws Exception { |
92 |
0 |
renderer = container.lookup(Renderer.class); |
93 |
|
|
94 |
0 |
InputStream skinIS = getResource("velocity-toolmanager.vm").openStream(); |
95 |
0 |
JarOutputStream jarOS = new JarOutputStream(new FileOutputStream(skinJar)); |
96 |
0 |
try { |
97 |
0 |
jarOS.putNextEntry(new ZipEntry("META-INF/maven/site.vm")); |
98 |
0 |
copy(skinIS, jarOS); |
99 |
0 |
jarOS.closeEntry(); |
100 |
|
} finally { |
101 |
0 |
closeQuietly(skinIS); |
102 |
0 |
closeQuietly(jarOS); |
103 |
|
} |
104 |
|
|
105 |
0 |
skinIS = new ByteArrayInputStream( |
106 |
|
"<main id=\"contentBox\">$bodyContent</main>".getBytes(StandardCharsets.UTF_8)); |
107 |
0 |
jarOS = new JarOutputStream(new FileOutputStream(minimalSkinJar)); |
108 |
0 |
try { |
109 |
0 |
jarOS.putNextEntry(new ZipEntry("META-INF/maven/site.vm")); |
110 |
0 |
copy(skinIS, jarOS); |
111 |
0 |
jarOS.closeEntry(); |
112 |
|
} finally { |
113 |
0 |
closeQuietly(skinIS); |
114 |
0 |
closeQuietly(jarOS); |
115 |
|
} |
116 |
|
|
117 |
0 |
oldLocale = Locale.getDefault(); |
118 |
0 |
Locale.setDefault(Locale.ENGLISH); |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
@throws |
123 |
|
|
124 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
125 |
0 |
@AfterEach... |
126 |
|
protected void tearDown() throws Exception { |
127 |
0 |
container.release(renderer); |
128 |
|
|
129 |
0 |
Locale.setDefault(oldLocale); |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
@throws |
134 |
|
|
135 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
4-
|
|
136 |
0 |
@Test... |
137 |
|
public void shouldAcceptSnippet() throws Exception { |
138 |
|
|
139 |
0 |
FileUtils.deleteDirectory(getTestFile(OUTPUT)); |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
0 |
final SiteModel model = new SiteXpp3Reader() |
145 |
|
.read(new FileInputStream(getTestFile("src/test/resources/site/site.xml"))); |
146 |
|
|
147 |
0 |
final Path targetSite = getTestFile(OUTPUT).toPath(); |
148 |
0 |
final Path srcSite = getTestFile("src/test/resources/site").toPath(); |
149 |
0 |
final SiteRenderingContext ctxt = getSiteRenderingContext(model, srcSite, false); |
150 |
|
|
151 |
0 |
ctxt.setRootDirectory(getTestFile("")); |
152 |
0 |
renderer.render(renderer.locateDocumentFiles(ctxt, true).values(), ctxt, targetSite.toFile()); |
153 |
|
|
154 |
0 |
verify(targetSite.resolve("snippet.html"), getPackagePath().resolve("snippet.approved.html")); |
155 |
|
} |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0,11 |
|
157 |
0 |
private SiteRenderingContext getSiteRenderingContext(final SiteModel model,... |
158 |
|
final Path siteDir, |
159 |
|
final boolean validate) throws RendererException, IOException { |
160 |
0 |
final File skinFile = minimalSkinJar; |
161 |
|
|
162 |
0 |
final Map<String, String> attributes = new HashMap<>(); |
163 |
0 |
attributes.put("outputEncoding", "UTF-8"); |
164 |
|
|
165 |
0 |
final Artifact skin = new DefaultArtifact("org.group", "artifact", VersionRange.createFromVersion("1.1"), null, |
166 |
|
"jar", "", null); |
167 |
0 |
skin.setFile(skinFile); |
168 |
0 |
final SiteRenderingContext siteRenderingContext = renderer |
169 |
|
.createContextForSkin(skin, attributes, model, "defaultWindowTitle", Locale.ENGLISH); |
170 |
0 |
siteRenderingContext.addSiteDirectory(siteDir.toFile()); |
171 |
0 |
siteRenderingContext.setValidate(validate); |
172 |
|
|
173 |
0 |
return siteRenderingContext; |
174 |
|
} |
175 |
|
} |