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