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 MailingListsReportTest 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(), "mailing-lists-plugin-config.xml");
48 assertTrue(
49 "Test html generated", getGeneratedReport("mailing-lists.html").exists());
50
51 URL reportURL = getGeneratedReport("mailing-lists.html").toURI().toURL();
52 assertNotNull(reportURL);
53
54
55 WebRequest request = new GetMethodWebRequest(reportURL.toString());
56 WebResponse response = WEB_CONVERSATION.getResponse(request);
57
58
59 assertTrue(response.isHTML());
60 assertTrue(response.getContentLength() > 0);
61
62
63 String expectedTitle = prepareTitle("mailing lists project info", getString("report.mailing-lists.title"));
64 assertEquals(expectedTitle, response.getTitle());
65
66
67 TextBlock[] textBlocks = response.getTextBlocks();
68 assertEquals(getString("report.mailing-lists.title"), textBlocks[1].getText());
69 assertEquals(getString("report.mailing-lists.intro"), textBlocks[2].getText());
70
71
72 String post = getString("report.mailing-lists.column.post");
73 WebLink[] postLinks = response.getMatchingLinks(WebLink.MATCH_CONTAINED_TEXT, post);
74 assertEquals("mailto:test@maven.apache.org", postLinks[0].getAttribute("href"));
75 assertEquals("mailto:test2@maven.apache.org", postLinks[1].getAttribute("href"));
76 String subscribe = getString("report.mailing-lists.column.subscribe");
77 WebLink[] subscribeLinks = response.getMatchingLinks(WebLink.MATCH_CONTAINED_TEXT, subscribe);
78 assertEquals("MAILTO:test-subscribe@maven.apache.org", subscribeLinks[0].getAttribute("href"));
79 assertEquals("MAILTO:test-subscribe2@maven.apache.org", subscribeLinks[1].getAttribute("href"));
80 String unsubscribe = getString("report.mailing-lists.column.unsubscribe");
81 WebLink[] unsubscribeLinks = response.getMatchingLinks(WebLink.MATCH_CONTAINED_TEXT, unsubscribe);
82 assertTrue(unsubscribeLinks.length == 1);
83 assertEquals("https://example.com/unsubscribe", unsubscribeLinks[0].getAttribute("href"));
84 }
85
86
87
88
89
90
91 public void testCustomBundle() throws Exception {
92 generateReport("mailing-lists", "custom-bundle/plugin-config.xml");
93 assertTrue(
94 "Test html generated", getGeneratedReport("mailing-lists.html").exists());
95
96 URL reportURL = getGeneratedReport("mailing-lists.html").toURI().toURL();
97 assertNotNull(reportURL);
98
99
100 WebRequest request = new GetMethodWebRequest(reportURL.toString());
101 WebResponse response = WEB_CONVERSATION.getResponse(request);
102
103
104 assertTrue(response.isHTML());
105 assertTrue(response.getContentLength() > 0);
106
107
108 TextBlock[] textBlocks = response.getTextBlocks();
109 assertEquals(getString("report.mailing-lists.title"), textBlocks[1].getText());
110 assertEquals("mail list intro text foo", textBlocks[2].getText());
111 }
112
113
114
115
116
117
118 public void testFrenchReport() throws Exception {
119 generateReport(getGoal(), "mailing-lists-plugin-config-fr.xml");
120 assertTrue(
121 "Test html generated", getGeneratedReport("mailing-lists.html").exists());
122 }
123
124
125
126
127
128
129 public void testInvalidLink() throws Exception {
130 generateReport(getGoal(), "mailing-lists-plugin-config-invalidlink.xml");
131 assertTrue(
132 "Test html generated", getGeneratedReport("mailing-lists.html").exists());
133 }
134
135 @Override
136 protected String getGoal() {
137 return "mailing-lists";
138 }
139 }