Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/META-INF/MANIFEST.MF3
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/src/org/eclipse/ecf/tests/provider/filetransfer/xmpp/XMPPOutgoingTest.java166
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/src/org/eclipse/ecf/tests/provider/filetransfer/xmpp/XMPPSOutgoingTest.java210
-rw-r--r--[-rwxr-xr-x]tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/test.src/test.txt (renamed from tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/test.target/test.txt)0
4 files changed, 93 insertions, 286 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/META-INF/MANIFEST.MF b/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/META-INF/MANIFEST.MF
index 125cf9502..f228ba49b 100755
--- a/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/META-INF/MANIFEST.MF
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/META-INF/MANIFEST.MF
@@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ecf.tests,
org.eclipse.ecf.tests.filetransfer,
org.eclipse.ecf,
- org.eclipse.ecf.filetransfer
+ org.eclipse.ecf.filetransfer,
+ org.eclipse.equinox.concurrent
Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
J2SE-1.4
Eclipse-LazyStart: true
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/src/org/eclipse/ecf/tests/provider/filetransfer/xmpp/XMPPOutgoingTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/src/org/eclipse/ecf/tests/provider/filetransfer/xmpp/XMPPOutgoingTest.java
index 23ce5f7b1..ec5802a3e 100755
--- a/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/src/org/eclipse/ecf/tests/provider/filetransfer/xmpp/XMPPOutgoingTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/src/org/eclipse/ecf/tests/provider/filetransfer/xmpp/XMPPOutgoingTest.java
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2004 Composent, Inc. and others.
+ * Copyright (c) 2004, 2015 Composent, 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
@@ -14,17 +14,16 @@ package org.eclipse.ecf.tests.provider.filetransfer.xmpp;
import java.io.File;
import java.io.FileOutputStream;
-import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.core.identity.IDFactory;
-import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.filetransfer.IFileTransferListener;
import org.eclipse.ecf.filetransfer.IIncomingFileTransferRequestListener;
+import org.eclipse.ecf.filetransfer.IOutgoingFileTransfer;
import org.eclipse.ecf.filetransfer.ISendFileTransferContainerAdapter;
import org.eclipse.ecf.filetransfer.events.IFileTransferEvent;
import org.eclipse.ecf.filetransfer.events.IFileTransferRequestEvent;
-import org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent;
+import org.eclipse.ecf.filetransfer.events.IOutgoingFileTransferResponseEvent;
import org.eclipse.ecf.filetransfer.identity.FileCreateException;
import org.eclipse.ecf.filetransfer.identity.FileIDFactory;
import org.eclipse.ecf.filetransfer.identity.IFileID;
@@ -40,77 +39,118 @@ public class XMPPOutgoingTest extends ContainerAbstractTestCase {
private static final String TESTTARGETPATH = "test.target";
- static final String XMPP_CONTAINER = "ecf.xmpp.smack";
+ static final String XMPP_CONTAINER = "ecf.xmpps.smack";
- protected ISendFileTransferContainerAdapter adapter0, adapter1 = null;
+ ISendFileTransferContainerAdapter adapter0, adapter1 = null;
+ IOutgoingFileTransfer outgoing;
+ File incomingDirectory;
+ File incomingFile;
+ IFileID targetID;
- protected String getClientContainerName() {
- return XMPP_CONTAINER;
- }
+ protected IIncomingFileTransferRequestListener requestListener = new IIncomingFileTransferRequestListener() {
- protected ISendFileTransferContainerAdapter getOutgoingFileTransfer(int client) {
- final IContainer c = getClient(client);
- if (c != null)
- return (ISendFileTransferContainerAdapter) c.getAdapter(ISendFileTransferContainerAdapter.class);
- else
- return null;
- }
+ public void handleFileTransferRequest(IFileTransferRequestEvent event) {
+ System.out.println("receiver.handleFileTransferRequest(" + event
+ + ")");
+ incomingDirectory = new File(TESTTARGETPATH);
+ incomingDirectory.mkdirs();
+ incomingFile = new File(incomingDirectory, event
+ .getFileTransferInfo().getFile().getName());
+ try {
+ // accept the request
+ event.accept(new FileOutputStream(incomingFile),
+ receiverTransferListener);
+ } catch (Exception e) {
+ e.printStackTrace(System.err);
+ fail("exception calling accept for receive file transfer");
+ }
+ }
+
+ };
- protected IFileTransferListener getFileTransferListener(final String prefix) {
- return new IFileTransferListener() {
- public void handleTransferEvent(IFileTransferEvent event) {
- System.out.println(prefix + ".handleTransferEvent(" + event + ")");
- if (event instanceof IIncomingFileTransferReceiveDoneEvent) {
+ private IFileTransferListener receiverTransferListener = new IFileTransferListener() {
+ public void handleTransferEvent(IFileTransferEvent event) {
+ System.out.println("sender.handleTransferEvent(" + event + ")");
+ }
+ };
- }
+ private IFileTransferListener senderTransferListener = new IFileTransferListener() {
+ public void handleTransferEvent(IFileTransferEvent event) {
+ System.out.println("receiver.handleTransferEvent(" + event + ")");
+ if (event instanceof IOutgoingFileTransferResponseEvent) {
+ final IOutgoingFileTransferResponseEvent revent = (IOutgoingFileTransferResponseEvent) event;
+ outgoing = revent.getSource();
}
- };
- }
+ }
+ };
- File incomingDirectory = null;
- File incomingFile = null;
+ protected void setUp() throws Exception {
+ super.setUp();
+ setClientCount(2);
+ // Create two clients
+ clients = createClients();
+ // Connect clients
+ for (int i = 0; i < 2; i++)
+ connectClient(i);
+ adapter0 = getOutgoingFileTransfer(0);
+ // 0 is the receiver, so has to listen for
+ // file transfer requests
+ adapter0.addListener(requestListener);
+ // 1 is the sender
+ adapter1 = getOutgoingFileTransfer(1);
+ // Target ID is client 0's connectedID (includes resource name now that
+ // connected)
+ targetID = createFileID(adapter1, getClient(0).getConnectedID(),
+ TESTSRCFILE);
+ }
- /* (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
- */
protected void tearDown() throws Exception {
super.tearDown();
+ disconnectClients();
if (incomingFile != null)
incomingFile.delete();
incomingFile = null;
if (incomingDirectory != null)
incomingDirectory.delete();
incomingDirectory = null;
+ outgoing = null;
+ targetID = null;
}
- protected IIncomingFileTransferRequestListener requestListener = new IIncomingFileTransferRequestListener() {
+ public void testTwoClientsToSendAndReceive() throws Exception {
+ // Initiate send request
+ adapter1.sendOutgoingRequest(targetID, new File(TESTSRCFILE),
+ senderTransferListener, null);
- public void handleFileTransferRequest(IFileTransferRequestEvent event) {
- System.out.println("receiver.handleFileTransferRequest(" + event + ")");
- incomingDirectory = new File(TESTTARGETPATH);
- incomingDirectory.mkdirs();
- incomingFile = new File(incomingDirectory, event.getFileTransferInfo().getFile().getName());
- try {
- FileOutputStream fos = new FileOutputStream(incomingFile);
- event.accept(fos, receiverTransferListener);
- //event.accept(f);
- } catch (Exception e) {
- e.printStackTrace(System.err);
- fail("exception calling accept for receive file transfer");
- }
- }
+ syncWaitForNotify(40000);
- };
+ assertNotNull(outgoing);
+ assertNull(outgoing.getException());
+ assertNotNull(incomingFile);
+ assertTrue(incomingFile.exists());
+ }
- protected IFileTransferListener senderTransferListener = getFileTransferListener("sender");
- protected IFileTransferListener receiverTransferListener = getFileTransferListener("receiver");
+ protected String getClientContainerName() {
+ return XMPP_CONTAINER;
+ }
+
+ private ISendFileTransferContainerAdapter getOutgoingFileTransfer(int client) {
+ return (ISendFileTransferContainerAdapter) getClient(client)
+ .getAdapter(ISendFileTransferContainerAdapter.class);
+ }
+
+ protected IFileID createFileID(ISendFileTransferContainerAdapter adapter,
+ ID clientID, String filename) throws FileCreateException {
+ return FileIDFactory.getDefault().createFileID(
+ adapter.getOutgoingNamespace(),
+ new Object[] { clientID, filename });
+ }
protected ID getServerConnectID(int client) {
- final IContainer container = getClient(client);
- final Namespace connectNamespace = container.getConnectNamespace();
- final String username = getUsername(client);
try {
- return IDFactory.getDefault().createID(connectNamespace, username);
+ return IDFactory.getDefault().createID(
+ getClient(client).getConnectNamespace(),
+ getUsername(client));
} catch (final IDCreateException e) {
e.printStackTrace(System.err);
fail("Could not create server connect ID");
@@ -118,28 +158,4 @@ public class XMPPOutgoingTest extends ContainerAbstractTestCase {
}
}
- protected IFileID createFileID(ISendFileTransferContainerAdapter adapter, ID clientID, String filename) throws FileCreateException {
- return FileIDFactory.getDefault().createFileID(adapter.getOutgoingNamespace(), new Object[] {clientID, filename});
- }
-
- public void testTwoClientsToSendAndReceive() throws Exception {
- // Setup two clients. Client 0 is the receiver, client 1 is the sender
- setClientCount(2);
- clients = createClients();
- adapter0 = getOutgoingFileTransfer(0);
- adapter0.addListener(requestListener);
- adapter1 = getOutgoingFileTransfer(1);
- for (int i = 0; i < 2; i++) {
- connectClient(i);
- }
-
- final IFileID targetID = createFileID(adapter1, getServerConnectID(0), TESTSRCFILE);
- adapter1.sendOutgoingRequest(targetID, new File(TESTSRCFILE), senderTransferListener, null);
-
- sleep(20000);
-
- disconnectClients();
-
- }
-
}
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/src/org/eclipse/ecf/tests/provider/filetransfer/xmpp/XMPPSOutgoingTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/src/org/eclipse/ecf/tests/provider/filetransfer/xmpp/XMPPSOutgoingTest.java
deleted file mode 100755
index 5db56b327..000000000
--- a/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/src/org/eclipse/ecf/tests/provider/filetransfer/xmpp/XMPPSOutgoingTest.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/****************************************************************************
- * Copyright (c) 2004 Composent, 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:
- * Composent, Inc. - initial API and implementation
- *****************************************************************************/
-
-package org.eclipse.ecf.tests.provider.filetransfer.xmpp;
-
-import java.io.File;
-import java.io.FileOutputStream;
-
-import org.eclipse.ecf.core.IContainer;
-import org.eclipse.ecf.core.identity.ID;
-import org.eclipse.ecf.core.identity.IDCreateException;
-import org.eclipse.ecf.core.identity.IDFactory;
-import org.eclipse.ecf.core.identity.Namespace;
-import org.eclipse.ecf.filetransfer.IFileTransferListener;
-import org.eclipse.ecf.filetransfer.IIncomingFileTransferRequestListener;
-import org.eclipse.ecf.filetransfer.IOutgoingFileTransfer;
-import org.eclipse.ecf.filetransfer.ISendFileTransferContainerAdapter;
-import org.eclipse.ecf.filetransfer.UserCancelledException;
-import org.eclipse.ecf.filetransfer.events.IFileTransferEvent;
-import org.eclipse.ecf.filetransfer.events.IFileTransferRequestEvent;
-import org.eclipse.ecf.filetransfer.events.IOutgoingFileTransferResponseEvent;
-import org.eclipse.ecf.filetransfer.identity.FileCreateException;
-import org.eclipse.ecf.filetransfer.identity.FileIDFactory;
-import org.eclipse.ecf.filetransfer.identity.IFileID;
-import org.eclipse.ecf.tests.ContainerAbstractTestCase;
-
-/**
- *
- */
-public class XMPPSOutgoingTest extends ContainerAbstractTestCase {
-
- private static final String TESTSRCPATH = "test.src";
- private static final String TESTSRCFILE = TESTSRCPATH + "/test.txt";
-
- private static final String TESTTARGETPATH = "test.target";
-
- static final String XMPP_CONTAINER = "ecf.xmpps.smack";
-
- protected ISendFileTransferContainerAdapter adapter0, adapter1 = null;
-
- protected IOutgoingFileTransfer outgoing;
-
- protected IFileID targetID;
-
- protected Object lock = new Object();
-
- protected String getClientContainerName() {
- return XMPP_CONTAINER;
- }
-
- protected ISendFileTransferContainerAdapter getOutgoingFileTransfer(int client) {
- final IContainer c = getClient(client);
- if (c != null)
- return (ISendFileTransferContainerAdapter) c.getAdapter(ISendFileTransferContainerAdapter.class);
- else
- return null;
- }
-
- protected IFileTransferListener getSenderFileTransferListener(final String prefix) {
- return new IFileTransferListener() {
- public void handleTransferEvent(IFileTransferEvent event) {
- System.out.println(prefix + ".handleTransferEvent(" + event + ")");
- if (event instanceof IOutgoingFileTransferResponseEvent) {
- final IOutgoingFileTransferResponseEvent revent = (IOutgoingFileTransferResponseEvent) event;
- outgoing = revent.getSource();
- synchronized (lock) {
- lock.notify();
- }
- }
- }
- };
- }
-
- protected IFileTransferListener getReceiverFileTransferListener(final String prefix) {
- return new IFileTransferListener() {
- public void handleTransferEvent(IFileTransferEvent event) {
- System.out.println(prefix + ".handleTransferEvent(" + event + ")");
- }
- };
- }
-
- File incomingDirectory = null;
- File incomingFile = null;
-
- /* (non-Javadoc)
- * @see org.eclipse.ecf.tests.ContainerAbstractTestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- setClientCount(2);
- clients = createClients();
- adapter0 = getOutgoingFileTransfer(0);
- adapter0.addListener(requestListener);
- adapter1 = getOutgoingFileTransfer(1);
- for (int i = 0; i < 2; i++) {
- connectClient(i);
- }
- targetID = createFileID(adapter1, getServerConnectID(0), TESTSRCFILE);
- }
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- disconnectClients();
- if (incomingFile != null)
- incomingFile.delete();
- incomingFile = null;
- if (incomingDirectory != null)
- incomingDirectory.delete();
- incomingDirectory = null;
- outgoing = null;
- targetID = null;
- }
-
- protected IIncomingFileTransferRequestListener requestListener = new IIncomingFileTransferRequestListener() {
-
- public void handleFileTransferRequest(IFileTransferRequestEvent event) {
- System.out.println("receiver.handleFileTransferRequest(" + event + ")");
- incomingDirectory = new File(TESTTARGETPATH);
- incomingDirectory.mkdirs();
- incomingFile = new File(incomingDirectory, event.getFileTransferInfo().getFile().getName());
- try {
- FileOutputStream fos = new FileOutputStream(incomingFile);
- event.accept(fos, receiverTransferListener);
- //event.accept(f);
- } catch (Exception e) {
- e.printStackTrace(System.err);
- fail("exception calling accept for receive file transfer");
- }
- }
-
- };
-
- protected IFileTransferListener senderTransferListener = getSenderFileTransferListener("sender");
- protected IFileTransferListener receiverTransferListener = getReceiverFileTransferListener("receiver");
-
- protected ID getServerConnectID(int client) {
- final IContainer container = getClient(client);
- final Namespace connectNamespace = container.getConnectNamespace();
- final String username = getUsername(client);
- try {
- return IDFactory.getDefault().createID(connectNamespace, username);
- } catch (final IDCreateException e) {
- e.printStackTrace(System.err);
- fail("Could not create server connect ID");
- return null;
- }
- }
-
- /*
- public void testOneClientToSend() throws Exception {
- // Setup one client. Client 0 is the sender
- setClientCount(2);
- clients = createClients();
- adapter0 = getOutgoingFileTransfer(0);
- for (int i = 0; i < 1; i++) {
- // Only connect client 0 (not client 1)
- connectClient(i);
- }
-
- adapter0.sendOutgoingRequest(getServerConnectID(1), new File(
- TESTSRCFILE), senderTransferListener, null);
- sleep(200000);
-
- disconnectClients();
-
- }
- */
-
- protected IFileID createFileID(ISendFileTransferContainerAdapter adapter, ID clientID, String filename) throws FileCreateException {
- return FileIDFactory.getDefault().createFileID(adapter.getOutgoingNamespace(), new Object[] {clientID, filename});
- }
-
- public void testTwoClientsToSendAndReceive() throws Exception {
- // Setup two clients. Client 0 is the receiver, client 1 is the sender
- adapter1.sendOutgoingRequest(targetID, new File(TESTSRCFILE), senderTransferListener, null);
-
- sleep(5000);
- }
-
- public void testSenderCancel() throws Exception {
- // Setup two clients. Client 0 is the receiver, client 1 is the sender
- adapter1.sendOutgoingRequest(targetID, new File(TESTSRCFILE), senderTransferListener, null);
-
- synchronized (lock) {
- lock.wait();
- }
- assertTrue(outgoing != null);
-
- // Now cancel
- outgoing.cancel();
- // wait a short while
- sleep(500);
-
- final Exception e = outgoing.getException();
- assertTrue(e != null && e instanceof UserCancelledException);
-
- }
-
-}
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/test.target/test.txt b/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/test.src/test.txt
index e69de29bb..e69de29bb 100755..100644
--- a/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/test.target/test.txt
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.filetransfer.xmpp/test.src/test.txt

Back to the top