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