1 /******************************************************************************* 2 * Copyright (c) 2006, 2011 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.team.tests.ccvs.core.cvsresources; 15 16 import java.net.URI; 17 import java.net.URISyntaxException; 18 19 import junit.framework.Test; 20 import junit.framework.TestSuite; 21 22 import org.eclipse.team.core.ScmUrlImportDescription; 23 import org.eclipse.team.internal.ccvs.core.CVSException; 24 import org.eclipse.team.internal.ccvs.core.CVSProjectSetCapability; 25 import org.eclipse.team.internal.ccvs.core.CVSTag; 26 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; 27 import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; 28 import org.eclipse.team.internal.ccvs.core.filesystem.CVSURI; 29 import org.eclipse.team.tests.ccvs.core.CVSTestSetup; 30 import org.eclipse.team.tests.ccvs.core.EclipseTest; 31 32 public class CVSURITest extends EclipseTest { 33 CVSURITest()34 public CVSURITest() { 35 super(); 36 } 37 CVSURITest(String name)38 public CVSURITest(String name) { 39 super(name); 40 } 41 suite()42 public static Test suite() { 43 TestSuite suite = new TestSuite(CVSURITest.class); 44 return new CVSTestSetup(suite); 45 } 46 testURIParse()47 public void testURIParse() throws URISyntaxException, CVSException { 48 URI uri = new URI("cvs://_pserver_user~host.here_!root!path/project/path"); 49 CVSURI cvsUri = CVSURI.fromUri(uri); 50 assertEquals("/project/path", cvsUri.getPath().toString()); 51 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:user@host.here:/root/path"); 52 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 53 assertEquals(cvsUri.getTag(), null); 54 assertEquals(cvsUri.toURI(), uri); 55 } 56 testURIParse2()57 public void testURIParse2() throws URISyntaxException, CVSException { 58 URI uri = new URI("cvs://_pserver_user_password~host.here_1234!root!path/project/path"); 59 CVSURI cvsUri = CVSURI.fromUri(uri); 60 assertEquals("/project/path", cvsUri.getPath().toString()); 61 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:user:password@host.here:1234/root/path"); 62 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 63 assertEquals(cvsUri.getTag(), null); 64 assertEquals(cvsUri.toURI(), uri); 65 } 66 testURIParse3()67 public void testURIParse3() throws URISyntaxException, CVSException { 68 URI uri = new URI("cvs://_pserver_user_password~host.here_1234!root!path/project/path?version=v1"); 69 CVSURI cvsUri = CVSURI.fromUri(uri); 70 assertEquals("/project/path", cvsUri.getPath().toString()); 71 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:user:password@host.here:1234/root/path"); 72 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 73 assertEquals(cvsUri.getTag(), new CVSTag("v1", CVSTag.VERSION)); 74 assertEquals(cvsUri.toURI(), uri); 75 } 76 testURIParse4()77 public void testURIParse4() throws URISyntaxException, CVSException { 78 URI uri = new URI("cvs://_pserver_user_password~host.here_1234!root!path/project/path?branch=b1"); 79 CVSURI cvsUri = CVSURI.fromUri(uri); 80 assertEquals("/project/path", cvsUri.getPath().toString()); 81 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:user:password@host.here:1234/root/path"); 82 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 83 assertEquals(cvsUri.getTag(), new CVSTag("b1", CVSTag.BRANCH)); 84 assertEquals(cvsUri.toURI(), uri); 85 } 86 testURIParse5()87 public void testURIParse5() throws URISyntaxException, CVSException { 88 URI uri = new URI("cvs://_pserver_user_password~host.here_1234!root!path/project/path?revision=1.5"); 89 CVSURI cvsUri = CVSURI.fromUri(uri); 90 assertEquals("/project/path", cvsUri.getPath().toString()); 91 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:user:password@host.here:1234/root/path"); 92 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 93 assertEquals(cvsUri.getRevision(), "1.5"); 94 assertEquals(cvsUri.toURI(), uri); 95 } 96 testURIParse6()97 public void testURIParse6() throws URISyntaxException, CVSException { 98 URI uri = new URI("cvs://_pserver_user_pass~~word~host.here_1234!the__root!path!!/project/path?revision=1.5"); 99 CVSURI cvsUri = CVSURI.fromUri(uri); 100 assertEquals("/project/path", cvsUri.getPath().toString()); 101 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:user:pass~word@host.here:1234/the_root/path!"); 102 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 103 assertEquals(cvsUri.getRevision(), "1.5"); 104 assertEquals(cvsUri.toURI(), uri); 105 } 106 107 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=231190 testURIParse7()108 public void testURIParse7() throws URISyntaxException, CVSException { 109 URI uri = new URI("cvs://_pserver_username_password~testserver.acme.com_!root/"); 110 CVSURI cvsUri = CVSURI.fromUri(uri); 111 assertEquals("/", cvsUri.getPath().toString()); 112 // location string taken from the bug 113 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver;username=username;password=password:testserver.acme.com/root"); 114 assertEquals("pserver", location.getMethod().getName()); 115 assertEquals("username", location.getUsername()); 116 assertEquals(ICVSRepositoryLocation.USE_DEFAULT_PORT, location.getPort()); 117 assertEquals("testserver.acme.com", location.getHost()); 118 assertEquals("/root", location.getRootDirectory()); 119 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 120 assertEquals(null, cvsUri.getTag()); 121 assertEquals(cvsUri.toURI(), uri); 122 } 123 124 // CVS SCM URL tests, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=326926 testScmUri1()125 public void testScmUri1() throws CVSException { 126 URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:module;tag=tag"); 127 CVSURI cvsUri = CVSURI.fromUri(uri); 128 assertEquals("module", cvsUri.getPath().toString()); 129 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path"); 130 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 131 assertEquals(cvsUri.getTag(), new CVSTag("tag", CVSTag.VERSION)); 132 133 String refString = new CVSProjectSetCapability().asReference(uri, "project"); 134 assertEquals("1.0,:pserver:host.com:/cvsroot/path,module,project,tag", refString); 135 } 136 testScmUri2()137 public void testScmUri2() throws CVSException { 138 URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:module;version=version"); 139 CVSURI cvsUri = CVSURI.fromUri(uri); 140 assertEquals("module", cvsUri.getPath().toString()); 141 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path"); 142 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 143 assertEquals(cvsUri.getTag(), new CVSTag("version", CVSTag.VERSION)); 144 145 String refString = new CVSProjectSetCapability().asReference(uri, "project"); 146 assertEquals("1.0,:pserver:host.com:/cvsroot/path,module,project,version", refString); 147 } 148 testScmUri3()149 public void testScmUri3() throws CVSException { 150 URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;version=version;project=project1"); 151 CVSURI cvsUri = CVSURI.fromUri(uri); 152 assertEquals("path/to/module", cvsUri.getPath().toString()); 153 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path"); 154 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 155 assertEquals(cvsUri.getTag(), new CVSTag("version", CVSTag.VERSION)); 156 157 String refString = new CVSProjectSetCapability().asReference(uri, "project2"); 158 assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,project2,version", refString); 159 } 160 testScmUri4()161 public void testScmUri4() throws CVSException { 162 URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;version=version;project=project1"); 163 CVSURI cvsUri = CVSURI.fromUri(uri); 164 assertEquals("path/to/module", cvsUri.getPath().toString()); 165 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path"); 166 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 167 assertEquals(cvsUri.getTag(), new CVSTag("version", CVSTag.VERSION)); 168 169 String refString = new CVSProjectSetCapability().asReference(uri, null); 170 assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,project1,version", refString); 171 } 172 testScmUri5()173 public void testScmUri5() throws CVSException { 174 URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;project=project1;version=version"); 175 CVSURI cvsUri = CVSURI.fromUri(uri); 176 assertEquals("path/to/module", cvsUri.getPath().toString()); 177 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path"); 178 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 179 assertEquals(cvsUri.getTag(), new CVSTag("version", CVSTag.VERSION)); 180 181 String refString = new CVSProjectSetCapability().asReference(uri, null); 182 assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,project1,version", refString); 183 } 184 testScmUri6()185 public void testScmUri6() throws CVSException { 186 URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;tag=tag"); 187 CVSURI cvsUri = CVSURI.fromUri(uri); 188 assertEquals("path/to/module", cvsUri.getPath().toString()); 189 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path"); 190 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 191 assertEquals(cvsUri.getTag(), new CVSTag("tag", CVSTag.VERSION)); 192 193 String refString = new CVSProjectSetCapability().asReference(uri, null); 194 assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,module,tag", refString); 195 } 196 testScmUri7()197 public void testScmUri7() throws CVSException { 198 URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;version=version"); 199 CVSURI cvsUri = CVSURI.fromUri(uri); 200 assertEquals("path/to/module", cvsUri.getPath().toString()); 201 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path"); 202 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 203 assertEquals(cvsUri.getTag(), new CVSTag("version", CVSTag.VERSION)); 204 205 String refString = new CVSProjectSetCapability().asReference(uri, null); 206 assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,module,version", refString); 207 } 208 testScmUri8()209 public void testScmUri8() throws CVSException { 210 URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;project="); 211 CVSURI cvsUri = CVSURI.fromUri(uri); 212 assertEquals("path/to/module", cvsUri.getPath().toString()); 213 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path"); 214 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 215 assertEquals(cvsUri.getTag(), CVSTag.DEFAULT); 216 217 String refString = new CVSProjectSetCapability().asReference(uri, null); 218 assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,module", refString); 219 } 220 testScmUri9()221 public void testScmUri9() throws CVSException { 222 URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module"); 223 CVSURI cvsUri = CVSURI.fromUri(uri); 224 assertEquals("path/to/module", cvsUri.getPath().toString()); 225 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path"); 226 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 227 assertEquals(cvsUri.getTag(), CVSTag.DEFAULT); 228 229 String refString = new CVSProjectSetCapability().asReference(uri, "project"); 230 assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,project", refString); 231 } 232 testScmUri10()233 public void testScmUri10() throws URISyntaxException, CVSException { 234 URI uri = new URI("scm:cvs:pserver:anonymous:@host.com:/cvsroot/path:module"); 235 CVSURI cvsUri = CVSURI.fromUri(uri); 236 assertEquals("module", cvsUri.getPath().toString()); 237 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:anonymous:@host.com:/cvsroot/path"); 238 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 239 assertEquals(cvsUri.getTag(), CVSTag.DEFAULT); 240 241 String refString = new CVSProjectSetCapability().asReference(uri, "project"); 242 assertEquals("1.0,:pserver:anonymous:@host.com:/cvsroot/path,module,project", refString); 243 } 244 testScmUri11()245 public void testScmUri11() throws URISyntaxException, CVSException { 246 URI uri = new URI("scm:cvs:pserver:username@host.com:/cvsroot/path:module"); 247 CVSURI cvsUri = CVSURI.fromUri(uri); 248 assertEquals("module", cvsUri.getPath().toString()); 249 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:username@host.com:/cvsroot/path"); 250 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 251 assertEquals(cvsUri.getTag(), CVSTag.DEFAULT); 252 253 String refString = new CVSProjectSetCapability().asReference(uri, "project"); 254 assertEquals("1.0,:pserver:username@host.com:/cvsroot/path,module,project", refString); 255 } 256 testScmUri12()257 public void testScmUri12() throws URISyntaxException { 258 URI uri = new URI("notScm:cvs:pserver:username@host.com:/cvsroot/path:module"); 259 try { 260 new CVSProjectSetCapability().asReference(uri, "project"); 261 fail("Expected IllegalArgumentException"); 262 } catch (IllegalArgumentException e) { 263 } 264 } 265 testScmUri13()266 public void testScmUri13() throws URISyntaxException { 267 URI uri = new URI("scm:cvs:pserver:username@host.com:/cvsroot/path:"); 268 String refString = new CVSProjectSetCapability().asReference(uri, null); 269 assertNull(refString); 270 } 271 testScmUri14()272 public void testScmUri14() { 273 try { 274 URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;tag=\"tag\""); 275 } catch (IllegalArgumentException e) { 276 // expected, " are not allowed in a URI reference 277 } 278 } 279 testScmUri15()280 public void testScmUri15() throws CVSException { 281 // ScmUrlImportDescription can handle " in Strings expected to be URI refs 282 ScmUrlImportDescription description = new ScmUrlImportDescription("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;tag=\"tag\"", null); 283 URI uri = description.getUri(); 284 CVSURI cvsUri = CVSURI.fromUri(uri); 285 assertEquals("path/to/module", cvsUri.getPath().toString()); 286 CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path"); 287 assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false)); 288 assertEquals(cvsUri.getTag(), new CVSTag("tag", CVSTag.VERSION)); 289 290 String refString = new CVSProjectSetCapability().asReference(uri, null); 291 assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,module,tag", refString); 292 } 293 } 294