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