Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8418eec03ce97ac757785ce3a72fa4224614a950 (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
/*******************************************************************************
 * Copyright (c) 2015 IBM Corporation.
 * 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:
 *     Wainer dos Santos Moschetta (IBM Corporation) - initial implementation
 *******************************************************************************/
package org.eclipse.linuxtools.remote.proxy.tests;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.net.URI;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.linuxtools.internal.profiling.launch.LocalFileProxy;
import org.eclipse.linuxtools.internal.profiling.launch.LocalLauncher;
import org.eclipse.linuxtools.internal.rdt.proxy.RDTCommandLauncher;
import org.eclipse.linuxtools.internal.rdt.proxy.RDTFileProxy;
import org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher;
import org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy;
import org.eclipse.linuxtools.profiling.launch.RemoteConnection;
import org.eclipse.ptp.rdt.sync.core.RemoteLocation;
import org.eclipse.ptp.rdt.sync.core.SyncConfig;

@SuppressWarnings("restriction")
public class RemoteProxyManagerTest extends AbstractProxyTest {

	@Test
	public void testGetFileProxy() {
		IRemoteFileProxy fp;
		try {
			/*
			 * Test the proxy for local URIs and project
			 */
			fp = proxyManager.getFileProxy(URI.create("/path/to/file"));
			assertTrue("Should return a local file proxy", fp instanceof LocalFileProxy);
			fp = proxyManager.getFileProxy(URI.create("file:/path/to/file"));
			assertTrue("Should return a local file proxy", fp instanceof LocalFileProxy);
			fp = proxyManager.getFileProxy(localProject.getLocationURI());
			assertTrue("Should return a local file proxy", fp instanceof LocalFileProxy);
			fp = proxyManager.getFileProxy(localProject.getProject());
			assertTrue("Should return a local file proxy", fp instanceof LocalFileProxy);
			/*
			 * Test the proxy for remote URIs and project
			 */
			fp = proxyManager.getFileProxy(URI.create("ssh://" + CONNECTION_NAME + "/path/to/file"));
			assertTrue("Should have returned a remote file proxy", fp instanceof RDTFileProxy);
			fp = proxyManager.getFileProxy(syncProject.getProject());
			assertTrue("Should have returned a remote file proxy", fp instanceof RDTFileProxy);
		} catch (CoreException e) {
			fail("Should have returned a file proxy: " + e.getCause());
		}

		/*
		 * Test the proxy for unsupported URIs
		 */
		try {
			// As of org.eclipse.remote 2.0, remotetools scheme is no longer
			// support
			fp = proxyManager.getFileProxy(URI.create("remotetools://MyConnection/path/to/file"));
			fail("remotetools scheme should not be recognized");
		} catch (CoreException e) {
			assertTrue(true);
		}
	}

	@Test
	public void testGetLauncher() {
		IRemoteCommandLauncher cl;
		try {
			/*
			 * Test launcher got for local URIs and project
			 */
			cl = proxyManager.getLauncher(localProject.getLocationURI());
			assertTrue("Should have returned a local launcher", cl instanceof LocalLauncher);
			cl = proxyManager.getLauncher(localProject);
			assertTrue("Should have returned a local launcher", cl instanceof LocalLauncher);
			/*
			 * Test launcher got for remote project and URI
			 */
			cl = proxyManager.getLauncher(URI.create("ssh://" + CONNECTION_NAME + "/path/to/file"));
			assertTrue("Should have returned a remote file proxy", cl instanceof RDTCommandLauncher);
			cl = proxyManager.getLauncher(syncProject);
			assertTrue("Should have returned a remote launcher", cl instanceof RDTCommandLauncher);
		} catch (CoreException e) {
			fail("Should have returned a launcher: " + e.getCause());
		}

		/*
		 * Test the proxy for unsupported URIs
		 */
		try {
			// As of org.eclipse.remote 2.0, remotetools scheme is no longer
			// support
			cl = proxyManager.getLauncher(URI.create("remotetools://MyConnection/path/to/file"));
			fail("remotetools scheme should not be recognized");
		} catch (CoreException e) {
			assertTrue(true);
		}
	}

	@Test
	public void testGetOS() {
		String actualOS = null;
		try {
			/*
			 * Test got OS for local URIs and project
			 */
			actualOS = proxyManager.getOS(URI.create("/path/to/file"));
			assertNotNull(actualOS);
			assertTrue("Should have returned the OS name", !actualOS.isEmpty());
			actualOS = proxyManager.getOS(URI.create("file:/path/to/file"));
			assertNotNull(actualOS);
			assertTrue("Should have returned the OS name", !actualOS.isEmpty());
			actualOS = proxyManager.getOS(localProject.getLocationURI());
			assertNotNull(actualOS);
			assertTrue("Should have returned the OS name", !actualOS.isEmpty());
			actualOS = proxyManager.getOS(localProject);
			assertNotNull(actualOS);
			assertTrue("Should have returned the OS name", !actualOS.isEmpty());
			/*
			 * Test got OS for remote URIs and project
			 */
			actualOS = proxyManager.getOS(syncProject);
			assertNotNull(actualOS);
			assertTrue("Should have returned the OS name", !actualOS.isEmpty());
		} catch (CoreException e) {
			fail("Unabled to get OS name: " + e.getMessage());
		}

		/*
		 * Test the proxy for unsupported URIs
		 */
		try {
			// As of org.eclipse.remote 2.0, remotetools scheme is no longer
			// support
			actualOS = proxyManager.getOS(URI.create("remotetools://MyConnection/path/to/file"));
			fail("remotetools scheme should not be recognized");
		} catch (CoreException e) {
			assertTrue(true);
		}
	}

	@Test
	public void testGetRemoteProjectLocationOnSyncProj() {
		try {
			String actualLocation = proxyManager.getRemoteProjectLocation(syncProject);
			SyncConfig config = getSyncConfig(syncProject);
			assertNotNull(config);
			assertEquals(this.connection.getConnectionType().getScheme(), URI.create(actualLocation).getScheme());
			assertEquals(config.getConnectionName(), URI.create(actualLocation).getAuthority());
			assertEquals(config.getLocation(),URI.create(actualLocation).getPath());
		} catch (CoreException e) {
			fail("Should have returned the remote project location: " + e.getMessage());
		}
	}
}

Back to the top