001package org.apache.maven.scm.provider.jazz.repository; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.maven.scm.ScmTestCase; 023import org.apache.maven.scm.manager.NoSuchScmProviderException; 024import org.apache.maven.scm.manager.ScmManager; 025import org.apache.maven.scm.repository.ScmRepository; 026import org.apache.maven.scm.repository.ScmRepositoryException; 027 028import java.util.List; 029 030/** 031 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a> 032 */ 033public class JazzScmProviderRepositoryTest 034 extends ScmTestCase 035{ 036 private ScmManager scmManager; 037 038 public void setUp() 039 throws Exception 040 { 041 super.setUp(); 042 043 scmManager = getScmManager(); 044 } 045 046 // ---------------------------------------------------------------------- 047 // Testing legal URLs 048 // "scm:jazz:[username[;password]@]http[s]://server_name[:port]/contextRoot:repositoryWorkspace"; 049 // ---------------------------------------------------------------------- 050 051 public void testLegalFullHttpURI() 052 throws Exception 053 { 054 testUrl( "scm:jazz:username;password@http://server_name:9443/contextRoot:repositoryWorkspace", 055 "http://server_name:9443/contextRoot", "username", "password", "server_name", 9443, 056 "repositoryWorkspace" ); 057 } 058 059 public void testLegalHttpURI() 060 throws Exception 061 { 062 testUrl( "scm:jazz:http://server_name:9443/contextRoot:repositoryWorkspace", 063 "http://server_name:9443/contextRoot", null, null, "server_name", 9443, "repositoryWorkspace" ); 064 } 065 066 public void testLegalFullHttpURIWithLongPath() 067 throws Exception 068 { 069 testUrl( "scm:jazz:username;password@http://server_name:9443/some/long/contextRoot:repositoryWorkspace", 070 "http://server_name:9443/some/long/contextRoot", "username", "password", "server_name", 9443, 071 "repositoryWorkspace" ); 072 } 073 074 public void testLegalHttpURIWithLongPath() 075 throws Exception 076 { 077 testUrl( "scm:jazz:http://server_name:9443/some/long/contextRoot:repositoryWorkspace", 078 "http://server_name:9443/some/long/contextRoot", null, null, "server_name", 9443, 079 "repositoryWorkspace" ); 080 } 081 082 public void testLegalFullHttpURIWithShortPath() 083 throws Exception 084 { 085 testUrl( "scm:jazz:username;password@http://server_name:9443/:repositoryWorkspace", "http://server_name:9443/", 086 "username", "password", "server_name", 9443, "repositoryWorkspace" ); 087 } 088 089 public void testLegalHttpURIWithShortPathPath() 090 throws Exception 091 { 092 testUrl( "scm:jazz:http://server_name:9443/:repositoryWorkspace", "http://server_name:9443/", null, null, 093 "server_name", 9443, "repositoryWorkspace" ); 094 } 095 096 097 public void testLegalFullHttpURIWithShortPathAndNoPort() 098 throws Exception 099 { 100 testUrl( "scm:jazz:username;password@http://server_name/:repositoryWorkspace", "http://server_name/", 101 "username", "password", "server_name", 0, "repositoryWorkspace" ); 102 } 103 104 public void testLegalHttpURIWithShortPathPathAndNoPort() 105 throws Exception 106 { 107 testUrl( "scm:jazz:http://server_name/:repositoryWorkspace", "http://server_name/", null, null, "server_name", 108 0, "repositoryWorkspace" ); 109 } 110 111 public void testLegalHttpURIWithUser() 112 throws Exception 113 { 114 testUrl( "scm:jazz:username@http://server_name:9443/contextRoot:repositoryWorkspace", 115 "http://server_name:9443/contextRoot", "username", null, "server_name", 9443, "repositoryWorkspace" ); 116 } 117 118 public void testLegalHttpURIWithUserAndPassword() 119 throws Exception 120 { 121 testUrl( "scm:jazz:username;password@http://server_name:9443/contextRoot:repositoryWorkspace", 122 "http://server_name:9443/contextRoot", "username", "password", "server_name", 9443, 123 "repositoryWorkspace" ); 124 } 125 126 public void testLegalFullHttpsURI() 127 throws Exception 128 { 129 testUrl( "scm:jazz:username;password@https://server_name:9443/contextRoot:repositoryWorkspace", 130 "https://server_name:9443/contextRoot", "username", "password", "server_name", 9443, 131 "repositoryWorkspace" ); 132 } 133 134 public void testLegalHttpsURI() 135 throws Exception 136 { 137 testUrl( "scm:jazz:https://server_name:9443/contextRoot:repositoryWorkspace", 138 "https://server_name:9443/contextRoot", null, null, "server_name", 9443, "repositoryWorkspace" ); 139 } 140 141 public void testLegalHttpsURINoPort() 142 throws Exception 143 { 144 testUrl( "scm:jazz:https://server_name/contextRoot:repositoryWorkspace", "https://server_name/contextRoot", 145 null, null, "server_name", 0, "repositoryWorkspace" ); 146 } 147 148 public void testLegalHttpsURIWithUser() 149 throws Exception 150 { 151 testUrl( "scm:jazz:username@https://server_name:9443/contextRoot:repositoryWorkspace", 152 "https://server_name:9443/contextRoot", "username", null, "server_name", 9443, "repositoryWorkspace" ); 153 } 154 155 public void testLegalHttpsURIWithUserAndPassword() 156 throws Exception 157 { 158 testUrl( "scm:jazz:username;password@https://server_name:9443/contextRoot:repositoryWorkspace", 159 "https://server_name:9443/contextRoot", "username", "password", "server_name", 9443, 160 "repositoryWorkspace" ); 161 } 162 163 public void testLegalFullHttpURIWithSpaces() 164 throws Exception 165 { 166 testUrl( "scm:jazz:username;password@http://server_name:9443/contextRoot:repository Workspace", 167 "http://server_name:9443/contextRoot", "username", "password", "server_name", 9443, 168 "repository Workspace" ); 169 } 170 171 public void testLegalFullHttpsURIWithSpaces() 172 throws Exception 173 { 174 testUrl( "scm:jazz:username;password@https://server_name:9443/contextRoot:repository Workspace", 175 "https://server_name:9443/contextRoot", "username", "password", "server_name", 9443, 176 "repository Workspace" ); 177 } 178 179 public void testLegalFullHttpsURIWithSpacesAndQuote() 180 throws Exception 181 { 182 testUrl( "scm:jazz:username;password@https://server_name:9443/contextRoot:Dave's Repository Workspace", 183 "https://server_name:9443/contextRoot", "username", "password", "server_name", 9443, 184 "Dave's Repository Workspace" ); 185 } 186 187 // ---------------------------------------------------------------------- 188 // Testing illegal URLs 189 // "scm:jazz:[username[;password]@]http[s]://server_name[:port]/contextRoot:repositoryWorkspace"; 190 // Something missing or broken in the above. 191 // ---------------------------------------------------------------------- 192 193 public void testIllegalFullHttpsURIWithMissingPathOrWorkspace() 194 throws Exception 195 { 196 testBrokenUrl( "scm:jazz:username;password@https://server_name:9443/contextRootOrWorkspaceIsMissing" ); 197 } 198 199 public void testIllegalFullHttpsURIWithMissingPathOrWorkspaceAndPort() 200 throws Exception 201 { 202 testBrokenUrl( "scm:jazz:username;password@https://server_name/contextRootOrWorkspaceIsMissing" ); 203 } 204 205 public void testIllegalFullHttpsURIWithMissingPathOrWorkspaceAndUsernameAndPasswordAndPort() 206 throws Exception 207 { 208 testBrokenUrl( "scm:jazz:https://server_name/contextRootOrWorkspaceIsMissing" ); 209 } 210 211 public void testIllegalFullHttpsURIWithMissingPortButWithColon() 212 throws Exception 213 { 214 testBrokenUrl( "scm:jazz:username;password@https://server_name:/contextRoot:repositoryWorkspace" ); 215 } 216 217 public void testIllegalFullHttpsURIWithMissingPortAndPathOrWorkspace() 218 throws Exception 219 { 220 testBrokenUrl( "scm:jazz:username;password@https://server_name/contextRootOrWorkspaceIsMissing" ); 221 } 222 223 public void testIllegalWrongProtocolURI() 224 throws Exception 225 { 226 testBrokenUrl( "scm:jazz:username;password@ssh://server_name/contextRoot/repositoryWorkspace" ); 227 } 228 229 public void testIllegalFullHttpsURIWithBadPort() 230 throws Exception 231 { 232 testBrokenUrl( "scm:jazz:username;password@https://server_name:xxxx/contextRoot:repositoryWorkspace" ); 233 } 234 235 // ---------------------------------------------------------------------- 236 // 237 // ---------------------------------------------------------------------- 238 239 private void testUrl( String scmUrl, String expectedrepositoryURI, String expectedUser, String expectedPassword, 240 String expectedHost, int expectedPort, String expectedRepositoryWorkspace ) 241 throws Exception 242 { 243 // The messages are the lines returned from the ScmRepositoryException when thrown on a failure. 244 List<String> messages = scmManager.validateScmRepository( scmUrl ); 245 assertEquals( 246 "Excepected zero messages back from URL Validation, but got: " + messages.size() + " messages. Contents = " 247 + messages, 0, messages.size() ); 248 249 // Get an instance of the JazzScmProviderRepository, parsing the URL as we go. 250 ScmRepository repository = scmManager.makeScmRepository( scmUrl ); 251 252 assertNotNull( "ScmManager.makeScmRepository() returned null!", repository ); 253 254 assertNotNull( "The provider repository was null!", repository.getProviderRepository() ); 255 256 assertTrue( "The SCM Repository isn't a " + JazzScmProviderRepository.class.getName() + "!", 257 repository.getProviderRepository() instanceof JazzScmProviderRepository ); 258 259 // Now that we have it, query the rest of the jazz specific values. 260 JazzScmProviderRepository providerRepository = (JazzScmProviderRepository) repository.getProviderRepository(); 261 262 assertEquals( "The URI is incorrect!", expectedrepositoryURI, providerRepository.getRepositoryURI() ); 263 264 assertEquals( "The URI string is incorrect!", 265 "jazz:" + expectedrepositoryURI + ":" + expectedRepositoryWorkspace, repository.toString() ); 266 267 assertEquals( "The user is incorrect!", expectedUser, providerRepository.getUser() ); 268 269 assertEquals( "The password is incorrect!", expectedPassword, providerRepository.getPassword() ); 270 271 assertEquals( "The host is incorrect!", expectedHost, 272 ( (JazzScmProviderRepository) repository.getProviderRepository() ).getHost() ); 273 274 if ( expectedPort > 0 ) 275 { 276 assertEquals( "The port is incorrect!", expectedPort, providerRepository.getPort() ); 277 } 278 279 assertEquals( "The RepositoryWorkspace is incorrect!", expectedRepositoryWorkspace, 280 providerRepository.getRepositoryWorkspace() ); 281 } 282 283 private void testBrokenUrl( String scmUrl ) 284 { 285 try 286 { 287 ScmRepository repository = scmManager.makeScmRepository( scmUrl ); 288 fail( "The expected ScmRepositoryException did not occur! " + repository ); 289 } 290 catch ( ScmRepositoryException expected ) 291 { 292 // This is the expected behaviour, so we do nothing. 293 } 294 catch ( NoSuchScmProviderException unexpected ) 295 { 296 fail( "Unexpected failure! " + unexpected.getMessage() ); 297 } 298 } 299}