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  
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   * @author Edwin Punzalan
32   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
33   * @version $Id$
34   */
35  public class MailingListsReportTest extends AbstractProjectInfoTestCase {
36      /**
37       * WebConversation object
38       */
39      private static final WebConversation WEB_CONVERSATION = new WebConversation();
40  
41      /**
42       * Test report
43       *
44       * @throws Exception if any
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          // HTTPUnit
55          WebRequest request = new GetMethodWebRequest(reportURL.toString());
56          WebResponse response = WEB_CONVERSATION.getResponse(request);
57  
58          // Basic HTML tests
59          assertTrue(response.isHTML());
60          assertTrue(response.getContentLength() > 0);
61  
62          // Test the Page title
63          String expectedTitle = prepareTitle("mailing lists project info", getString("report.mailing-lists.title"));
64          assertEquals(expectedTitle, response.getTitle());
65  
66          // Test the texts
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          // MPIR-385 + MPIR-401: Test links are URIs otherwise assume a plain email address
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       * Test custom bundle
88       *
89       * @throws Exception if any
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          // HTTPUnit
100         WebRequest request = new GetMethodWebRequest(reportURL.toString());
101         WebResponse response = WEB_CONVERSATION.getResponse(request);
102 
103         // Basic HTML tests
104         assertTrue(response.isHTML());
105         assertTrue(response.getContentLength() > 0);
106 
107         // Test the texts
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      * Test report in French (MPIR-59)
115      *
116      * @throws Exception if any
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      * Test invalid links (MPIR-404)
126      * Those should only lead to a WARN but not an exception
127      * @throws Exception if any
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 }