View Javadoc

1   package org.apache.maven.archiva.model;
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 junit.framework.TestCase;
23  
24  /**
25   * RepositoryURLTest 
26   *
27   * @version $Id: RepositoryURLTest.java 718864 2008-11-19 06:33:35Z brett $
28   */
29  public class RepositoryURLTest
30      extends TestCase
31  {
32      private static final String NO_HOST = null;
33  
34      private static final String NO_PORT = null;
35  
36      private static final String NO_USER = null;
37  
38      private static final String NO_PASS = null;
39  
40      private void assertURL( String url, String expectedProtocol, String expectedHost, String expectedPort,
41                              String expectedPath, String expectedUsername, String expectedPassword )
42      {
43          RepositoryURL rurl = new RepositoryURL( url );
44          assertEquals( "Protocol", expectedProtocol, rurl.getProtocol() );
45          assertEquals( "Host", expectedHost, rurl.getHost() );
46          assertEquals( "Port", expectedPort, rurl.getPort() );
47          assertEquals( "Path", expectedPath, rurl.getPath() );
48          assertEquals( "Username", expectedUsername, rurl.getUsername() );
49          assertEquals( "Password", expectedPassword, rurl.getPassword() );
50      }
51  
52      public void testFileUrlNormal()
53      {
54          assertURL( "file:///home/joakim/code/test/this/", "file", NO_HOST, NO_PORT, "/home/joakim/code/test/this/",
55                     NO_USER, NO_PASS );
56      }
57  
58      public void testFileUrlShort()
59      {
60          assertURL( "file:/home/joakim/code/test/this/", "file", NO_HOST, NO_PORT, "/home/joakim/code/test/this/",
61                     NO_USER, NO_PASS );
62      }
63  
64      public void testHttpUrlPathless()
65      {
66          assertURL( "http://machine", "http", "machine", NO_PORT, "/", NO_USER, NO_PASS );
67      }
68  
69      public void testHttpUrlWithPort()
70      {
71          assertURL( "http://machine:8080/", "http", "machine", "8080", "/", NO_USER, NO_PASS );
72      }
73  
74      public void testHttpUrlWithUsernamePassword()
75      {
76          assertURL( "http://user:pass@machine/secured/", "http", "machine", NO_PORT, "/secured/", "user", "pass" );
77      }
78  
79      public void testHttpUrlWithUsernameNoPassword()
80      {
81          assertURL( "http://user@machine/secured/", "http", "machine", NO_PORT, "/secured/", "user", NO_PASS );
82      }
83  
84      public void testHttpUrlWithUsernamePasswordAndPort()
85      {
86          assertURL( "http://user:pass@machine:9090/secured/", "http", "machine", "9090", "/secured/", "user", "pass" );
87      }
88  
89      public void testBogusWithPath()
90      {
91          // This should not fail.  The intent of RepositoryURL is to have it support oddball protocols that
92          // are used by maven-scm and maven-wagon (unlike java.net.URL)
93          assertURL( "bogus://a.machine.name.com/path/to/resource/file.txt", "bogus", "a.machine.name.com", NO_PORT,
94                     "/path/to/resource/file.txt", NO_USER, NO_PASS );
95      }
96  }