001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm.provider.svn.repository; 020 021import org.apache.maven.scm.ScmTestCase; 022import org.apache.maven.scm.manager.ScmManager; 023import org.apache.maven.scm.repository.ScmRepository; 024import org.apache.maven.scm.repository.ScmRepositoryException; 025import org.junit.Before; 026import org.junit.Test; 027 028import static org.junit.Assert.assertEquals; 029import static org.junit.Assert.assertNotNull; 030import static org.junit.Assert.assertTrue; 031import static org.junit.Assert.fail; 032 033/** 034 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 035 * 036 */ 037public class SvnScmProviderRepositoryTest extends ScmTestCase { 038 private ScmManager scmManager; 039 040 @Before 041 @Override 042 public void setUp() throws Exception { 043 super.setUp(); 044 045 scmManager = getScmManager(); 046 } 047 048 // ---------------------------------------------------------------------- 049 // Testing legal URLs 050 // ---------------------------------------------------------------------- 051 052 @Test 053 public void testLegalFileURL() throws Exception { 054 testUrl("scm:svn:file:///tmp/repo", "file:///tmp/repo", null, null, null); 055 } 056 057 @Test 058 public void testLegalLocalhostFileURL() throws Exception { 059 testUrl("scm:svn:file://localhost/tmp/repo", "file://localhost/tmp/repo", null, null, null); 060 } 061 062 @Test 063 public void testLegalHistnameFileURL() throws Exception { 064 testUrl("scm:svn:file://my_server/tmp/repo", "file://my_server/tmp/repo", null, null, null); 065 } 066 067 @Test 068 public void testLegalHttpURL() throws Exception { 069 testUrl( 070 "scm:svn:http://subversion.tigris.org", 071 "http://subversion.tigris.org", 072 null, 073 null, 074 "subversion.tigris.org"); 075 } 076 077 @Test 078 public void testLegalHttpURLWithUser() throws Exception { 079 testUrl( 080 "scm:svn:http://user@subversion.tigris.org", 081 "http://subversion.tigris.org", 082 "user", 083 null, 084 "subversion.tigris.org"); 085 } 086 087 @Test 088 public void testLegalHttpURLWithUserPassword() throws Exception { 089 testUrl( 090 "scm:svn:http://user:password@subversion.tigris.org", 091 "http://subversion.tigris.org", 092 "user", 093 "password", 094 "subversion.tigris.org"); 095 } 096 097 @Test 098 public void testLegalHttpsURL() throws Exception { 099 testUrl( 100 "scm:svn:https://subversion.tigris.org", 101 "https://subversion.tigris.org", 102 null, 103 null, 104 "subversion.tigris.org"); 105 } 106 107 @Test 108 public void testLegalHttpsURLWithUser() throws Exception { 109 testUrl( 110 "scm:svn:https://user@subversion.tigris.org", 111 "https://subversion.tigris.org", 112 "user", 113 null, 114 "subversion.tigris.org"); 115 } 116 117 @Test 118 public void testLegalHttpsURLWithUserPassword() throws Exception { 119 testUrl( 120 "scm:svn:https://user:password@subversion.tigris.org", 121 "https://subversion.tigris.org", 122 "user", 123 "password", 124 "subversion.tigris.org"); 125 } 126 127 @Test 128 public void testLegalSvnURL() throws Exception { 129 testUrl( 130 "scm:svn:svn://subversion.tigris.org", 131 "svn://subversion.tigris.org", 132 null, 133 null, 134 "subversion.tigris.org"); 135 } 136 137 @Test 138 public void testLegalSvnPlusUsernameURL() throws Exception { 139 testUrl( 140 "scm:svn:svn://username@subversion.tigris.org", 141 "svn://subversion.tigris.org", 142 "username", 143 null, 144 "subversion.tigris.org"); 145 } 146 147 @Test 148 public void testLegalSvnPlusUsernamePasswordURL() throws Exception { 149 testUrl( 150 "scm:svn:svn://username:password@subversion.tigris.org", 151 "svn://subversion.tigris.org", 152 "username", 153 "password", 154 "subversion.tigris.org"); 155 } 156 157 @Test 158 public void testLegalSvnPlusSshURL() throws Exception { 159 testUrl( 160 "scm:svn:svn+ssh://subversion.tigris.org", 161 "svn+ssh://subversion.tigris.org", 162 null, 163 null, 164 "subversion.tigris.org"); 165 } 166 167 /* This test require a specific subversion config file 168 public void testLegalSvnPlusXxxURL() 169 throws Exception 170 { 171 testUrl( "scm:svn:svn+something://subversion.tigris.org", "svn+something://subversion.tigris.org", null, 172 "subversion.tigris.org" ); 173 }*/ 174 175 @Test 176 public void testLegalSvnPlusSshPlusUsernameURL() throws Exception { 177 testUrl( 178 "scm:svn:svn+ssh://username@subversion.tigris.org", 179 "svn+ssh://username@subversion.tigris.org", 180 null, 181 null, 182 "username@subversion.tigris.org"); 183 } 184 185 /* This test require a specific subversion config file 186 public void testLegalSvnPlusXxxPlusUsernameURL() 187 throws Exception 188 { 189 testUrl( "scm:svn:svn+something://username@subversion.tigris.org", "svn+something://username@subversion.tigris.org", null, 190 "username@subversion.tigris.org" ); 191 }*/ 192 193 @Test 194 public void testLegalSvnPortUrl() throws Exception { 195 testUrl( 196 "scm:svn:http://username@subversion.tigris.org:8800/pmgt/trunk", 197 "http://subversion.tigris.org:8800/pmgt/trunk", 198 "username", 199 "subversion.tigris.org", 200 8800); 201 testUrl( 202 "scm:svn:https://username@subversion.tigris.org:8080/pmgt/trunk", 203 "https://subversion.tigris.org:8080/pmgt/trunk", 204 "username", 205 "subversion.tigris.org", 206 8080); 207 testUrl( 208 "scm:svn:svn://username@subversion.tigris.org:8800/pmgt/trunk", 209 "svn://subversion.tigris.org:8800/pmgt/trunk", 210 "username", 211 "subversion.tigris.org", 212 8800); 213 testUrl( 214 "scm:svn:svn+ssh://username@subversion.tigris.org:8080/pmgt/trunk", 215 "svn+ssh://username@subversion.tigris.org:8080/pmgt/trunk", 216 null, 217 "username@subversion.tigris.org", 218 8080); 219 } 220 221 // ---------------------------------------------------------------------- 222 // Testing illegal URLs 223 // ---------------------------------------------------------------------- 224 225 @Test 226 public void testIllegalFileUrl() throws Exception { 227 testIllegalUrl("file:/tmp/svn"); 228 } 229 230 // ---------------------------------------------------------------------- 231 // 232 // ---------------------------------------------------------------------- 233 234 private void testUrl( 235 String scmUrl, String expectedUrl, String expectedUser, String expectedPassword, String expectedHost) 236 throws Exception { 237 ScmRepository repository = scmManager.makeScmRepository(scmUrl); 238 239 assertNotNull("ScmManager.makeScmRepository() returned null", repository); 240 241 assertNotNull("The provider repository was null.", repository.getProviderRepository()); 242 243 assertTrue( 244 "The SCM Repository isn't a " + SvnScmProviderRepository.class.getName() + ".", 245 repository.getProviderRepository() instanceof SvnScmProviderRepository); 246 247 SvnScmProviderRepository providerRepository = (SvnScmProviderRepository) repository.getProviderRepository(); 248 249 assertEquals("url is incorrect", expectedUrl, providerRepository.getUrl()); 250 251 assertEquals("url string is incorrect", "svn:" + expectedUrl, repository.toString()); 252 253 assertEquals("User is incorrect", expectedUser, providerRepository.getUser()); 254 255 assertEquals("Password is incorrect", expectedPassword, providerRepository.getPassword()); 256 257 assertEquals( 258 "Host is incorrect", 259 expectedHost, 260 ((SvnScmProviderRepository) repository.getProviderRepository()).getHost()); 261 } 262 263 private void testUrl(String scmUrl, String expectedUrl, String expectedUser, String expectedHost, int expectedPort) 264 throws Exception { 265 testUrl(scmUrl, expectedUrl, expectedUser, null, expectedHost); 266 } 267 268 @SuppressWarnings("unused") 269 private void testUrl( 270 String scmUrl, 271 String expectedUrl, 272 String expectedUser, 273 String expectedPassword, 274 String expectedHost, 275 int expectedPort) 276 throws Exception { 277 testUrl(scmUrl, expectedUrl, expectedUser, expectedPassword, expectedHost); 278 279 ScmRepository repository = scmManager.makeScmRepository(scmUrl); 280 281 assertEquals( 282 "Port is incorrect", 283 expectedPort, 284 ((SvnScmProviderRepository) repository.getProviderRepository()).getPort()); 285 } 286 287 private void testIllegalUrl(String url) throws Exception { 288 try { 289 scmManager.makeScmRepository("scm:svn:" + url); 290 291 fail("Expected a ScmRepositoryException while testing the url '" + url + "'."); 292 } catch (ScmRepositoryException e) { 293 // expected 294 } 295 } 296 297 @Test 298 public void testGetParent() { 299 new SvnScmProviderRepository("http://subversion.tigris.org"); 300 } 301 302 @Test 303 public void testGetParentDotSlashEndingURL() { 304 SvnScmProviderRepository slashDotRepo = new SvnScmProviderRepository("file://a/b/c/././."); 305 assertTrue(slashDotRepo.getParent() instanceof SvnScmProviderRepository); 306 assertEquals("file://a/b", ((SvnScmProviderRepository) slashDotRepo.getParent()).getUrl()); 307 } 308 309 @Test 310 public void testGetParentSlashEndingURL() { 311 SvnScmProviderRepository slashRepo = new SvnScmProviderRepository("file://a/b/c///"); 312 assertTrue(slashRepo.getParent() instanceof SvnScmProviderRepository); 313 assertEquals("file://a/b", ((SvnScmProviderRepository) slashRepo.getParent()).getUrl()); 314 } 315}