Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 21ddfc8baa48671f0c77478030fa014af508679b (plain) (blame)
1
2
3
4
5
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/*******************************************************************************
 * Copyright (c) 2006, 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.tests.ccvs.core.cvsresources;

import java.net.URI;
import java.net.URISyntaxException;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.eclipse.team.core.ScmUrlImportDescription;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.CVSProjectSetCapability;
import org.eclipse.team.internal.ccvs.core.CVSTag;
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.core.filesystem.CVSURI;
import org.eclipse.team.tests.ccvs.core.CVSTestSetup;
import org.eclipse.team.tests.ccvs.core.EclipseTest;

public class CVSURITest extends EclipseTest {

	public CVSURITest() {
		super();
	}

	public CVSURITest(String name) {
		super(name);
	}

	public static Test suite() {
		TestSuite suite = new TestSuite(CVSURITest.class);
		return new CVSTestSetup(suite);
	}
	
	public void testURIParse() throws URISyntaxException, CVSException {
		URI uri = new URI("cvs://_pserver_user~host.here_!root!path/project/path");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("/project/path", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:user@host.here:/root/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), null);
		assertEquals(cvsUri.toURI(), uri);
	}
	
	public void testURIParse2() throws URISyntaxException, CVSException {
		URI uri = new URI("cvs://_pserver_user_password~host.here_1234!root!path/project/path");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("/project/path", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:user:password@host.here:1234/root/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), null);
		assertEquals(cvsUri.toURI(), uri);
	}
	
	public void testURIParse3() throws URISyntaxException, CVSException {
		URI uri = new URI("cvs://_pserver_user_password~host.here_1234!root!path/project/path?version=v1");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("/project/path", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:user:password@host.here:1234/root/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), new CVSTag("v1", CVSTag.VERSION));
		assertEquals(cvsUri.toURI(), uri);
	}
	
	public void testURIParse4() throws URISyntaxException, CVSException {
		URI uri = new URI("cvs://_pserver_user_password~host.here_1234!root!path/project/path?branch=b1");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("/project/path", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:user:password@host.here:1234/root/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), new CVSTag("b1", CVSTag.BRANCH));
		assertEquals(cvsUri.toURI(), uri);
	}
	
	public void testURIParse5() throws URISyntaxException, CVSException {
		URI uri = new URI("cvs://_pserver_user_password~host.here_1234!root!path/project/path?revision=1.5");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("/project/path", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:user:password@host.here:1234/root/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getRevision(), "1.5");
		assertEquals(cvsUri.toURI(), uri);
	}
	
	public void testURIParse6() throws URISyntaxException, CVSException {
		URI uri = new URI("cvs://_pserver_user_pass~~word~host.here_1234!the__root!path!!/project/path?revision=1.5");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("/project/path", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:user:pass~word@host.here:1234/the_root/path!");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getRevision(), "1.5");
		assertEquals(cvsUri.toURI(), uri);
	}
	
	// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=231190
	public void testURIParse7() throws URISyntaxException, CVSException {
		URI uri = new URI("cvs://_pserver_username_password~testserver.acme.com_!root/");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("/", cvsUri.getPath().toString());
		// location string taken from the bug
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver;username=username;password=password:testserver.acme.com/root");
		assertEquals("pserver", location.getMethod().getName());
		assertEquals("username", location.getUsername());
		assertEquals(ICVSRepositoryLocation.USE_DEFAULT_PORT, location.getPort()); 
		assertEquals("testserver.acme.com", location.getHost());
		assertEquals("/root", location.getRootDirectory());
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(null, cvsUri.getTag());
		assertEquals(cvsUri.toURI(), uri);
	}

	// CVS SCM URL tests, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=326926
	public void testScmUri1() throws CVSException {
		URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:module;tag=tag");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("module", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), new CVSTag("tag", CVSTag.VERSION));

		String refString = new CVSProjectSetCapability().asReference(uri, "project");
		assertEquals("1.0,:pserver:host.com:/cvsroot/path,module,project,tag", refString);
	}

	public void testScmUri2() throws CVSException {
		URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:module;version=version");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("module", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), new CVSTag("version", CVSTag.VERSION));

		String refString = new CVSProjectSetCapability().asReference(uri, "project");
		assertEquals("1.0,:pserver:host.com:/cvsroot/path,module,project,version", refString);
	}

	public void testScmUri3() throws CVSException {
		URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;version=version;project=project1");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("path/to/module", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), new CVSTag("version", CVSTag.VERSION));

		String refString = new CVSProjectSetCapability().asReference(uri, "project2");
		assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,project2,version", refString);
	}

	public void testScmUri4() throws CVSException {
		URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;version=version;project=project1");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("path/to/module", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), new CVSTag("version", CVSTag.VERSION));

		String refString = new CVSProjectSetCapability().asReference(uri, null);
		assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,project1,version", refString);
	}

	public void testScmUri5() throws CVSException {
		URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;project=project1;version=version");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("path/to/module", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), new CVSTag("version", CVSTag.VERSION));

		String refString = new CVSProjectSetCapability().asReference(uri, null);
		assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,project1,version", refString);
	}

	public void testScmUri6() throws CVSException {
		URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;tag=tag");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("path/to/module", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), new CVSTag("tag", CVSTag.VERSION));

		String refString = new CVSProjectSetCapability().asReference(uri, null);
		assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,module,tag", refString);
	}

	public void testScmUri7() throws CVSException {
		URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;version=version");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("path/to/module", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), new CVSTag("version", CVSTag.VERSION));

		String refString = new CVSProjectSetCapability().asReference(uri, null);
		assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,module,version", refString);
	}
	
	public void testScmUri8() throws CVSException {
		URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;project=");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("path/to/module", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), CVSTag.DEFAULT);

		String refString = new CVSProjectSetCapability().asReference(uri, null);
		assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,module", refString);
	}

	public void testScmUri9() throws CVSException {
		URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("path/to/module", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), CVSTag.DEFAULT);

		String refString = new CVSProjectSetCapability().asReference(uri, "project");
		assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,project", refString);
	}

	public void testScmUri10() throws URISyntaxException, CVSException {
		URI uri = new URI("scm:cvs:pserver:anonymous:@host.com:/cvsroot/path:module");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("module", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:anonymous:@host.com:/cvsroot/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), CVSTag.DEFAULT);

		String refString = new CVSProjectSetCapability().asReference(uri, "project");
		assertEquals("1.0,:pserver:anonymous:@host.com:/cvsroot/path,module,project", refString);
	}

	public void testScmUri11() throws URISyntaxException, CVSException {
		URI uri = new URI("scm:cvs:pserver:username@host.com:/cvsroot/path:module");
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("module", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:username@host.com:/cvsroot/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), CVSTag.DEFAULT);

		String refString = new CVSProjectSetCapability().asReference(uri, "project");
		assertEquals("1.0,:pserver:username@host.com:/cvsroot/path,module,project", refString);
	}
	
	public void testScmUri12() throws URISyntaxException {
		URI uri = new URI("notScm:cvs:pserver:username@host.com:/cvsroot/path:module");
		try {
			new CVSProjectSetCapability().asReference(uri, "project");
			fail("Expected IllegalArgumentException");
		} catch (IllegalArgumentException e) {
		}
	}

	public void testScmUri13() throws URISyntaxException {
		URI uri = new URI("scm:cvs:pserver:username@host.com:/cvsroot/path:");
		String refString = new CVSProjectSetCapability().asReference(uri, null);
		assertNull(refString);
	}
	
	public void testScmUri14() {
		try {
			URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;tag=\"tag\"");
		} catch (IllegalArgumentException e) {
			// expected, " are not allowed in a URI reference
		}
	}
	
	public void testScmUri15() throws CVSException {
		// ScmUrlImportDescription can handle " in Strings expected to be URI refs
		ScmUrlImportDescription description = new ScmUrlImportDescription("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;tag=\"tag\"", null);
		URI uri = description.getUri();
		CVSURI cvsUri = CVSURI.fromUri(uri);
		assertEquals("path/to/module", cvsUri.getPath().toString());
		CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
		assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
		assertEquals(cvsUri.getTag(), new CVSTag("tag", CVSTag.VERSION));

		String refString = new CVSProjectSetCapability().asReference(uri, null);
		assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,module,tag", refString);
	}
}

Back to the top