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 LicenseReportTest
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( "license", "license-plugin-config.xml" );
53 assertTrue( "Test html generated", getGeneratedReport( "license.html" ).exists() );
54
55 URL reportURL = getGeneratedReport( "license.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 assertEquals( getString( "report.license.title" ), response.getTitle() );
68
69
70 TextBlock[] textBlocks = response.getTextBlocks();
71 assertEquals( getString( "report.license.overview.title" ), textBlocks[0].getText() );
72 assertEquals( getString( "report.license.overview.intro" ), textBlocks[1].getText() );
73 assertEquals( getString( "report.license.name" ), textBlocks[2].getText() );
74 assertEquals( "The Apache Software License, Version 2.0", textBlocks[3].getText() );
75
76
77 final WebLink[] links = response.getLinks();
78 assertEquals( 1, links.length );
79 assertEquals( "http://maven.apache.org/", links[0].getURLString() );
80 }
81
82 public void testReportLinksOnly()
83 throws Exception
84 {
85 generateReport( "license", "license-plugin-config-linkonly.xml" );
86 assertTrue( "Test html generated", getGeneratedReport( "license.html" ).exists() );
87
88 URL reportURL = getGeneratedReport( "license.html" ).toURI().toURL();
89 assertNotNull( reportURL );
90
91
92 WebRequest request = new GetMethodWebRequest( reportURL.toString() );
93 WebResponse response = WEB_CONVERSATION.getResponse( request );
94
95
96 assertTrue( response.isHTML() );
97 assertTrue( response.getContentLength() > 0 );
98
99
100 assertEquals( getString( "report.license.title" ), response.getTitle() );
101
102
103 TextBlock[] textBlocks = response.getTextBlocks();
104 assertEquals( getString( "report.license.overview.title" ), textBlocks[0].getText() );
105 assertEquals( getString( "report.license.overview.intro" ), textBlocks[1].getText() );
106 assertEquals( getString( "report.license.name" ), textBlocks[2].getText() );
107 assertEquals( "The Apache Software License, Version 2.0", textBlocks[3].getText() );
108
109
110 final WebLink[] links = response.getLinks();
111 assertEquals( 2, links.length );
112 assertEquals( "http://maven.apache.org/", links[0].getURLString() );
113 assertEquals( "http://www.apache.org/licenses/LICENSE-2.0.txt", links[1].getURLString() );
114 assertEquals( "http://www.apache.org/licenses/LICENSE-2.0.txt", links[1].getText() );
115 }
116 }