1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.report.projectinfo;
20
21 import java.io.File;
22 import java.lang.reflect.Field;
23 import java.net.URL;
24 import java.nio.charset.StandardCharsets;
25 import java.nio.file.Files;
26 import java.util.Collections;
27
28 import com.meterware.httpunit.GetMethodWebRequest;
29 import com.meterware.httpunit.TextBlock;
30 import com.meterware.httpunit.WebConversation;
31 import com.meterware.httpunit.WebRequest;
32 import com.meterware.httpunit.WebResponse;
33 import org.apache.maven.plugin.testing.SilentLog;
34 import org.apache.maven.report.projectinfo.stubs.SubProject1Stub;
35 import org.codehaus.plexus.util.ReflectionUtils;
36
37
38
39
40
41 public class ModulesReportTest extends AbstractProjectInfoTestCase {
42
43
44
45 private static final WebConversation WEB_CONVERSATION = new WebConversation();
46
47 @Override
48 protected AbstractProjectInfoReport createReportMojo(String goal, File pluginXmlFile) throws Exception {
49 AbstractProjectInfoReport mojo = super.createReportMojo(goal, pluginXmlFile);
50
51 mojo.setLog(new SilentLog());
52
53 return mojo;
54 }
55
56
57
58
59
60
61 public void testReport() throws Exception {
62 generateReport(getGoal(), "modules-plugin-config.xml");
63 assertTrue("Test html generated", getGeneratedReport("modules.html").exists());
64
65 URL reportURL = getGeneratedReport("modules.html").toURI().toURL();
66 assertNotNull(reportURL);
67
68
69 WebRequest request = new GetMethodWebRequest(reportURL.toString());
70 WebResponse response = WEB_CONVERSATION.getResponse(request);
71
72
73 assertTrue(response.isHTML());
74 assertTrue(response.getContentLength() > 0);
75
76
77 String expectedTitle = prepareTitle("modules project info", getString("report.modules.title"));
78 assertEquals(expectedTitle, response.getTitle());
79
80
81 TextBlock[] textBlocks = response.getTextBlocks();
82
83 assertEquals(4, textBlocks.length - 1);
84 assertEquals(getString("report.modules.title"), textBlocks[1].getText());
85 assertEquals(getString("report.modules.intro"), textBlocks[2].getText());
86
87 String[][] cellTexts = response.getTables()[0].asText();
88 assertEquals(3, cellTexts.length);
89 assertEquals(2, cellTexts[0].length);
90 assertEquals(getString("report.modules.header.name"), cellTexts[0][0]);
91 assertEquals(getString("report.modules.header.description"), cellTexts[0][1]);
92 assertEquals("project1", cellTexts[1][0]);
93 assertEquals("-", cellTexts[1][1]);
94 assertEquals("project2", cellTexts[2][0]);
95 assertEquals("project2 description", cellTexts[2][1]);
96 }
97
98
99
100
101
102
103 public void testReportModuleLinksVariableSettingsInterpolated() throws Exception {
104 String pluginXml = "modules-variable-settings-interpolated-plugin-config.xml";
105 File pluginXmlFile = new File(getBasedir(), "src/test/resources/plugin-configs/" + pluginXml);
106 AbstractProjectInfoReport mojo = createReportMojo(getGoal(), pluginXmlFile);
107
108 class SubProjectStub extends SubProject1Stub {
109 @Override
110 public File getBasedir() {
111 return new File("src/test/resources/plugin-configs/subproject-site-url").getAbsoluteFile();
112 }
113
114 @Override
115 protected String getPOM() {
116 return "pom.xml";
117 }
118 }
119 Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses("reactorProjects", mojo.getClass());
120 field.setAccessible(true);
121 field.set(mojo, Collections.singletonList(new SubProjectStub()));
122
123 generateReport(mojo, pluginXmlFile);
124
125 assertFalse(
126 "Variable 'sitePublishLocation' should be interpolated",
127 new String(Files.readAllBytes(getGeneratedReport("modules.html").toPath()), StandardCharsets.UTF_8)
128 .contains("sitePublishLocation"));
129 }
130
131 @Override
132 protected String getGoal() {
133 return "modules";
134 }
135 }