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(getGoal(), pluginXmlFile);
52          setVariableValueToObject(mojo, "showAvatarImages", Boolean.TRUE);
53          setVariableValueToObject(mojo, "externalAvatarImages", Boolean.TRUE);
54          setVariableValueToObject(mojo, "avatarProviderName", "gravatar");
55          setVariableValueToObject(mojo, "avatarBaseUrl", "https://www.gravatar.com/avatar/");
56          generateReport(mojo, pluginXmlFile);
57          assertTrue("Test html generated", getGeneratedReport("team.html").exists());
58  
59          URL reportURL = getGeneratedReport("team.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          String expectedTitle = prepareTitle("team project info", getString("report.team.title"));
72          assertEquals(expectedTitle, response.getTitle());
73  
74          assertTrue(response.getText().contains("gravatar"));
75  
76          // Test the texts
77          TextBlock[] textBlocks = response.getTextBlocks();
78          // Last one is footer noise
79          assertEquals(9, textBlocks.length - 1);
80          assertEquals(getString("report.team.intro.title"), textBlocks[1].getText());
81          assertEquals(getString("report.team.intro.description1"), textBlocks[2].getText());
82          assertEquals(getString("report.team.intro.description2"), textBlocks[3].getText());
83          assertEquals(getString("report.team.developers.title"), textBlocks[4].getText());
84          assertEquals(getString("report.team.developers.intro"), textBlocks[5].getText());
85          assertEquals(getString("report.team.contributors.title"), textBlocks[6].getText());
86          assertEquals(getString("report.team.nocontributor"), textBlocks[7].getText());
87  
88          WebTable[] tables = response.getTables();
89          assertEquals(1, tables.length);
90          TableCell emailCell = tables[0].getTableCell(1, 3);
91          assertEquals("vsiveton@apache.org", emailCell.getText());
92          WebLink[] links = emailCell.getLinks();
93          assertEquals(1, links.length);
94          assertEquals("mailto:vsiveton@apache.org", links[0].getURLString());
95      }
96  
97      @Override
98      protected String getGoal() {
99          return "team";
100     }
101 }