View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * @author Edwin Punzalan
33   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
34   * @version $Id$
35   */
36  public class MailingListsReportTest extends AbstractProjectInfoTestCase {
37      /**
38       * WebConversation object
39       */
40      private static final WebConversation WEB_CONVERSATION = new WebConversation();
41  
42      /**
43       * Test report
44       *
45       * @throws Exception if any
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          // HTTPUnit
56          WebRequest request = new GetMethodWebRequest(reportURL.toString());
57          WebResponse response = WEB_CONVERSATION.getResponse(request);
58  
59          // Basic HTML tests
60          assertTrue(response.isHTML());
61          assertTrue(response.getContentLength() > 0);
62  
63          // Test the Page title
64          String expectedTitle = prepareTitle("mailing lists project info", getString("report.mailing-lists.title"));
65          assertEquals(expectedTitle, response.getTitle());
66  
67          // Test the texts
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          // MPIR-385 + MPIR-401: Test links are URIs otherwise assume a plain email address
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       * Test custom bundle
89       *
90       * @throws Exception if any
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         // HTTPUnit
101         WebRequest request = new GetMethodWebRequest(reportURL.toString());
102         WebResponse response = WEB_CONVERSATION.getResponse(request);
103 
104         // Basic HTML tests
105         assertTrue(response.isHTML());
106         assertTrue(response.getContentLength() > 0);
107 
108         // Test the texts
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      * Test report in French (MPIR-59)
116      *
117      * @throws Exception if any
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      * Test invalid links (MPIR-404)
136      * Those should only lead to a WARN but not an exception
137      * @throws Exception if any
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 }