Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorslewis2014-10-15 01:54:20 -0400
committerslewis2014-10-15 01:54:20 -0400
commit95be0f16ba85abe08f88805dba1f2331b1a2ff87 (patch)
tree9e773e7d440fa9fd4acb5740bc7f110c136355a7 /tests
parent9ab0c39f091cae1abab806bf104f7e911fabaf56 (diff)
downloadorg.eclipse.ecf-95be0f16ba85abe08f88805dba1f2331b1a2ff87.tar.gz
org.eclipse.ecf-95be0f16ba85abe08f88805dba1f2331b1a2ff87.tar.xz
org.eclipse.ecf-95be0f16ba85abe08f88805dba1f2331b1a2ff87.zip
Robustness improvement for scp file browser implementation. Also
simplified test cases for scp retrieve, send, and browse. Change-Id: I8a307f852c0c010f633e68acd207880b8461d079
Diffstat (limited to 'tests')
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/AbstractSCPTest.java30
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/SCPOutgoingTest.java17
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/SCPRetrieveTest.java20
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/ScpFileBrowseTest.java111
4 files changed, 81 insertions, 97 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/AbstractSCPTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/AbstractSCPTest.java
new file mode 100644
index 000000000..6e6e03ca5
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/AbstractSCPTest.java
@@ -0,0 +1,30 @@
+package org.eclipse.ecf.tests.provider.filetransfer.scp;
+
+import org.eclipse.ecf.core.ContainerFactory;
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.tests.ContainerAbstractTestCase;
+
+public abstract class AbstractSCPTest extends ContainerAbstractTestCase {
+
+ protected String host = System.getProperty("host", "localhost"); //$NON-NLS-1$ //$NON-NLS-2$
+ protected String username = System.getProperty("username", "nobody"); //$NON-NLS-1$ //$NON-NLS-2$
+ protected String password = System.getProperty("password", "password"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ protected IContainer baseContainer;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.baseContainer = ContainerFactory.getDefault().createContainer();
+ }
+
+ protected void tearDown() throws Exception {
+ this.baseContainer.dispose();
+ this.baseContainer = null;
+ super.tearDown();
+ }
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/SCPOutgoingTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/SCPOutgoingTest.java
index c9698a133..1d6adaeeb 100755
--- a/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/SCPOutgoingTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/SCPOutgoingTest.java
@@ -21,21 +21,14 @@ import org.eclipse.ecf.filetransfer.ISendFileTransferContainerAdapter;
import org.eclipse.ecf.filetransfer.events.IFileTransferEvent;
import org.eclipse.ecf.filetransfer.identity.FileIDFactory;
import org.eclipse.ecf.filetransfer.identity.IFileID;
-import org.eclipse.ecf.tests.ContainerAbstractTestCase;
/**
*
*/
-public class SCPOutgoingTest extends ContainerAbstractTestCase {
+public class SCPOutgoingTest extends AbstractSCPTest {
- String sendFile = System.getProperty("sendFile", "test.txt"); //$NON-NLS-1$ //$NON-NLS-2$
-
- String host = System.getProperty("host", "localhost"); //$NON-NLS-1$ //$NON-NLS-2$
- String file = System.getProperty("file", "test.txt"); //$NON-NLS-1$ //$NON-NLS-2$
-
- // URL (example: scp://slewis@ecf1.osuosl.org/test.txt
- String username = System.getProperty("username", "nobody"); //$NON-NLS-1$ //$NON-NLS-2$
- String password = System.getProperty("password", "password"); //$NON-NLS-1$ //$NON-NLS-2$
+ private String localSendFile = System.getProperty("localSendFile", "test.txt"); //$NON-NLS-1$ //$NON-NLS-2$
+ private String targetSendFile = System.getProperty("targetSendFile", "test.txt"); //$NON-NLS-1$ //$NON-NLS-2$
protected ISendFileTransferContainerAdapter adapter = null;
protected IFileTransferListener senderTransferListener = null;
@@ -62,11 +55,11 @@ public class SCPOutgoingTest extends ContainerAbstractTestCase {
}
public void testSend() throws Exception {
- String targetURL = "scp://" + username + "@" + host + (file.startsWith("/") ? "" : "/") + file; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ String targetURL = "scp://" + username + "@" + host + (targetSendFile.startsWith("/") ? "" : "/") + targetSendFile; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
System.out.println("Sending to " + targetURL); //$NON-NLS-1$
final IFileID targetID = FileIDFactory.getDefault().createFileID(adapter.getOutgoingNamespace(), new URL(targetURL));
adapter.setConnectContextForAuthentication(ConnectContextFactory.createPasswordConnectContext(password));
- adapter.sendOutgoingRequest(targetID, new File(sendFile), senderTransferListener, null);
+ adapter.sendOutgoingRequest(targetID, new File(localSendFile), senderTransferListener, null);
sleep(10000);
}
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/SCPRetrieveTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/SCPRetrieveTest.java
index c07d2ce86..0a7a723a4 100755
--- a/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/SCPRetrieveTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/SCPRetrieveTest.java
@@ -14,25 +14,16 @@ package org.eclipse.ecf.tests.provider.filetransfer.scp;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.ecf.core.ContainerFactory;
-import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.security.ConnectContextFactory;
import org.eclipse.ecf.filetransfer.IFileTransferListener;
import org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter;
import org.eclipse.ecf.filetransfer.events.*;
import org.eclipse.ecf.filetransfer.identity.FileIDFactory;
-import org.eclipse.ecf.tests.ContainerAbstractTestCase;
-public class SCPRetrieveTest extends ContainerAbstractTestCase {
+public class SCPRetrieveTest extends AbstractSCPTest {
- String host = System.getProperty("host", "localhost"); //$NON-NLS-1$ //$NON-NLS-2$
- String file = System.getProperty("file", "test.txt"); //$NON-NLS-1$ //$NON-NLS-2$
-
- // URL (example: scp://slewis@ecf1.osuosl.org/test.txt
- String username = System.getProperty("username", "nobody"); //$NON-NLS-1$ //$NON-NLS-2$
- String password = System.getProperty("password", "password"); //$NON-NLS-1$ //$NON-NLS-2$
-
- IRetrieveFileTransferContainerAdapter adapter = null;
+ private String retrieveFile = System.getProperty("retrieveFile", "test.txt"); //$NON-NLS-1$ //$NON-NLS-2$
+ private IRetrieveFileTransferContainerAdapter adapter = null;
/*
* (non-Javadoc)
@@ -41,8 +32,7 @@ public class SCPRetrieveTest extends ContainerAbstractTestCase {
*/
protected void setUp() throws Exception {
super.setUp();
- final IContainer container = ContainerFactory.getDefault().createContainer();
- adapter = (IRetrieveFileTransferContainerAdapter) container.getAdapter(IRetrieveFileTransferContainerAdapter.class);
+ adapter = (IRetrieveFileTransferContainerAdapter) baseContainer.getAdapter(IRetrieveFileTransferContainerAdapter.class);
receiveStartEvents = new ArrayList();
receiveDataEvents = new ArrayList();
receiveDoneEvents = new ArrayList();
@@ -90,7 +80,7 @@ public class SCPRetrieveTest extends ContainerAbstractTestCase {
}
};
- String targetURL = "scp://" + host + (file.startsWith("/") ? "" : "/") + file; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ String targetURL = "scp://" + host + (retrieveFile.startsWith("/") ? "" : "/") + retrieveFile; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
System.out.println("Retrieving from " + targetURL + " with username=" + username); //$NON-NLS-1$ //$NON-NLS-2$
adapter.setConnectContextForAuthentication(ConnectContextFactory.createUsernamePasswordConnectContext(username, password));
adapter.sendRetrieveRequest(FileIDFactory.getDefault().createFileID(adapter.getRetrieveNamespace(), targetURL), listener, null);
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/ScpFileBrowseTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/ScpFileBrowseTest.java
index e7632b6ec..d1c5887bb 100644
--- a/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/ScpFileBrowseTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.scp/src/org/eclipse/ecf/tests/provider/filetransfer/scp/ScpFileBrowseTest.java
@@ -11,95 +11,66 @@
package org.eclipse.ecf.tests.provider.filetransfer.scp;
-import java.io.File;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import org.eclipse.ecf.core.ContainerFactory;
import org.eclipse.ecf.core.security.ConnectContextFactory;
-import org.eclipse.ecf.core.security.IConnectContext;
+import org.eclipse.ecf.filetransfer.*;
import org.eclipse.ecf.filetransfer.events.IRemoteFileSystemBrowseEvent;
-import org.eclipse.ecf.tests.filetransfer.AbstractBrowseTestCase;
+import org.eclipse.ecf.filetransfer.events.IRemoteFileSystemEvent;
+import org.eclipse.ecf.filetransfer.identity.FileIDFactory;
-public class ScpFileBrowseTest extends AbstractBrowseTestCase {
+public class ScpFileBrowseTest extends AbstractSCPTest {
- protected File[] roots;
+ private String browseDir = System.getProperty("browseDirectory", "/"); //$NON-NLS-1$ //$NON-NLS-2$
+ private IRemoteFileSystemBrowserContainerAdapter adapter = null;
- protected File[] files;
-
- // Using a countdown latch to wait until we get the proper number
- // of browse results
- CountDownLatch latch = new CountDownLatch(1);
-
- String username;
+ Throwable exception;
+ IRemoteFileSystemBrowseEvent browseEvent;
protected void setUp() throws Exception {
super.setUp();
- username = System.getProperty("user.name"); //$NON-NLS-1$
- IConnectContext cctx = ConnectContextFactory.createUsernamePasswordConnectContext(username, null);
-
- this.adapter.setConnectContextForAuthentication(cctx);
-
- roots = File.listRoots();
- List fList = new ArrayList();
- for (int i = 0; i < roots.length; i++) {
- final File[] fs = roots[i].listFiles();
- if (fs != null)
- for (int j = 0; j < fs.length; j++) {
- if (fs[j].exists())
- fList.add(fs[j]);
- }
- }
- this.files = (File[]) fList.toArray(new File[] {});
+ this.adapter = (IRemoteFileSystemBrowserContainerAdapter) ContainerFactory.getDefault().createContainer().getAdapter(IRemoteFileSystemBrowserContainerAdapter.class);
}
protected void tearDown() throws Exception {
+ this.adapter = null;
super.tearDown();
- this.roots = null;
- this.files = null;
}
- public void testBrowseRoots() throws Exception {
- latch = new CountDownLatch(roots.length);
- for (int i = 0; i < roots.length; i++) {
- if (roots[i].exists()) {
- URL url = new URL("scp://" + username + "@localhost:" + roots[i].getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$
- System.out.println("Browsing: " + url); //$NON-NLS-1$
- testBrowse(url);
- } else {
- System.out.println("Skipping: " + roots[i].toString()); //$NON-NLS-1$
- latch.countDown();
+ public void testFileBrowse() throws Exception {
+ assertNotNull(adapter);
+ IRemoteFileSystemListener listener = new IRemoteFileSystemListener() {
+ public void handleRemoteFileEvent(IRemoteFileSystemEvent event) {
+ System.out.println("localhost.handleRemoteFileEvent=" + event); //$NON-NLS-1$
+ if (event instanceof IRemoteFileSystemBrowseEvent) {
+ exception = event.getException();
+ if (exception == null) {
+ browseEvent = (IRemoteFileSystemBrowseEvent) event;
+ syncNotify();
+ }
+ }
}
- // Need to sleep to give the connection time to close out
- Thread.sleep(100);
- }
- assertTrue(latch.await(60, TimeUnit.SECONDS));
- }
+ };
+ String targetURL = "scp://" + host + browseDir; //$NON-NLS-1$
+ System.out.println("Browsing targetURL=" + targetURL + " with username=" + username); //$NON-NLS-1$ //$NON-NLS-2$
+ adapter.setConnectContextForAuthentication(ConnectContextFactory.createUsernamePasswordConnectContext(username, password));
+ adapter.sendBrowseRequest(FileIDFactory.getDefault().createFileID(adapter.getBrowseNamespace(), targetURL), listener);
+
+ syncWaitForNotify(60000);
+
+ assertNotNull(browseEvent);
- protected void handleFileSystemBrowseEvent(IRemoteFileSystemBrowseEvent event) {
- trace("handleFileSystemBrowseEvent(" + event + ")"); //$NON-NLS-1$ //$NON-NLS-2$
- if (event.getException() != null) {
- trace(event.getException().toString());
+ IRemoteFile[] remoteFiles = browseEvent.getRemoteFiles();
+ assertNotNull(remoteFiles);
+ assertTrue(remoteFiles.length > 1);
+
+ for (int i = 0; i < remoteFiles.length; i++) {
+ IRemoteFileInfo fInfo = remoteFiles[i].getInfo();
+ System.out.println("directory entry=" + i + ";id=" + remoteFiles[i].getID() + ";name=" + fInfo.getName() + ";isDirectory=" + fInfo.isDirectory() + ";size=" + fInfo.getLength() + ";lastModified=" + fInfo.getLastModified()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
}
- latch.countDown();
}
- public void testFileBrowse() throws Exception {
- latch = new CountDownLatch(files.length);
- for (int i = 0; i < files.length; i++) {
- if (files[i].isDirectory() && files[i].exists()) {
- URL url = new URL("scp://" + username + "@localhost:" + files[i].getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$
- System.out.println("Browsing: " + url); //$NON-NLS-1$
- testBrowse(url);
- } else {
- System.out.println("Skipping: " + files[i].toString()); //$NON-NLS-1$
- latch.countDown();
- }
- // Need to sleep to give the connection time to close out
- Thread.sleep(100);
- }
- assertTrue(latch.await(60, TimeUnit.SECONDS));
+ public void syncNotify() {
+ super.syncNotify();
}
}

Back to the top