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.TextBlock;
26  import com.meterware.httpunit.WebConversation;
27  import com.meterware.httpunit.WebRequest;
28  import com.meterware.httpunit.WebResponse;
29  import org.apache.maven.plugin.Mojo;
30  
31  /**
32   * @author Edwin Punzalan
33   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
34   * @version $Id$
35   */
36  public class ScmReportTest extends AbstractProjectInfoTestCase {
37      /**
38       * WebConversation object
39       */
40      private static final WebConversation WEB_CONVERSATION = new WebConversation();
41  
42      /**
43       * Test report
44       *
45       * @throws Exception if any
46       */
47      public void testReport() throws Exception {
48          generateReport("scm", "scm-plugin-config.xml");
49          assertTrue("Test html generated", getGeneratedReport("scm.html").exists());
50  
51          URL reportURL = getGeneratedReport("scm.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("scm project info", getString("report.scm.title"));
64          assertEquals(expectedTitle, response.getTitle());
65  
66          // Test the texts
67          TextBlock[] textBlocks = response.getTextBlocks();
68          assertEquals(6, textBlocks.length);
69          assertEquals(getString("report.scm.overview.title"), textBlocks[0].getText());
70          assertEquals(getString("report.scm.general.intro"), textBlocks[1].getText());
71          assertEquals(getString("report.scm.webaccess.title"), textBlocks[2].getText());
72          assertEquals(getString("report.scm.webaccess.nourl"), textBlocks[3].getText());
73          assertEquals(getString("report.scm.accessbehindfirewall.title"), textBlocks[4].getText());
74          assertEquals(getString("report.scm.accessbehindfirewall.general.intro"), textBlocks[5].getText());
75      }
76  
77      /**
78       * Test report with wrong URL
79       *
80       * @throws Exception if any
81       */
82      public void testReportWithWrongUrl() throws Exception {
83          File pluginXmlFile =
84                  new File(getBasedir(), "src/test/resources/plugin-configs/" + "scm-wrong-url-plugin-config.xml");
85          Mojo mojo = createReportMojo("scm", pluginXmlFile);
86  
87          setVariableValueToObject(mojo, "anonymousConnection", "scm:svn");
88          try {
89              mojo.execute();
90              fail("IllegalArgumentException NOT catched");
91          } catch (IllegalArgumentException e) {
92              assertTrue("IllegalArgumentException catched", true);
93          }
94  
95          tearDown();
96          setUp();
97  
98          mojo = lookupMojo("scm", pluginXmlFile);
99          assertNotNull("Mojo not found.", mojo);
100         setVariableValueToObject(mojo, "anonymousConnection", "scm:svn:http");
101         try {
102             mojo.execute();
103             fail("IllegalArgumentException NOT catched");
104         } catch (Exception e) {
105             assertTrue("IllegalArgumentException catched", true);
106         }
107 
108         tearDown();
109         setUp();
110 
111         mojo = lookupMojo("scm", pluginXmlFile);
112         assertNotNull("Mojo not found.", mojo);
113         setVariableValueToObject(mojo, "anonymousConnection", "scm");
114         try {
115             mojo.execute();
116             fail("IllegalArgumentException NOT catched");
117         } catch (Exception e) {
118             assertTrue("IllegalArgumentException catched", true);
119         }
120     }
121 }