View Javadoc

1   package org.apache.maven.report.projectinfo;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.net.URL;
24  
25  import org.apache.maven.plugin.Mojo;
26  
27  import com.meterware.httpunit.GetMethodWebRequest;
28  import com.meterware.httpunit.TextBlock;
29  import com.meterware.httpunit.WebConversation;
30  import com.meterware.httpunit.WebRequest;
31  import com.meterware.httpunit.WebResponse;
32  
33  /**
34   * @author Edwin Punzalan
35   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
36   * @version $Id: ScmReportTest.java 1100761 2011-05-08 16:14:18Z hboutemy $
37   */
38  public class ScmReportTest
39      extends AbstractProjectInfoTestCase
40  {
41      /**
42       * WebConversation object
43       */
44      private static final WebConversation WEB_CONVERSATION = new WebConversation();
45  
46      /**
47       * Test report
48       *
49       * @throws Exception if any
50       */
51      public void testReport()
52          throws Exception
53      {
54          generateReport( "scm", "scm-plugin-config.xml" );
55          assertTrue( "Test html generated", getGeneratedReport( "source-repository.html" ).exists() );
56  
57          URL reportURL = getGeneratedReport( "source-repository.html" ).toURI().toURL();
58          assertNotNull( reportURL );
59  
60          // HTTPUnit
61          WebRequest request = new GetMethodWebRequest( reportURL.toString() );
62          WebResponse response = WEB_CONVERSATION.getResponse( request );
63  
64          // Basic HTML tests
65          assertTrue( response.isHTML() );
66          assertTrue( response.getContentLength() > 0 );
67  
68          // Test the Page title
69          assertEquals( getString( "report.scm.title" ), response.getTitle() );
70  
71          // Test the texts
72          TextBlock[] textBlocks = response.getTextBlocks();
73  
74          assertEquals( textBlocks.length, 6 );
75  
76          assertEquals( getString( "report.scm.overview.title" ), textBlocks[0].getText() );
77          assertEquals( getString( "report.scm.general.intro" ), textBlocks[1].getText() );
78          assertEquals( getString( "report.scm.webaccess.title" ), textBlocks[2].getText() );
79          assertEquals( getString( "report.scm.webaccess.nourl" ), textBlocks[3].getText() );
80          assertEquals( getString( "report.scm.accessbehindfirewall.title" ), textBlocks[4].getText() );
81          assertEquals( getString( "report.scm.accessbehindfirewall.general.intro" ), textBlocks[5].getText() );
82      }
83  
84      /**
85       * Test report with wrong URL
86       *
87       * @throws Exception if any
88       */
89      public void testReportWithWrongUrl()
90          throws Exception
91      {
92          File pluginXmlFile = new File( getBasedir(), "src/test/resources/plugin-configs/"
93                  + "scm-wrong-url-plugin-config.xml" );
94          Mojo mojo = lookupMojo( "scm", pluginXmlFile );
95          assertNotNull( "Mojo found.", mojo );
96  
97          setVariableValueToObject( mojo, "anonymousConnection", "scm:svn" );
98          try
99          {
100             mojo.execute();
101             assertTrue( "IllegalArgumentException NOT catched", false );
102         }
103         catch ( IllegalArgumentException e )
104         {
105             assertTrue( "IllegalArgumentException catched", true );
106         }
107 
108         tearDown();
109         setUp();
110 
111         mojo = lookupMojo( "scm", pluginXmlFile );
112         assertNotNull( "Mojo found.", mojo );
113         setVariableValueToObject( mojo, "anonymousConnection", "scm:svn:http" );
114         try
115         {
116             mojo.execute();
117             assertTrue( "IllegalArgumentException NOT catched", false );
118         }
119         catch ( Exception e )
120         {
121             assertTrue( "IllegalArgumentException catched", true );
122         }
123 
124         tearDown();
125         setUp();
126 
127         mojo = lookupMojo( "scm", pluginXmlFile );
128         assertNotNull( "Mojo found.", mojo );
129         setVariableValueToObject( mojo, "anonymousConnection", "scm" );
130         try
131         {
132             mojo.execute();
133             assertTrue( "IllegalArgumentException NOT catched", false );
134         }
135         catch ( Exception e )
136         {
137             assertTrue( "IllegalArgumentException catched", true );
138         }
139     }
140 }