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