1 package org.apache.archiva.model;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import junit.framework.TestCase;
23 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
32 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
33 public class RepositoryURLTest
36 private static final String NO_HOST = null;
38 private static final String NO_PORT = null;
40 private static final String NO_USER = null;
42 private static final String NO_PASS = null;
44 private void assertURL( String url, String expectedProtocol, String expectedHost, String expectedPort,
45 String expectedPath, String expectedUsername, String expectedPassword )
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() );
57 public void testFileUrlNormal()
59 assertURL( "file:///home/joakim/code/test/this/", "file", NO_HOST, NO_PORT, "/home/joakim/code/test/this/",
64 public void testFileUrlShort()
66 assertURL( "file:/home/joakim/code/test/this/", "file", NO_HOST, NO_PORT, "/home/joakim/code/test/this/",
71 public void testHttpUrlPathless()
73 assertURL( "http://machine", "http", "machine", NO_PORT, "/", NO_USER, NO_PASS );
77 public void testHttpUrlWithPort()
79 assertURL( "http://machine:8080/", "http", "machine", "8080", "/", NO_USER, NO_PASS );
83 public void testHttpUrlWithUsernamePassword()
85 assertURL( "http://user:pass@machine/secured/", "http", "machine", NO_PORT, "/secured/", "user", "pass" );
89 public void testHttpUrlWithUsernameNoPassword()
91 assertURL( "http://user@machine/secured/", "http", "machine", NO_PORT, "/secured/", "user", NO_PASS );
95 public void testHttpUrlWithUsernamePasswordAndPort()
97 assertURL( "http://user:pass@machine:9090/secured/", "http", "machine", "9090", "/secured/", "user", "pass" );
101 public void testBogusWithPath()
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 );