1 package org.apache.maven.continuum.utils;
2
3 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
4
5 import java.io.File;
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().validate(
62 "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().validate(
69 "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().validate(
88 "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().validate(
95 "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().validate(
102 "http://username:password@svn.apache.org/viewvc/continuum/trunk/pom.xml?revision=681492&content-type=text%2Fplain" ) );
103 }
104
105 public void testSuccessHttpsviewvc()
106 throws Exception
107 {
108 assertTrue( getContinuumUrlValidator().validate(
109 "https://svn.apache.org/viewvc/continuum/trunk/pom.xml?revision=681492&content-type=text%2Fplain" ) );
110 }
111
112 public void testSuccessHttpsviewvcWithAuth()
113 throws Exception
114 {
115 assertTrue( getContinuumUrlValidator().validate(
116 "https://username:password@svn.apache.org/viewvc/continuum/trunk/pom.xml?revision=681492&content-type=text%2Fplain" ) );
117 }
118
119 public void testSuccessHttpfisheye()
120 throws Exception
121 {
122 assertTrue( getContinuumUrlValidator().validate(
123 "http://fisheye6.atlassian.com/browse/~raw,r=680040/continuum/trunk/pom.xml" ) );
124 }
125
126 public void testSuccessHttpsfisheye()
127 throws Exception
128 {
129 assertTrue( getContinuumUrlValidator().validate(
130 "https://fisheye6.atlassian.com/browse/~raw,r=680040/continuum/trunk/pom.xml" ) );
131 }
132
133 public void testValidateFile()
134 throws Exception
135 {
136 File rootPom = getTestFile( "src/test/resources/META-INF/continuum/continuum-configuration.xml" );
137 assertTrue( rootPom.exists() );
138 assertTrue( getContinuumUrlValidator().validate( rootPom.toURL().toExternalForm() ) );
139 }
140
141
142 public void testExtractUserNamePwd()
143 throws Exception
144 {
145 ContinuumUrlValidator continuumUrlValidator = new ContinuumUrlValidator();
146 URLUserInfo usrInfo = continuumUrlValidator.extractURLUserInfo(
147 "https://username:password@svn.apache.org/repos/asf/continuum/trunk/pom.xml" );
148 assertEquals( "username", usrInfo.getUsername() );
149 assertEquals( "password", usrInfo.getPassword() );
150 }
151
152 public void testExtractUserNameEmptyPwd()
153 throws Exception
154 {
155 ContinuumUrlValidator continuumUrlValidator = new ContinuumUrlValidator();
156 URLUserInfo usrInfo = continuumUrlValidator.extractURLUserInfo(
157 "https://username@svn.apache.org/repos/asf/continuum/trunk/pom.xml" );
158 assertEquals( "username", usrInfo.getUsername() );
159 assertNull( usrInfo.getPassword() );
160 }
161
162 public void testExtractEmptyUserNameEmptyPwd()
163 throws Exception
164 {
165 ContinuumUrlValidator continuumUrlValidator = new ContinuumUrlValidator();
166 URLUserInfo usrInfo = continuumUrlValidator.extractURLUserInfo(
167 "https://svn.apache.org/repos/asf/continuum/trunk/pom.xml" );
168 assertNull( usrInfo.getUsername() );
169 assertNull( usrInfo.getPassword() );
170 }
171 }