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(getGoal(), "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          // Last one is footer noise
69          assertEquals(8, textBlocks.length - 1);
70          assertEquals(getString("report.scm.overview.title"), textBlocks[1].getText());
71          assertEquals(getString("report.scm.general.intro"), textBlocks[2].getText());
72          assertEquals(getString("report.scm.webaccess.title"), textBlocks[3].getText());
73          assertEquals(getString("report.scm.webaccess.nourl"), textBlocks[4].getText());
74          assertEquals(getString("report.scm.accessbehindfirewall.title"), textBlocks[5].getText());
75          assertEquals(getString("report.scm.accessbehindfirewall.general.intro"), textBlocks[6].getText());
76      }
77  
78      /**
79       * Test report with wrong URL
80       *
81       * @throws Exception if any
82       */
83      public void testReportWithWrongUrl() throws Exception {
84          File pluginXmlFile =
85                  new File(getBasedir(), "src/test/resources/plugin-configs/" + "scm-wrong-url-plugin-config.xml");
86          Mojo mojo = createReportMojo(getGoal(), pluginXmlFile);
87  
88          setVariableValueToObject(mojo, "anonymousConnection", "scm:svn");
89          try {
90              mojo.execute();
91              fail("IllegalArgumentException NOT catched");
92          } catch (IllegalArgumentException e) {
93              assertTrue("IllegalArgumentException catched", true);
94          }
95  
96          tearDown();
97          setUp();
98  
99          mojo = lookupMojo("scm", pluginXmlFile);
100         assertNotNull("Mojo not found.", mojo);
101         setVariableValueToObject(mojo, "anonymousConnection", "scm:svn:http");
102         try {
103             mojo.execute();
104             fail("IllegalArgumentException NOT catched");
105         } catch (Exception e) {
106             assertTrue("IllegalArgumentException catched", true);
107         }
108 
109         tearDown();
110         setUp();
111 
112         mojo = lookupMojo("scm", pluginXmlFile);
113         assertNotNull("Mojo not found.", mojo);
114         setVariableValueToObject(mojo, "anonymousConnection", "scm");
115         try {
116             mojo.execute();
117             fail("IllegalArgumentException NOT catched");
118         } catch (Exception e) {
119             assertTrue("IllegalArgumentException catched", true);
120         }
121     }
122 
123     @Override
124     protected String getGoal() {
125         return "scm";
126     }
127 }