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;
29 public class RepositoryURLTest
32 private static final String NO_HOST = null;
34 private static final String NO_PORT = null;
36 private static final String NO_USER = null;
38 private static final String NO_PASS = null;
40 private void assertURL( String url, String expectedProtocol, String expectedHost, String expectedPort,
41 String expectedPath, String expectedUsername, String expectedPassword )
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() );
52 public void testFileUrlNormal()
54 assertURL( "file:///home/joakim/code/test/this/", "file", NO_HOST, NO_PORT, "/home/joakim/code/test/this/",
58 public void testFileUrlShort()
60 assertURL( "file:/home/joakim/code/test/this/", "file", NO_HOST, NO_PORT, "/home/joakim/code/test/this/",
64 public void testHttpUrlPathless()
66 assertURL( "http://machine", "http", "machine", NO_PORT, "/", NO_USER, NO_PASS );
69 public void testHttpUrlWithPort()
71 assertURL( "http://machine:8080/", "http", "machine", "8080", "/", NO_USER, NO_PASS );
74 public void testHttpUrlWithUsernamePassword()
76 assertURL( "http://user:pass@machine/secured/", "http", "machine", NO_PORT, "/secured/", "user", "pass" );
79 public void testHttpUrlWithUsernameNoPassword()
81 assertURL( "http://user@machine/secured/", "http", "machine", NO_PORT, "/secured/", "user", NO_PASS );
84 public void testHttpUrlWithUsernamePasswordAndPort()
86 assertURL( "http://user:pass@machine:9090/secured/", "http", "machine", "9090", "/secured/", "user", "pass" );
89 public void testBogusWithPath()
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 );