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.io.File;
22  import java.net.URL;
23  
24  import com.meterware.httpunit.GetMethodWebRequest;
25  import com.meterware.httpunit.TableCell;
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  import com.meterware.httpunit.WebTable;
32  
33  /**
34   * @author Edwin Punzalan
35   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
36   * @version $Id$
37   */
38  public class TeamReportTest extends AbstractProjectInfoTestCase {
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() throws Exception {
50          File pluginXmlFile = new File(getBasedir(), "src/test/resources/plugin-configs/" + "team-plugin-config.xml");
51          AbstractProjectInfoReport mojo = createReportMojo("team", pluginXmlFile);
52          setVariableValueToObject(mojo, "showAvatarImages", Boolean.TRUE);
53          generateReport(mojo, pluginXmlFile);
54          assertTrue("Test html generated", getGeneratedReport("team.html").exists());
55  
56          URL reportURL = getGeneratedReport("team.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("team project info", getString("report.team.title"));
69          assertEquals(expectedTitle, response.getTitle());
70  
71          assertTrue(response.getText().contains("gravatar"));
72  
73          // Test the texts
74          TextBlock[] textBlocks = response.getTextBlocks();
75          assertEquals(7, textBlocks.length);
76          assertEquals(getString("report.team.intro.title"), textBlocks[0].getText());
77          assertEquals(getString("report.team.intro.description1"), textBlocks[1].getText());
78          assertEquals(getString("report.team.intro.description2"), textBlocks[2].getText());
79          assertEquals(getString("report.team.developers.title"), textBlocks[3].getText());
80          assertEquals(getString("report.team.developers.intro"), textBlocks[4].getText());
81          assertEquals(getString("report.team.contributors.title"), textBlocks[5].getText());
82          assertEquals(getString("report.team.nocontributor"), textBlocks[6].getText());
83  
84          WebTable[] tables = response.getTables();
85          assertEquals(1, tables.length);
86          TableCell emailCell = tables[0].getTableCell(1, 3);
87          assertEquals("vsiveton@apache.org", emailCell.getText());
88          WebLink[] links = emailCell.getLinks();
89          assertEquals(1, links.length);
90          assertEquals("mailto:vsiveton@apache.org", links[0].getURLString());
91      }
92  }