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