1 package org.apache.archiva.repository;
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
23 import org.apache.archiva.model.RepositoryURL;
25 import java.net.MalformedURLException;
27 import junit.framework.TestCase;
34 public class RepositoryURLTest
37 private void assertURL( String actualURL, String protocol, String username, String password, String hostname,
38 String port, String path )
40 RepositoryURL url = new RepositoryURL( actualURL );
42 assertEquals( protocol, url.getProtocol() );
43 assertEquals( username, url.getUsername() );
44 assertEquals( password, url.getPassword() );
45 assertEquals( hostname, url.getHost() );
46 assertEquals( port, url.getPort() );
47 assertEquals( path, url.getPath() );
50 public void testProtocolHttp()
51 throws MalformedURLException
53 assertURL( "http://localhost/path/to/resource.txt", "http", null, null, "localhost", null,
54 "/path/to/resource.txt" );
57 public void testProtocolWagonWebdav()
58 throws MalformedURLException
60 assertURL( "dav:http://localhost/path/to/resource.txt", "dav:http", null, null, "localhost", null,
61 "/path/to/resource.txt" );
64 public void testProtocolHttpWithPort()
65 throws MalformedURLException
67 assertURL( "http://localhost:9090/path/to/resource.txt", "http", null, null, "localhost", "9090",
68 "/path/to/resource.txt" );
71 public void testProtocolHttpWithUsername()
72 throws MalformedURLException
74 assertURL( "http://user@localhost/path/to/resource.txt", "http", "user", null, "localhost", null,
75 "/path/to/resource.txt" );
78 public void testProtocolHttpWithUsernamePassword()
79 throws MalformedURLException
81 assertURL( "http://user:pass@localhost/path/to/resource.txt", "http", "user", "pass", "localhost", null,
82 "/path/to/resource.txt" );
85 public void testProtocolHttpWithUsernamePasswordPort()
86 throws MalformedURLException
88 assertURL( "http://user:pass@localhost:9090/path/to/resource.txt", "http", "user", "pass", "localhost", "9090",
89 "/path/to/resource.txt" );