1 package org.apache.maven.continuum.utils;
2
3 import java.io.File;
4
5 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 public class ContinuumUrlValidatorTest
31 extends PlexusInSpringTestCase
32 {
33
34 protected ContinuumUrlValidator getContinuumUrlValidator()
35 throws Exception
36 {
37 return getContinuumUrlValidator( "continuumUrl" );
38 }
39
40 protected ContinuumUrlValidator getContinuumUrlValidator( String roleHint )
41 throws Exception
42 {
43 return (ContinuumUrlValidator) lookup( ContinuumUrlValidator.class, roleHint );
44 }
45
46 public void testSuccessHttp()
47 throws Exception
48 {
49 assertTrue( getContinuumUrlValidator().validate( "http://svn.apache.org/repos/asf/continuum/trunk/pom.xml" ) );
50 }
51
52 public void testFailureHttp()
53 throws Exception
54 {
55 assertFalse( getContinuumUrlValidator().validate( "ttp://svn.apache.org/repos/asf/continuum/trunk/pom.xml" ) );
56 }
57
58 public void testSuccessHttpWithAuth()
59 throws Exception
60 {
61 assertTrue( getContinuumUrlValidator()
62 .validate( "https://username:password@svn.apache.org/repos/asf/continuum/trunk/pom.xml" ) );
63 }
64
65 public void testFailureHttpWithAuth()
66 throws Exception
67 {
68 assertTrue( getContinuumUrlValidator()
69 .validate( "http://username:passwordsvn.apache.org/repos/asf/continuum/trunk/pom.xml" ) );
70 }
71
72 public void testFailureHttpWithFile()
73 throws Exception
74 {
75 assertFalse( getContinuumUrlValidator( "continuumUrlWithoutFile" ).validate( "file:///home/zloug/pom.xml" ) );
76 }
77
78 public void testSuccessHttps()
79 throws Exception
80 {
81 assertTrue( getContinuumUrlValidator().validate( "https://svn.apache.org/repos/asf/continuum/trunk/pom.xml" ) );
82 }
83
84 public void testSuccessHttpsWithAuth()
85 throws Exception
86 {
87 assertTrue( getContinuumUrlValidator()
88 .validate( "https://username:password@svn.apache.org/repos/asf/continuum/trunk/pom.xml" ) );
89 }
90
91 public void testSuccessHttpviewvc()
92 throws Exception
93 {
94 assertTrue( getContinuumUrlValidator()
95 .validate( "http://svn.apache.org/viewvc/continuum/trunk/pom.xml?revision=681492&content-type=text%2Fplain" ) );
96 }
97
98 public void testSuccessHttpviewvcWithAuth()
99 throws Exception
100 {
101 assertTrue( getContinuumUrlValidator()
102 .validate(
103 "http://username:password@svn.apache.org/viewvc/continuum/trunk/pom.xml?revision=681492&content-type=text%2Fplain" ) );
104 }
105
106 public void testSuccessHttpsviewvc()
107 throws Exception
108 {
109 assertTrue( getContinuumUrlValidator()
110 .validate(
111 "https://svn.apache.org/viewvc/continuum/trunk/pom.xml?revision=681492&content-type=text%2Fplain" ) );
112 }
113
114 public void testSuccessHttpsviewvcWithAuth()
115 throws Exception
116 {
117 assertTrue( getContinuumUrlValidator()
118 .validate(
119 "https://username:password@svn.apache.org/viewvc/continuum/trunk/pom.xml?revision=681492&content-type=text%2Fplain" ) );
120 }
121
122 public void testSuccessHttpfisheye()
123 throws Exception
124 {
125 assertTrue( getContinuumUrlValidator()
126 .validate( "http://fisheye6.atlassian.com/browse/~raw,r=680040/continuum/trunk/pom.xml" ) );
127 }
128
129 public void testSuccessHttpsfisheye()
130 throws Exception
131 {
132 assertTrue( getContinuumUrlValidator()
133 .validate( "https://fisheye6.atlassian.com/browse/~raw,r=680040/continuum/trunk/pom.xml" ) );
134 }
135
136 public void testValidateFile()
137 throws Exception
138 {
139 File rootPom = getTestFile( "src/test/resources/META-INF/continuum/continuum-configuration.xml" );
140 assertTrue( rootPom.exists() );
141 assertTrue( getContinuumUrlValidator().validate( rootPom.toURL().toExternalForm() ) );
142 }
143
144
145 public void testExtractUserNamePwd()
146 throws Exception
147 {
148 ContinuumUrlValidator continuumUrlValidator = new ContinuumUrlValidator();
149 URLUserInfo usrInfo = continuumUrlValidator
150 .extractURLUserInfo( "https://username:password@svn.apache.org/repos/asf/continuum/trunk/pom.xml" );
151 assertEquals( "username", usrInfo.getUsername() );
152 assertEquals( "password", usrInfo.getPassword() );
153 }
154
155 public void testExtractUserNameEmptyPwd()
156 throws Exception
157 {
158 ContinuumUrlValidator continuumUrlValidator = new ContinuumUrlValidator();
159 URLUserInfo usrInfo = continuumUrlValidator
160 .extractURLUserInfo( "https://username@svn.apache.org/repos/asf/continuum/trunk/pom.xml" );
161 assertEquals( "username", usrInfo.getUsername() );
162 assertNull( usrInfo.getPassword() );
163 }
164
165 public void testExtractEmptyUserNameEmptyPwd()
166 throws Exception
167 {
168 ContinuumUrlValidator continuumUrlValidator = new ContinuumUrlValidator();
169 URLUserInfo usrInfo = continuumUrlValidator
170 .extractURLUserInfo( "https://svn.apache.org/repos/asf/continuum/trunk/pom.xml" );
171 assertNull( usrInfo.getUsername() );
172 assertNull( usrInfo.getPassword() );
173 }
174 }