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 org.apache.maven.report.projectinfo.MailingListsReport.MailingListsRenderer;
26  
27  import junitx.util.PrivateAccessor;
28  
29  import com.meterware.httpunit.GetMethodWebRequest;
30  import com.meterware.httpunit.TextBlock;
31  import com.meterware.httpunit.WebConversation;
32  import com.meterware.httpunit.WebRequest;
33  import com.meterware.httpunit.WebResponse;
34  
35  /**
36   * @author Edwin Punzalan
37   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
38   * @version $Id: MailingListsReportTest.java 890109 2009-12-13 19:57:28Z ltheussl $
39   */
40  public class MailingListsReportTest
41      extends AbstractProjectInfoTestCase
42  {
43      /**
44       * WebConversation object
45       */
46      private static final WebConversation WEB_CONVERSATION = new WebConversation();
47  
48      /**
49       * Test report
50       *
51       * @throws Exception if any
52       */
53      public void testReport()
54          throws Exception
55      {
56          generateReport( "mailing-list", "mailing-list-plugin-config.xml" );
57          assertTrue( "Test html generated", getGeneratedReport( "mail-lists.html" ).exists() );
58  
59          URL reportURL = getGeneratedReport( "mail-lists.html" ).toURI().toURL();
60          assertNotNull( reportURL );
61  
62          // HTTPUnit
63          WebRequest request = new GetMethodWebRequest( reportURL.toString() );
64          WebResponse response = WEB_CONVERSATION.getResponse( request );
65  
66          // Basic HTML tests
67          assertTrue( response.isHTML() );
68          assertTrue( response.getContentLength() > 0 );
69  
70          // Test the Page title
71          assertEquals( getString( "report.mailing-lists.name" ) + " - " + getString( "report.mailing-lists.title" ),
72                        response.getTitle() );
73  
74          // Test the texts
75          TextBlock[] textBlocks = response.getTextBlocks();
76          assertEquals( textBlocks[0].getText(), getString( "report.mailing-lists.title" ) );
77          assertEquals( textBlocks[1].getText(), getString( "report.mailing-lists.intro" ) );
78      }
79  
80      /**
81       * Test report in French (MPIR-59)
82       *
83       * @throws Exception if any
84       */
85      public void testFrenchReport()
86          throws Exception
87      {
88          Locale oldLocale = Locale.getDefault();
89  
90          try
91          {
92              Locale.setDefault( Locale.FRENCH );
93  
94              generateReport( "mailing-list", "mailing-list-plugin-config.xml" );
95              assertTrue( "Test html generated", getGeneratedReport( "mail-lists.html" ).exists() );
96          }
97          finally
98          {
99              Locale.setDefault( oldLocale );
100         }
101     }
102 
103     /**
104      * @throws Throwable if any
105      */
106     public void testGetArchiveServer()
107         throws Throwable
108     {
109         String server = "http://mail-archives.apache.org/mod_mbox/maven-announce/";
110         assertEquals( "mail-archives.apache.org", invokeGetArchiveServer( server ) );
111 
112         server = "http://mail-archives.apache.org/mod_mbox/maven-announce";
113         assertEquals( "mail-archives.apache.org", invokeGetArchiveServer( server ) );
114 
115         server = "http://www.mail-archive.com/announce@maven.apache.org";
116         assertEquals( "www.mail-archive.com", invokeGetArchiveServer( server ) );
117 
118         server = "http://www.nabble.com/Maven-Announcements-f15617.html";
119         assertEquals( "www.nabble.com", invokeGetArchiveServer( server ) );
120 
121         server = "http://maven.announce.markmail.org/";
122         assertEquals( "maven.announce.markmail.org", invokeGetArchiveServer( server ) );
123 
124         server = "http://maven.announce.markmail.org";
125         assertEquals( "maven.announce.markmail.org", invokeGetArchiveServer( server ) );
126     }
127 
128     /**
129      * @throws Throwable if any
130      */
131     private static String invokeGetArchiveServer( String s )
132         throws Throwable
133     {
134         return (String) PrivateAccessor.invoke( MailingListsRenderer.class, "getArchiveServer",
135                                                 new Class[] { String.class }, new Object[] { s } );
136     }
137 }