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.net.URL;
22  
23  import com.meterware.httpunit.GetMethodWebRequest;
24  import com.meterware.httpunit.TextBlock;
25  import com.meterware.httpunit.WebConversation;
26  import com.meterware.httpunit.WebRequest;
27  import com.meterware.httpunit.WebResponse;
28  import com.meterware.httpunit.WebTable;
29  
30  /**
31   * @author Nick Stolwijk
32   * @version $Id$
33   * @since 2.1
34   */
35  public class DependencyManagementReportTest extends AbstractProjectInfoTestCase {
36      /**
37       * WebConversation object
38       */
39      private static final WebConversation WEB_CONVERSATION = new WebConversation();
40  
41      /**
42       * Test report
43       *
44       * @throws Exception if any
45       */
46      public void testReport() throws Exception {
47          generateReport("dependency-management", "dependency-management-plugin-config.xml");
48          assertTrue(
49                  "Test html generated",
50                  getGeneratedReport("dependency-management.html").exists());
51  
52          URL reportURL = getGeneratedReport("dependency-management.html").toURI().toURL();
53          assertNotNull(reportURL);
54  
55          // HTTPUnit
56          WebRequest request = new GetMethodWebRequest(reportURL.toString());
57          WebResponse response = WEB_CONVERSATION.getResponse(request);
58  
59          // Basic HTML tests
60          assertTrue(response.isHTML());
61          assertTrue(response.getContentLength() > 0);
62  
63          // Test the Page title
64          String expectedTitle =
65                  prepareTitle("dependency management project info", getString("report.dependency-management.title"));
66          assertEquals(expectedTitle, response.getTitle());
67  
68          // Test the tables
69          WebTable[] webTables = response.getTables();
70          assertEquals(webTables.length, 1);
71  
72          assertEquals(webTables[0].getColumnCount(), 5);
73          assertEquals(
74                  webTables[0].getRowCount(),
75                  1
76                          + getTestMavenProject()
77                                  .getDependencyManagement()
78                                  .getDependencies()
79                                  .size());
80  
81          // Test the texts
82          TextBlock[] textBlocks = response.getTextBlocks();
83          assertEquals(getString("report.dependency-management.title"), textBlocks[0].getText());
84          assertEquals("test", textBlocks[1].getText());
85      }
86  }