1 package org.apache.maven.archiva.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24
25
26
27
28
29 public class RepositoryURLTest
30 extends TestCase
31 {
32 private static final String NO_HOST = null;
33
34 private static final String NO_PORT = null;
35
36 private static final String NO_USER = null;
37
38 private static final String NO_PASS = null;
39
40 private void assertURL( String url, String expectedProtocol, String expectedHost, String expectedPort,
41 String expectedPath, String expectedUsername, String expectedPassword )
42 {
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() );
50 }
51
52 public void testFileUrlNormal()
53 {
54 assertURL( "file:///home/joakim/code/test/this/", "file", NO_HOST, NO_PORT, "/home/joakim/code/test/this/",
55 NO_USER, NO_PASS );
56 }
57
58 public void testFileUrlShort()
59 {
60 assertURL( "file:/home/joakim/code/test/this/", "file", NO_HOST, NO_PORT, "/home/joakim/code/test/this/",
61 NO_USER, NO_PASS );
62 }
63
64 public void testHttpUrlPathless()
65 {
66 assertURL( "http://machine", "http", "machine", NO_PORT, "/", NO_USER, NO_PASS );
67 }
68
69 public void testHttpUrlWithPort()
70 {
71 assertURL( "http://machine:8080/", "http", "machine", "8080", "/", NO_USER, NO_PASS );
72 }
73
74 public void testHttpUrlWithUsernamePassword()
75 {
76 assertURL( "http://user:pass@machine/secured/", "http", "machine", NO_PORT, "/secured/", "user", "pass" );
77 }
78
79 public void testHttpUrlWithUsernameNoPassword()
80 {
81 assertURL( "http://user@machine/secured/", "http", "machine", NO_PORT, "/secured/", "user", NO_PASS );
82 }
83
84 public void testHttpUrlWithUsernamePasswordAndPort()
85 {
86 assertURL( "http://user:pass@machine:9090/secured/", "http", "machine", "9090", "/secured/", "user", "pass" );
87 }
88
89 public void testBogusWithPath()
90 {
91
92
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 );
95 }
96 }