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;
28 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
37 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
38 public class RepositoryURLTest
41 private void assertURL( String actualURL, String protocol, String username, String password, String hostname,
42 String port, String path )
44 RepositoryURL url = new RepositoryURL( actualURL );
46 assertEquals( protocol, url.getProtocol() );
47 assertEquals( username, url.getUsername() );
48 assertEquals( password, url.getPassword() );
49 assertEquals( hostname, url.getHost() );
50 assertEquals( port, url.getPort() );
51 assertEquals( path, url.getPath() );
55 public void testProtocolHttp()
56 throws MalformedURLException
58 assertURL( "http://localhost/path/to/resource.txt", "http", null, null, "localhost", null,
59 "/path/to/resource.txt" );
63 public void testProtocolWagonWebdav()
64 throws MalformedURLException
66 assertURL( "dav:http://localhost/path/to/resource.txt", "dav:http", null, null, "localhost", null,
67 "/path/to/resource.txt" );
71 public void testProtocolHttpWithPort()
72 throws MalformedURLException
74 assertURL( "http://localhost:9090/path/to/resource.txt", "http", null, null, "localhost", "9090",
75 "/path/to/resource.txt" );
79 public void testProtocolHttpWithUsername()
80 throws MalformedURLException
82 assertURL( "http://user@localhost/path/to/resource.txt", "http", "user", null, "localhost", null,
83 "/path/to/resource.txt" );
87 public void testProtocolHttpWithUsernamePassword()
88 throws MalformedURLException
90 assertURL( "http://user:pass@localhost/path/to/resource.txt", "http", "user", "pass", "localhost", null,
91 "/path/to/resource.txt" );
95 public void testProtocolHttpWithUsernamePasswordPort()
96 throws MalformedURLException
98 assertURL( "http://user:pass@localhost:9090/path/to/resource.txt", "http", "user", "pass", "localhost", "9090",
99 "/path/to/resource.txt" );