1 package org.apache.maven.report.projectinfo;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.when;
24 import static org.mockito.Mockito.isA;
25
26 import java.io.File;
27 import java.net.URL;
28
29 import org.apache.maven.artifact.Artifact;
30 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
31 import org.apache.maven.project.ProjectBuilder;
32 import org.apache.maven.project.ProjectBuildingRequest;
33 import org.apache.maven.project.ProjectBuildingResult;
34 import org.mockito.invocation.InvocationOnMock;
35 import org.mockito.stubbing.Answer;
36
37 import com.meterware.httpunit.GetMethodWebRequest;
38 import com.meterware.httpunit.TextBlock;
39 import com.meterware.httpunit.WebConversation;
40 import com.meterware.httpunit.WebRequest;
41 import com.meterware.httpunit.WebResponse;
42 import com.meterware.httpunit.WebTable;
43
44
45
46
47
48 public class PluginManagementReportTest
49 extends AbstractProjectInfoTestCase
50 {
51
52
53
54 private static final WebConversation WEB_CONVERSATION = new WebConversation();
55
56
57
58 @Override
59 protected AbstractProjectInfoReport createReportMojo( String goal, File pluginXmlFile )
60 throws Exception
61 {
62 AbstractProjectInfoReport mojo = super.createReportMojo( goal, pluginXmlFile );
63
64 ProjectBuilder builder = mock( ProjectBuilder.class );
65
66 when( builder.build( isA( Artifact.class ),
67 isA( ProjectBuildingRequest.class ) ) ).thenAnswer( new Answer<ProjectBuildingResult>()
68 {
69 @Override
70 public ProjectBuildingResult answer( InvocationOnMock invocation )
71 throws Throwable
72 {
73 return createProjectBuildingResult( (Artifact) invocation.getArgument( 0 ),
74 "http://m.a.o/" );
75 }
76 } );
77
78 setVariableValueToObject( mojo, "projectBuilder", builder );
79
80 return mojo;
81 }
82
83
84
85
86
87
88 public void testReport()
89 throws Exception
90 {
91 generateReport( "plugin-management", "plugin-management-plugin-config.xml" );
92 assertTrue( "Test html generated", getGeneratedReport( "plugin-management.html" ).exists() );
93
94 URL reportURL = getGeneratedReport( "plugin-management.html" ).toURI().toURL();
95 assertNotNull( reportURL );
96
97
98 WebRequest request = new GetMethodWebRequest( reportURL.toString() );
99 WebResponse response = WEB_CONVERSATION.getResponse( request );
100
101
102 assertTrue( response.isHTML() );
103 assertTrue( response.getContentLength() > 0 );
104
105
106 String expectedTitle = prepareTitle( getString( "report.plugin-management.name" ),
107 getString( "report.plugin-management.title" ) );
108 assertEquals( expectedTitle, response.getTitle() );
109
110
111 WebTable[] webTables = response.getTables();
112 assertEquals( 1, webTables.length );
113
114 assertEquals( 3, webTables[0].getColumnCount() );
115 assertEquals( 3, webTables[0].getRowCount() );
116
117
118 TextBlock[] textBlocks = response.getTextBlocks();
119 assertEquals( getString( "report.plugin-management.title" ), textBlocks[0].getText() );
120 }
121
122 private static ProjectBuildingResult createProjectBuildingResult( Artifact artifact, String url )
123 {
124 ProjectBuildingResult result = mock( ProjectBuildingResult.class );
125 MavenProjectStub stub = new MavenProjectStub();
126 stub.setGroupId( artifact.getGroupId() );
127 stub.setArtifactId( artifact.getArtifactId() );
128 stub.setVersion( artifact.getVersion() );
129 stub.setUrl( url );
130
131 when( result.getProject() ).thenReturn( stub );
132
133 return result;
134 }
135 }