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.net.URL;
23
24 import com.meterware.httpunit.GetMethodWebRequest;
25 import com.meterware.httpunit.TextBlock;
26 import com.meterware.httpunit.WebConversation;
27 import com.meterware.httpunit.WebRequest;
28 import com.meterware.httpunit.WebResponse;
29 import com.meterware.httpunit.WebTable;
30 import org.apache.maven.artifact.Artifact;
31 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
32 import org.apache.maven.project.ProjectBuilder;
33 import org.apache.maven.project.ProjectBuildingRequest;
34 import org.apache.maven.project.ProjectBuildingResult;
35 import org.mockito.invocation.InvocationOnMock;
36 import org.mockito.stubbing.Answer;
37
38 import static org.mockito.Mockito.isA;
39 import static org.mockito.Mockito.mock;
40 import static org.mockito.Mockito.when;
41
42
43
44
45
46 public class PluginManagementReportTest extends AbstractProjectInfoTestCase {
47
48
49
50 private static final WebConversation WEB_CONVERSATION = new WebConversation();
51
52 @Override
53 protected AbstractProjectInfoReport createReportMojo(String goal, File pluginXmlFile) throws Exception {
54 AbstractProjectInfoReport mojo = super.createReportMojo(goal, pluginXmlFile);
55
56 ProjectBuilder builder = mock(ProjectBuilder.class);
57
58 when(builder.build(isA(Artifact.class), isA(ProjectBuildingRequest.class)))
59 .thenAnswer(new Answer<ProjectBuildingResult>() {
60 @Override
61 public ProjectBuildingResult answer(InvocationOnMock invocation) throws Throwable {
62 return createProjectBuildingResult((Artifact) invocation.getArgument(0), "http://m.a.o/");
63 }
64 });
65
66 setVariableValueToObject(mojo, "projectBuilder", builder);
67
68 return mojo;
69 }
70
71
72
73
74
75
76 public void testReport() throws Exception {
77 generateReport(getGoal(), "plugin-management-plugin-config.xml");
78 assertTrue(
79 "Test html generated",
80 getGeneratedReport("plugin-management.html").exists());
81
82 URL reportURL = getGeneratedReport("plugin-management.html").toURI().toURL();
83 assertNotNull(reportURL);
84
85
86 WebRequest request = new GetMethodWebRequest(reportURL.toString());
87 WebResponse response = WEB_CONVERSATION.getResponse(request);
88
89
90 assertTrue(response.isHTML());
91 assertTrue(response.getContentLength() > 0);
92
93
94 String expectedTitle =
95 prepareTitle("plugin management project info", getString("report.plugin-management.title"));
96 assertEquals(expectedTitle, response.getTitle());
97
98
99 WebTable[] webTables = response.getTables();
100 assertEquals(1, webTables.length);
101
102 assertEquals(3, webTables[0].getColumnCount());
103 assertEquals(3, webTables[0].getRowCount());
104
105
106 TextBlock[] textBlocks = response.getTextBlocks();
107 assertEquals(getString("report.plugin-management.title"), textBlocks[1].getText());
108 }
109
110
111
112
113
114
115 public void testReportEclipseM2EPluginLifecycleMapping() throws Exception {
116 generateReport(getGoal(), "plugin-management-plugin-config-MPIR-375.xml");
117 assertTrue(
118 "Test html generated",
119 getGeneratedReport("plugin-management.html").exists());
120
121 URL reportURL = getGeneratedReport("plugin-management.html").toURI().toURL();
122 assertNotNull(reportURL);
123
124
125 WebRequest request = new GetMethodWebRequest(reportURL.toString());
126 WebResponse response = WEB_CONVERSATION.getResponse(request);
127
128
129 assertTrue(response.isHTML());
130 assertTrue(response.getContentLength() > 0);
131
132
133 String expectedTitle =
134 prepareTitle("plugin management project info", getString("report.plugin-management.title"));
135 assertEquals(expectedTitle, response.getTitle());
136
137
138 WebTable[] webTables = response.getTables();
139 assertEquals(1, webTables.length);
140
141
142 assertEquals(3, webTables[0].getColumnCount());
143 assertEquals(2, webTables[0].getRowCount());
144
145
146 assertEquals("org.apache.maven.plugins", webTables[0].getCellAsText(1, 0));
147 assertEquals("maven-javadoc-plugin", webTables[0].getCellAsText(1, 1));
148 assertEquals("3.0.1", webTables[0].getCellAsText(1, 2));
149
150
151 TextBlock[] textBlocks = response.getTextBlocks();
152 assertEquals(getString("report.plugin-management.title"), textBlocks[1].getText());
153 }
154
155 private static ProjectBuildingResult createProjectBuildingResult(Artifact artifact, String url) {
156 ProjectBuildingResult result = mock(ProjectBuildingResult.class);
157 MavenProjectStub stub = new MavenProjectStub();
158 stub.setGroupId(artifact.getGroupId());
159 stub.setArtifactId(artifact.getArtifactId());
160 stub.setVersion(artifact.getVersion());
161 stub.setUrl(url);
162
163 when(result.getProject()).thenReturn(stub);
164
165 return result;
166 }
167
168 @Override
169 protected String getGoal() {
170 return "plugin-management";
171 }
172 }