View Javadoc

1   package org.apache.maven.continuum.utils;
2   
3   import org.codehaus.plexus.spring.PlexusInSpringTestCase;
4   
5   import java.io.File;
6   
7   /*
8    * Licensed to the Apache Software Foundation (ASF) under one
9    * or more contributor license agreements.  See the NOTICE file
10   * distributed with this work for additional information
11   * regarding copyright ownership.  The ASF licenses this file
12   * to you under the Apache License, Version 2.0 (the
13   * "License"); you may not use this file except in compliance
14   * with the License.  You may obtain a copy of the License at
15   *
16   *   http://www.apache.org/licenses/LICENSE-2.0
17   *
18   * Unless required by applicable law or agreed to in writing,
19   * software distributed under the License is distributed on an
20   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21   * KIND, either express or implied.  See the License for the
22   * specific language governing permissions and limitations
23   * under the License.
24   */
25  
26  /**
27   * @author <a href="mailto:olamy@apache.org">olamy</a>
28   * @version $Id: ContinuumUrlValidatorTest.java 1372260 2012-08-13 04:29:09Z brett $
29   */
30  public class ContinuumUrlValidatorTest
31      extends PlexusInSpringTestCase
32  {
33  
34      protected ContinuumUrlValidator getContinuumUrlValidator()
35          throws Exception
36      {
37          return getContinuumUrlValidator( "continuumUrl" );
38      }
39  
40      protected ContinuumUrlValidator getContinuumUrlValidator( String roleHint )
41          throws Exception
42      {
43          return (ContinuumUrlValidator) lookup( ContinuumUrlValidator.class, roleHint );
44      }
45  
46      public void testSuccessHttp()
47          throws Exception
48      {
49          assertTrue( getContinuumUrlValidator().validate( "http://svn.apache.org/repos/asf/continuum/trunk/pom.xml" ) );
50      }
51  
52      public void testFailureHttp()
53          throws Exception
54      {
55          assertFalse( getContinuumUrlValidator().validate( "ttp://svn.apache.org/repos/asf/continuum/trunk/pom.xml" ) );
56      }
57  
58      public void testSuccessHttpWithAuth()
59          throws Exception
60      {
61          assertTrue( getContinuumUrlValidator().validate(
62              "https://username:password@svn.apache.org/repos/asf/continuum/trunk/pom.xml" ) );
63      }
64  
65      public void testFailureHttpWithAuth()
66          throws Exception
67      {
68          assertTrue( getContinuumUrlValidator().validate(
69              "http://username:passwordsvn.apache.org/repos/asf/continuum/trunk/pom.xml" ) );
70      }
71  
72      public void testFailureHttpWithFile()
73          throws Exception
74      {
75          assertFalse( getContinuumUrlValidator( "continuumUrlWithoutFile" ).validate( "file:///home/zloug/pom.xml" ) );
76      }
77  
78      public void testSuccessHttps()
79          throws Exception
80      {
81          assertTrue( getContinuumUrlValidator().validate( "https://svn.apache.org/repos/asf/continuum/trunk/pom.xml" ) );
82      }
83  
84      public void testSuccessHttpsWithAuth()
85          throws Exception
86      {
87          assertTrue( getContinuumUrlValidator().validate(
88              "https://username:password@svn.apache.org/repos/asf/continuum/trunk/pom.xml" ) );
89      }
90  
91      public void testSuccessHttpviewvc()
92          throws Exception
93      {
94          assertTrue( getContinuumUrlValidator().validate(
95              "http://svn.apache.org/viewvc/continuum/trunk/pom.xml?revision=681492&content-type=text%2Fplain" ) );
96      }
97  
98      public void testSuccessHttpviewvcWithAuth()
99          throws Exception
100     {
101         assertTrue( getContinuumUrlValidator().validate(
102             "http://username:password@svn.apache.org/viewvc/continuum/trunk/pom.xml?revision=681492&content-type=text%2Fplain" ) );
103     }
104 
105     public void testSuccessHttpsviewvc()
106         throws Exception
107     {
108         assertTrue( getContinuumUrlValidator().validate(
109             "https://svn.apache.org/viewvc/continuum/trunk/pom.xml?revision=681492&content-type=text%2Fplain" ) );
110     }
111 
112     public void testSuccessHttpsviewvcWithAuth()
113         throws Exception
114     {
115         assertTrue( getContinuumUrlValidator().validate(
116             "https://username:password@svn.apache.org/viewvc/continuum/trunk/pom.xml?revision=681492&content-type=text%2Fplain" ) );
117     }
118 
119     public void testSuccessHttpfisheye()
120         throws Exception
121     {
122         assertTrue( getContinuumUrlValidator().validate(
123             "http://fisheye6.atlassian.com/browse/~raw,r=680040/continuum/trunk/pom.xml" ) );
124     }
125 
126     public void testSuccessHttpsfisheye()
127         throws Exception
128     {
129         assertTrue( getContinuumUrlValidator().validate(
130             "https://fisheye6.atlassian.com/browse/~raw,r=680040/continuum/trunk/pom.xml" ) );
131     }
132 
133     public void testValidateFile()
134         throws Exception
135     {
136         File rootPom = getTestFile( "src/test/resources/META-INF/continuum/continuum-configuration.xml" );
137         assertTrue( rootPom.exists() );
138         assertTrue( getContinuumUrlValidator().validate( rootPom.toURL().toExternalForm() ) );
139     }
140 
141 
142     public void testExtractUserNamePwd()
143         throws Exception
144     {
145         ContinuumUrlValidator continuumUrlValidator = new ContinuumUrlValidator();
146         URLUserInfo usrInfo = continuumUrlValidator.extractURLUserInfo(
147             "https://username:password@svn.apache.org/repos/asf/continuum/trunk/pom.xml" );
148         assertEquals( "username", usrInfo.getUsername() );
149         assertEquals( "password", usrInfo.getPassword() );
150     }
151 
152     public void testExtractUserNameEmptyPwd()
153         throws Exception
154     {
155         ContinuumUrlValidator continuumUrlValidator = new ContinuumUrlValidator();
156         URLUserInfo usrInfo = continuumUrlValidator.extractURLUserInfo(
157             "https://username@svn.apache.org/repos/asf/continuum/trunk/pom.xml" );
158         assertEquals( "username", usrInfo.getUsername() );
159         assertNull( usrInfo.getPassword() );
160     }
161 
162     public void testExtractEmptyUserNameEmptyPwd()
163         throws Exception
164     {
165         ContinuumUrlValidator continuumUrlValidator = new ContinuumUrlValidator();
166         URLUserInfo usrInfo = continuumUrlValidator.extractURLUserInfo(
167             "https://svn.apache.org/repos/asf/continuum/trunk/pom.xml" );
168         assertNull( usrInfo.getUsername() );
169         assertNull( usrInfo.getPassword() );
170     }
171 }