1 package org.apache.archiva.repository.maven;
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
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
22 import junit.framework.TestCase;
23 import org.apache.archiva.model.RepositoryURL;
24 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
28 import java.net.MalformedURLException;
35 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
36 public class RepositoryURLTest
39 private void assertURL( String actualURL, String protocol, String username, String password, String hostname,
40 String port, String path )
42 RepositoryURL url = new RepositoryURL( actualURL );
44 assertEquals( protocol, url.getProtocol() );
45 assertEquals( username, url.getUsername() );
46 assertEquals( password, url.getPassword() );
47 assertEquals( hostname, url.getHost() );
48 assertEquals( port, url.getPort() );
49 assertEquals( path, url.getPath() );
53 public void testProtocolHttp()
54 throws MalformedURLException
56 assertURL( "http://localhost/path/to/resource.txt", "http", null, null, "localhost", null,
57 "/path/to/resource.txt" );
61 public void testProtocolWagonWebdav()
62 throws MalformedURLException
64 assertURL( "dav:http://localhost/path/to/resource.txt", "dav:http", null, null, "localhost", null,
65 "/path/to/resource.txt" );
69 public void testProtocolHttpWithPort()
70 throws MalformedURLException
72 assertURL( "http://localhost:9090/path/to/resource.txt", "http", null, null, "localhost", "9090",
73 "/path/to/resource.txt" );
77 public void testProtocolHttpWithUsername()
78 throws MalformedURLException
80 assertURL( "http://user@localhost/path/to/resource.txt", "http", "user", null, "localhost", null,
81 "/path/to/resource.txt" );
85 public void testProtocolHttpWithUsernamePassword()
86 throws MalformedURLException
88 assertURL( "http://user:pass@localhost/path/to/resource.txt", "http", "user", "pass", "localhost", null,
89 "/path/to/resource.txt" );
93 public void testProtocolHttpWithUsernamePasswordPort()
94 throws MalformedURLException
96 assertURL( "http://user:pass@localhost:9090/path/to/resource.txt", "http", "user", "pass", "localhost", "9090",
97 "/path/to/resource.txt" );