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.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.WebLink;
28 import com.meterware.httpunit.WebRequest;
29 import com.meterware.httpunit.WebResponse;
30
31
32
33
34
35
36 public class LicensesReportTest
37 extends AbstractProjectInfoTestCase
38 {
39
40
41
42 private static final WebConversation WEB_CONVERSATION = new WebConversation();
43
44
45
46
47
48
49 public void testReport()
50 throws Exception
51 {
52 generateReport( "licenses", "licenses-plugin-config.xml" );
53 assertTrue( "Test html generated", getGeneratedReport( "licenses.html" ).exists() );
54
55 URL reportURL = getGeneratedReport( "licenses.html" ).toURI().toURL();
56 assertNotNull( reportURL );
57
58
59 WebRequest request = new GetMethodWebRequest( reportURL.toString() );
60 WebResponse response = WEB_CONVERSATION.getResponse( request );
61
62
63 assertTrue( response.isHTML() );
64 assertTrue( response.getContentLength() > 0 );
65
66
67 String expectedTitle = prepareTitle( getString( "report.licenses.name" ),
68 getString( "report.licenses.title" ) );
69 assertEquals( expectedTitle, response.getTitle() );
70
71
72 TextBlock[] textBlocks = response.getTextBlocks();
73 assertEquals( getString( "report.licenses.overview.title" ), textBlocks[0].getText() );
74 assertEquals( getString( "report.licenses.overview.intro" ), textBlocks[1].getText() );
75 assertEquals( getString( "report.licenses.title" ), textBlocks[2].getText() );
76 assertEquals( "The Apache Software License, Version 2.0", textBlocks[3].getText() );
77
78
79 final WebLink[] links = response.getLinks();
80 assertEquals( 1, links.length );
81 assertEquals( "http://maven.apache.org/", links[0].getURLString() );
82 }
83
84 public void testReportLinksOnly()
85 throws Exception
86 {
87 generateReport( "licenses", "licenses-plugin-config-linkonly.xml" );
88 assertTrue( "Test html generated", getGeneratedReport( "licenses.html" ).exists() );
89
90 URL reportURL = getGeneratedReport( "licenses.html" ).toURI().toURL();
91 assertNotNull( reportURL );
92
93
94 WebRequest request = new GetMethodWebRequest( reportURL.toString() );
95 WebResponse response = WEB_CONVERSATION.getResponse( request );
96
97
98 assertTrue( response.isHTML() );
99 assertTrue( response.getContentLength() > 0 );
100
101
102 String expectedTitle = prepareTitle( getString( "report.licenses.name" ),
103 getString( "report.licenses.title" ) );
104 assertEquals( expectedTitle, response.getTitle() );
105
106
107 TextBlock[] textBlocks = response.getTextBlocks();
108 assertEquals( getString( "report.licenses.overview.title" ), textBlocks[0].getText() );
109 assertEquals( getString( "report.licenses.overview.intro" ), textBlocks[1].getText() );
110 assertEquals( getString( "report.licenses.title" ), textBlocks[2].getText() );
111 assertEquals( "The Apache Software License, Version 2.0", textBlocks[3].getText() );
112
113
114 final WebLink[] links = response.getLinks();
115 assertEquals( 2, links.length );
116 assertEquals( "http://maven.apache.org/", links[0].getURLString() );
117 assertEquals( "http://www.apache.org/licenses/LICENSE-2.0.txt", links[1].getURLString() );
118 assertEquals( "http://www.apache.org/licenses/LICENSE-2.0.txt", links[1].getText() );
119 }
120 }