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.WebLink;
27  import com.meterware.httpunit.WebRequest;
28  import com.meterware.httpunit.WebResponse;
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 LicensesReportTest 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("licenses", "licenses-plugin-config.xml");
48          assertTrue("Test html generated", getGeneratedReport("licenses.html").exists());
49  
50          URL reportURL = getGeneratedReport("licenses.html").toURI().toURL();
51          assertNotNull(reportURL);
52  
53          // HTTPUnit
54          WebRequest request = new GetMethodWebRequest(reportURL.toString());
55          WebResponse response = WEB_CONVERSATION.getResponse(request);
56  
57          // Basic HTML tests
58          assertTrue(response.isHTML());
59          assertTrue(response.getContentLength() > 0);
60  
61          // Test the Page title
62          String expectedTitle = prepareTitle("licenses project info", getString("report.licenses.title"));
63          assertEquals(expectedTitle, response.getTitle());
64  
65          // Test the texts
66          TextBlock[] textBlocks = response.getTextBlocks();
67          assertEquals(getString("report.licenses.overview.title"), textBlocks[0].getText());
68          assertEquals(getString("report.licenses.overview.intro"), textBlocks[1].getText());
69          assertEquals(getString("report.licenses.title"), textBlocks[2].getText());
70          assertEquals("The Apache Software License, Version 2.0", textBlocks[3].getText());
71  
72          // only 1 link in default report
73          final WebLink[] links = response.getLinks();
74          assertEquals(1, links.length);
75          assertEquals("http://maven.apache.org/", links[0].getURLString());
76      }
77  
78      public void testReportLinksOnly() throws Exception {
79          generateReport("licenses", "licenses-plugin-config-linkonly.xml");
80          assertTrue("Test html generated", getGeneratedReport("licenses.html").exists());
81  
82          URL reportURL = getGeneratedReport("licenses.html").toURI().toURL();
83          assertNotNull(reportURL);
84  
85          // HTTPUnit
86          WebRequest request = new GetMethodWebRequest(reportURL.toString());
87          WebResponse response = WEB_CONVERSATION.getResponse(request);
88  
89          // Basic HTML tests
90          assertTrue(response.isHTML());
91          assertTrue(response.getContentLength() > 0);
92  
93          // Test the Page title
94          String expectedTitle = prepareTitle("licenses project info", getString("report.licenses.title"));
95          assertEquals(expectedTitle, response.getTitle());
96  
97          // Test the texts
98          TextBlock[] textBlocks = response.getTextBlocks();
99          assertEquals(getString("report.licenses.overview.title"), textBlocks[0].getText());
100         assertEquals(getString("report.licenses.overview.intro"), textBlocks[1].getText());
101         assertEquals(getString("report.licenses.title"), textBlocks[2].getText());
102         assertEquals("The Apache Software License, Version 2.0", textBlocks[3].getText());
103 
104         // here's our specific test
105         final WebLink[] links = response.getLinks();
106         assertEquals(2, links.length);
107         assertEquals("http://maven.apache.org/", links[0].getURLString());
108         assertEquals("https://www.apache.org/licenses/LICENSE-2.0.txt", links[1].getURLString());
109         assertEquals("https://www.apache.org/licenses/LICENSE-2.0.txt", links[1].getText());
110     }
111 }