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 testFrenchReport() throws Exception {
93 Locale oldLocale = Locale.getDefault();
94
95 try {
96 Locale.setDefault(Locale.FRENCH);
97
98 generateReport("mailing-lists", "mailing-lists-plugin-config.xml");
99 assertTrue(
100 "Test html generated",
101 getGeneratedReport("mailing-lists.html").exists());
102 } finally {
103 Locale.setDefault(oldLocale);
104 }
105 }
106
107
108
109
110
111
112 public void testInvalidLink() throws Exception {
113 generateReport("mailing-lists", "mailing-lists-plugin-config-invalidlink.xml");
114 assertTrue(
115 "Test html generated", getGeneratedReport("mailing-lists.html").exists());
116 }
117 }