Skip to main content
summaryrefslogtreecommitdiffstats
blob: c7334d577a052f6494454332e4182ff20313e461 (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
/*******************************************************************************
 * Copyright (c) 2006, 2008 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.internal.ccvs.core.CVSException;
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);
	}
	
}

Back to the top