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