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