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  
29  /**
30   * @author Edwin Punzalan
31   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
32   * @version $Id$
33   */
34  public class IndexReportTest extends AbstractProjectInfoTestCase {
35      /**
36       * WebConversation object
37       */
38      private static final WebConversation WEB_CONVERSATION = new WebConversation();
39  
40      /**
41       * Test report
42       *
43       * @throws Exception if any
44       */
45      public void testReport() throws Exception {
46          generateReport("index", "index-plugin-config.xml");
47          assertTrue("Test html generated", getGeneratedReport("index.html").exists());
48  
49          URL reportURL = getGeneratedReport("index.html").toURI().toURL();
50          assertNotNull(reportURL);
51  
52          // HTTPUnit
53          WebRequest request = new GetMethodWebRequest(reportURL.toString());
54          WebResponse response = WEB_CONVERSATION.getResponse(request);
55  
56          // Basic HTML tests
57          assertTrue(response.isHTML());
58          assertTrue(response.getContentLength() > 0);
59  
60          // Test the Page title
61          // Index does not have a 'name' but 'title' only
62          String expectedTitle = prepareTitle("index project info", getString("report.index.title"));
63          assertEquals(expectedTitle, response.getTitle());
64  
65          // Test the texts
66          TextBlock[] textBlocks = response.getTextBlocks();
67          assertEquals(
68                  getString("report.index.title") + " " + getTestMavenProject().getName(), textBlocks[0].getText());
69          assertEquals(getString("report.index.nodescription"), textBlocks[1].getText());
70      }
71  }