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.io.File;
23  import java.net.URL;
24  
25  import com.meterware.httpunit.GetMethodWebRequest;
26  import com.meterware.httpunit.TextBlock;
27  import com.meterware.httpunit.WebConversation;
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: TeamListReportTest.html 861765 2013-05-12 18:46:29Z hboutemy $
35   */
36  public class TeamListReportTest
37      extends AbstractProjectInfoTestCase
38  {
39      /**
40       * WebConversation object
41       */
42      private static final WebConversation WEB_CONVERSATION = new WebConversation();
43  
44      /**
45       * Test report
46       *
47       * @throws Exception if any
48       */
49      public void testReport()
50          throws Exception
51      {
52          File pluginXmlFile = new File( getBasedir(), "src/test/resources/plugin-configs/" + "project-team-plugin-config.xml" );
53          AbstractProjectInfoReport mojo  = createReportMojo( "project-team", pluginXmlFile );
54          setVariableValueToObject( mojo, "showAvatarImages", Boolean.TRUE );
55         generateReport( mojo, pluginXmlFile);
56          assertTrue( "Test html generated", getGeneratedReport( "team-list.html" ).exists() );
57  
58          URL reportURL = getGeneratedReport( "team-list.html" ).toURI().toURL();
59          assertNotNull( reportURL );
60  
61          // HTTPUnit
62          WebRequest request = new GetMethodWebRequest( reportURL.toString() );
63          WebResponse response = WEB_CONVERSATION.getResponse( request );
64  
65          // Basic HTML tests
66          assertTrue( response.isHTML() );
67          assertTrue( response.getContentLength() > 0 );
68  
69          // Test the Page title
70          assertEquals( getString( "report.team-list.title" ), response.getTitle() );
71  
72          assertTrue( response.getText().contains( "gravatar" ));
73  
74          // Test the texts
75          TextBlock[] textBlocks = response.getTextBlocks();
76  
77          assertEquals( textBlocks.length, 7 );
78  
79          assertEquals( getString( "report.team-list.intro.title" ), textBlocks[0].getText() );
80          assertEquals( getString( "report.team-list.intro.description1" ), textBlocks[1].getText() );
81          assertEquals( getString( "report.team-list.intro.description2" ), textBlocks[2].getText() );
82          assertEquals( getString( "report.team-list.developers.title" ), textBlocks[3].getText() );
83          assertEquals( getString( "report.team-list.developers.intro" ), textBlocks[4].getText() );
84          assertEquals( getString( "report.team-list.contributors.title" ), textBlocks[5].getText() );
85          assertEquals( getString( "report.team-list.nocontributor" ), textBlocks[6].getText() );
86      }
87  }