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 import java.util.Locale;
24
25 import com.meterware.httpunit.GetMethodWebRequest;
26 import com.meterware.httpunit.TextBlock;
27 import com.meterware.httpunit.WebConversation;
28 import com.meterware.httpunit.WebLink;
29 import com.meterware.httpunit.WebRequest;
30 import com.meterware.httpunit.WebResponse;
31
32
33
34
35
36
37 public class MailingListsReportTest
38 extends AbstractProjectInfoTestCase
39 {
40
41
42
43 private static final WebConversation WEB_CONVERSATION = new WebConversation();
44
45
46
47
48
49
50 public void testReport()
51 throws Exception
52 {
53 generateReport( "mailing-lists", "mailing-lists-plugin-config.xml" );
54 assertTrue( "Test html generated", getGeneratedReport( "mailing-lists.html" ).exists() );
55
56 URL reportURL = getGeneratedReport( "mailing-lists.html" ).toURI().toURL();
57 assertNotNull( reportURL );
58
59
60 WebRequest request = new GetMethodWebRequest( reportURL.toString() );
61 WebResponse response = WEB_CONVERSATION.getResponse( request );
62
63
64 assertTrue( response.isHTML() );
65 assertTrue( response.getContentLength() > 0 );
66
67
68 String expectedTitle = prepareTitle( getString( "report.mailing-lists.name" ),
69 getString( "report.mailing-lists.title" ) );
70 assertEquals( expectedTitle, response.getTitle() );
71
72
73 TextBlock[] textBlocks = response.getTextBlocks();
74 assertEquals( getString( "report.mailing-lists.title" ), textBlocks[0].getText() );
75 assertEquals( getString( "report.mailing-lists.intro" ), textBlocks[1].getText() );
76
77
78 String post = getString("report.mailing-lists.column.post");
79 WebLink[] postLinks = response.getMatchingLinks( WebLink.MATCH_CONTAINED_TEXT, post );
80 assertEquals( "mailto:test@maven.apache.org", postLinks[0].getAttribute( "href" ) );
81 assertEquals( "mailto:test2@maven.apache.org", postLinks[1].getAttribute( "href" ) );
82 String subscribe = getString("report.mailing-lists.column.subscribe");
83 WebLink[] subscribeLinks = response.getMatchingLinks( WebLink.MATCH_CONTAINED_TEXT, subscribe );
84 assertEquals( "MAILTO:test-subscribe@maven.apache.org", subscribeLinks[0].getAttribute( "href" ) );
85 assertEquals( "MAILTO:test-subscribe2@maven.apache.org", subscribeLinks[1].getAttribute( "href" ) );
86 String unsubscribe = getString("report.mailing-lists.column.unsubscribe");
87 WebLink[] unsubscribeLinks = response.getMatchingLinks( WebLink.MATCH_CONTAINED_TEXT, unsubscribe );
88 assertTrue( unsubscribeLinks.length == 1 );
89 assertEquals( "https://example.com/unsubscribe", unsubscribeLinks[0].getAttribute( "href" ) );
90 }
91
92
93
94
95
96
97 public void testFrenchReport()
98 throws Exception
99 {
100 Locale oldLocale = Locale.getDefault();
101
102 try
103 {
104 Locale.setDefault( Locale.FRENCH );
105
106 generateReport( "mailing-lists", "mailing-lists-plugin-config.xml" );
107 assertTrue( "Test html generated", getGeneratedReport( "mailing-lists.html" ).exists() );
108 }
109 finally
110 {
111 Locale.setDefault( oldLocale );
112 }
113 }
114 }