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  
24  import com.meterware.httpunit.GetMethodWebRequest;
25  import com.meterware.httpunit.TextBlock;
26  import com.meterware.httpunit.WebConversation;
27  import com.meterware.httpunit.WebRequest;
28  import com.meterware.httpunit.WebResponse;
29  
30  /**
31   * @author ltheussl
32   * @version $Id: ModulesReportTest.html 861765 2013-05-12 18:46:29Z hboutemy $
33   */
34  public class ModulesReportTest
35      extends AbstractProjectInfoTestCase
36  {
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()
48          throws Exception
49      {
50          generateReport( "modules", "modules-plugin-config.xml" );
51          assertTrue( "Test html generated", getGeneratedReport( "modules.html" ).exists() );
52  
53          URL reportURL = getGeneratedReport( "modules.html" ).toURI().toURL();
54          assertNotNull( reportURL );
55  
56          // HTTPUnit
57          WebRequest request = new GetMethodWebRequest( reportURL.toString() );
58          WebResponse response = WEB_CONVERSATION.getResponse( request );
59  
60          // Basic HTML tests
61          assertTrue( response.isHTML() );
62          assertTrue( response.getContentLength() > 0 );
63  
64          // Test the Page title
65          assertEquals( getString( "report.modules.title" ), response.getTitle() );
66  
67          // Test the texts
68          TextBlock[] textBlocks = response.getTextBlocks();
69          assertEquals( 2, textBlocks.length );
70          assertEquals( getString( "report.modules.title" ), textBlocks[0].getText() );
71          assertEquals( getString( "report.modules.intro" ), textBlocks[1].getText() );
72  
73          String[][] cellTexts = response.getTables()[0].asText();
74          assertEquals( 3, cellTexts.length );
75          assertEquals( 2, cellTexts[0].length );
76          assertEquals( getString( "report.modules.header.name" ), cellTexts[0][0] );
77          assertEquals( getString( "report.modules.header.description" ), cellTexts[0][1] );
78          assertEquals( "project1", cellTexts[1][0] );
79          assertEquals( "-", cellTexts[1][1] );
80          assertEquals( "project2", cellTexts[2][0] );
81          assertEquals( "project2 description", cellTexts[2][1] );
82      }
83  }