Search in sources :

Example 1 with RDTFileProxy

use of org.eclipse.linuxtools.internal.rdt.proxy.RDTFileProxy in project linuxtools by eclipse.

the class FileProxyTest method testRemoteFileProxyOnSyncProject.

@Test
public void testRemoteFileProxyOnSyncProject() {
    IRemoteFileProxy fileProxy = null;
    try {
        fileProxy = proxyManager.getFileProxy(syncProject.getProject());
        assertTrue("Should have returned a remote launcher", fileProxy instanceof RDTFileProxy);
    } catch (CoreException e) {
        fail("Should have returned a launcher: " + e.getCause());
    }
    String ds = fileProxy.getDirectorySeparator();
    assertNotNull(ds);
    SyncConfig config = getSyncConfig(syncProject.getProject());
    String projectLocation = config.getLocation();
    assertNotNull(projectLocation);
    IRemoteConnection conn = null;
    String connScheme = null;
    try {
        conn = config.getRemoteConnection();
        connScheme = conn.getConnectionType().getScheme();
    } catch (MissingConnectionException e) {
        fail("Unabled to get remote connection: " + e.getMessage());
    }
    /*
		 *  Test getResource()
		 */
    IFileStore fs = fileProxy.getResource(projectLocation);
    assertNotNull(fs);
    assertEquals("Remote connection and FileStore schemes diverge", connScheme, fs.toURI().getScheme());
    // assertTrue(fs.fetchInfo().isDirectory());
    fs = fileProxy.getResource("/filenotexits");
    assertNotNull(fs);
    IFileInfo fileInfo = fs.fetchInfo();
    assertNotNull(fileInfo);
    assertFalse(fileInfo.exists());
    /*
		 * Test getWorkingDir()
		 */
    URI workingDir = fileProxy.getWorkingDir();
    assertNotNull(workingDir);
    assertEquals("Remote connection and URI schemes diverge", connScheme, workingDir.getScheme());
    /*
		 * Test toPath()
		 */
    URI uri = null;
    try {
        uri = new URI(connScheme, conn.getName(), projectLocation, null, null);
    } catch (URISyntaxException e) {
        fail("Failed to build URI for the test: " + e.getMessage());
    }
    assertEquals(projectLocation, fileProxy.toPath(uri));
    /*
		 * Test it opens connection
		 */
    assertNotNull(conn);
    conn.close();
    assertFalse(conn.isOpen());
    try {
        fileProxy = proxyManager.getFileProxy(syncProject.getProject());
        assertNotNull(fileProxy);
    } catch (CoreException e) {
        fail("Failed to obtain file proxy when connection is closed: " + e.getMessage());
    }
    fs = fileProxy.getResource("/tmp/somedir");
    assertNotNull(fs);
    assertFalse(fs.fetchInfo().exists());
    try {
        fs.mkdir(EFS.SHALLOW, new NullProgressMonitor());
    } catch (CoreException e) {
        fail("should be able to create a directory when connection is closed: " + e.getMessage());
    }
    assertTrue(fs.fetchInfo().exists());
    try {
        fs.delete(EFS.NONE, new NullProgressMonitor());
    } catch (CoreException e) {
        fail("Failed to delete file: " + e.getMessage());
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFileInfo(org.eclipse.core.filesystem.IFileInfo) CoreException(org.eclipse.core.runtime.CoreException) IRemoteConnection(org.eclipse.remote.core.IRemoteConnection) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) RDTFileProxy(org.eclipse.linuxtools.internal.rdt.proxy.RDTFileProxy) IFileStore(org.eclipse.core.filesystem.IFileStore) SyncConfig(org.eclipse.ptp.rdt.sync.core.SyncConfig) URISyntaxException(java.net.URISyntaxException) MissingConnectionException(org.eclipse.ptp.rdt.sync.core.exceptions.MissingConnectionException) URI(java.net.URI) AbstractProxyTest(org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest) Test(org.junit.Test)

Example 2 with RDTFileProxy

use of org.eclipse.linuxtools.internal.rdt.proxy.RDTFileProxy in project linuxtools by eclipse.

the class RemoteProxyManagerTest method testGetFileProxy.

@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);
        /*
			 * Test the proxy for jsch connection scheme
			 */
        fp = proxyManager.getFileProxy(URI.create("jsch://" + USERNAME + "@" + HOST + ":22/path/to/file"));
        assertTrue("Should have returned a remote file proxy", fp instanceof SSHFileProxy);
    } 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(e.getMessage(), true);
    }
}
Also used : LocalFileProxy(org.eclipse.linuxtools.internal.profiling.launch.LocalFileProxy) CoreException(org.eclipse.core.runtime.CoreException) SSHFileProxy(org.eclipse.linuxtools.internal.ssh.proxy.SSHFileProxy) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) RDTFileProxy(org.eclipse.linuxtools.internal.rdt.proxy.RDTFileProxy) AbstractProxyTest(org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest) Test(org.junit.Test)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)2 RDTFileProxy (org.eclipse.linuxtools.internal.rdt.proxy.RDTFileProxy)2 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)2 AbstractProxyTest (org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest)2 Test (org.junit.Test)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 IFileInfo (org.eclipse.core.filesystem.IFileInfo)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 LocalFileProxy (org.eclipse.linuxtools.internal.profiling.launch.LocalFileProxy)1 SSHFileProxy (org.eclipse.linuxtools.internal.ssh.proxy.SSHFileProxy)1 SyncConfig (org.eclipse.ptp.rdt.sync.core.SyncConfig)1 MissingConnectionException (org.eclipse.ptp.rdt.sync.core.exceptions.MissingConnectionException)1 IRemoteConnection (org.eclipse.remote.core.IRemoteConnection)1