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 org.w3c.dom.html.HTMLAnchorElement;
29  
30  /**
31   * @author Edwin Punzalan
32   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
33   * @version $Id$
34   */
35  public class CiManagementReportTest 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("ci-management", "ci-management-plugin-config.xml");
48          assertTrue(
49                  "Test html generated", getGeneratedReport("ci-management.html").exists());
50  
51          URL reportURL = getGeneratedReport("ci-management.html").toURI().toURL();
52          assertNotNull(reportURL);
53  
54          // HTTPUnit
55          WebRequest request = new GetMethodWebRequest(reportURL.toString());
56          WebResponse response = WEB_CONVERSATION.getResponse(request);
57  
58          // Basic HTML tests
59          assertTrue(response.isHTML());
60          assertTrue(response.getContentLength() > 0);
61  
62          // Test the Page title
63          String expectedTitle = prepareTitle("ci mangement project info", getString("report.ci-management.title"));
64          assertEquals(expectedTitle, response.getTitle());
65  
66          // Test the texts
67          TextBlock[] textBlocks = response.getTextBlocks();
68          assertEquals(getString("report.ci-management.name"), textBlocks[0].getText());
69          assertEquals(getString("report.ci-management.nocim"), textBlocks[1].getText());
70      }
71  
72      /**
73       * When a ciManagement section is present, test that the correct name and link text are chosen
74       * from the 'system' property.
75       *
76       * @throws Exception if any
77       */
78      public void testCiNameReport() throws Exception {
79          generateReport("ci-management", "ci-management-plugin-with-ci-section-config.xml");
80          assertTrue(
81                  "Test html generated", getGeneratedReport("ci-management.html").exists());
82  
83          URL reportURL = getGeneratedReport("ci-management.html").toURI().toURL();
84          assertNotNull(reportURL);
85  
86          // HTTPUnit
87          WebRequest request = new GetMethodWebRequest(reportURL.toString());
88          WebResponse response = WEB_CONVERSATION.getResponse(request);
89  
90          // Basic HTML tests
91          assertTrue(response.isHTML());
92          assertTrue(response.getContentLength() > 0);
93  
94          // Test the texts
95          TextBlock[] textBlocks = response.getTextBlocks();
96          assertTrue(textBlocks[1].getText().startsWith("This project uses "));
97          assertEquals(3, textBlocks[1].getNode().getChildNodes().getLength());
98          HTMLAnchorElement anchor =
99                  (HTMLAnchorElement) textBlocks[1].getNode().getChildNodes().item(1);
100         assertEquals("https://www.jetbrains.com/teamcity/", anchor.getAttribute("href"));
101         assertEquals("TeamCity", anchor.getFirstChild().getNodeValue());
102     }
103 }