Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 501498f9bb25dfe726490537ad3937bf8ad01716 (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
/*******************************************************************************
 * Copyright (c) 2012 Wind River Systems, Inc. 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.tests.tcf.filesystem.url;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import org.eclipse.tcf.te.tests.CoreTestCase;

public class TcfURLTests extends CoreTestCase {

	public void testWinURLFormat() throws MalformedURLException {
		String string = "tcf:/TCP:127.0.0.1:1534/C:/temp/hello.txt"; //$NON-NLS-1$
		URL url = new URL(string);
		assertEquals("tcf", url.getProtocol()); //$NON-NLS-1$
		assertEquals("TCP:127.0.0.1:1534", url.getHost()); //$NON-NLS-1$
		assertEquals("C:/temp/hello.txt", url.getPath()); //$NON-NLS-1$
	}

	@SuppressWarnings("unused")
    public void testWinURLFormatNegative() {
		try {
			String string = "tcf:/TCP:127.0.0.1:1534/C:/hello:txt"; //$NON-NLS-1$
			new URL(string);
			assertTrue("FAILED", false); //$NON-NLS-1$
		}
		catch (MalformedURLException e) {
		}
	}

	public void testUnixURLFormat() throws MalformedURLException {
		String string = "tcf:/TCP:127.0.0.1:1534/folk/wchen/hello.txt"; //$NON-NLS-1$
		URL url = new URL(string);
		assertEquals("tcf", url.getProtocol()); //$NON-NLS-1$
		assertEquals("TCP:127.0.0.1:1534", url.getHost()); //$NON-NLS-1$
		assertEquals("/folk/wchen/hello.txt", url.getPath()); //$NON-NLS-1$
	}

	@SuppressWarnings("unused")
    public void testUnixURLFormatNegative() {
		try {
			String string = "tcf://TCP:127.0.0.1:1534/folk/wchen/hello.txt"; //$NON-NLS-1$
			new URL(string);
			assertTrue("FAILED", false); //$NON-NLS-1$
		}
		catch (MalformedURLException e) {
		}
	}

	public void testUDPURLFormat() throws MalformedURLException {
		String string = "tcf:/UDP:127.0.0.1:1534/C:/temp/hello.txt"; //$NON-NLS-1$
		URL url = new URL(string);
		assertEquals("tcf", url.getProtocol()); //$NON-NLS-1$
		assertEquals("UDP:127.0.0.1:1534", url.getHost()); //$NON-NLS-1$
		assertEquals("C:/temp/hello.txt", url.getPath()); //$NON-NLS-1$
	}
	
	@SuppressWarnings("unused")
    public void testSpaceInURINegative() {
		try{
			String string = "tcf:/TCP:127.0.0.1:1534/C:/Documents and Settings/hello.txt"; //$NON-NLS-1$
			new URI(string);
			assertTrue("FAILED", false); //$NON-NLS-1$
		}catch(URISyntaxException e){
			// Right and Ignore
		}
	}
	
	public void testSpaceInURL() throws MalformedURLException, URISyntaxException {
		String string = "tcf:/TCP:127.0.0.1:1534/C:/Documents and Settings/hello.txt";  //$NON-NLS-1$
		URL url = new URL(string);
		assertEquals("tcf", url.getProtocol()); //$NON-NLS-1$
		assertEquals("TCP:127.0.0.1:1534", url.getHost()); //$NON-NLS-1$
		assertEquals("C:/Documents and Settings/hello.txt", url.getPath()); //$NON-NLS-1$
	}
	
	public void testURLtoURI() throws MalformedURLException, URISyntaxException {
		String string = "tcf:/TCP:127.0.0.1:1534/C:/Documents and Settings/hello.txt";  //$NON-NLS-1$
		URL url = new URL(string);
		URI uri = url.toURI();
		assertEquals("tcf:/TCP:127.0.0.1:1534/C:/Documents+and+Settings/hello.txt", uri.toString()); //$NON-NLS-1$
	}
	
	public void testURItoURL() throws MalformedURLException, URISyntaxException {
		String string = "tcf:/TCP:127.0.0.1:1534/C:/Documents+and+Settings/hello.txt";  //$NON-NLS-1$
		URI uri = new URI(string);
		URL url = uri.toURL();
		assertEquals("tcf", url.getProtocol()); //$NON-NLS-1$
		assertEquals("TCP:127.0.0.1:1534", url.getHost()); //$NON-NLS-1$
		assertEquals("C:/Documents and Settings/hello.txt", url.getPath()); //$NON-NLS-1$
	}
}

Back to the top