Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2009-03-13 04:18:19 +0000
committerslewis2009-03-13 04:18:19 +0000
commite4bd422a5f9ef8eb581ea3e52a872242a4d45afb (patch)
tree114faf93384cf26909ec11b10096157710a45c46 /tests/bundles/org.eclipse.ecf.tests.remoteservice
parentc8a84e5f88f0dd1a579fff26bc82410814b1211c (diff)
downloadorg.eclipse.ecf-e4bd422a5f9ef8eb581ea3e52a872242a4d45afb.tar.gz
org.eclipse.ecf-e4bd422a5f9ef8eb581ea3e52a872242a4d45afb.tar.xz
org.eclipse.ecf-e4bd422a5f9ef8eb581ea3e52a872242a4d45afb.zip
Added tests and corrected others
Diffstat (limited to 'tests/bundles/org.eclipse.ecf.tests.remoteservice')
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests.remoteservice/META-INF/MANIFEST.MF5
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatClient.java83
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatServer.java61
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleTest.java138
4 files changed, 286 insertions, 1 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice/META-INF/MANIFEST.MF b/tests/bundles/org.eclipse.ecf.tests.remoteservice/META-INF/MANIFEST.MF
index d45abe312..712edd9af 100755
--- a/tests/bundles/org.eclipse.ecf.tests.remoteservice/META-INF/MANIFEST.MF
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice/META-INF/MANIFEST.MF
@@ -13,7 +13,10 @@ Require-Bundle: org.eclipse.equinox.common,
org.junit
Eclipse-LazyStart: true
Export-Package: org.eclipse.ecf.tests.remoteservice
-Import-Package: org.eclipse.equinox.concurrent.future;version="1.0.0",
+Import-Package: org.eclipse.ecf.provider.generic,
+ org.eclipse.ecf.server.generic,
+ org.eclipse.equinox.concurrent.future;version="1.0.0",
+ org.eclipse.osgi.util,
org.osgi.framework;version="1.4.0",
org.osgi.util.tracker;version="1.3.3"
Bundle-ActivationPolicy: lazy
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatClient.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatClient.java
new file mode 100644
index 000000000..050454d88
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatClient.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+* Copyright (c) 2009 EclipseSource 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:
+* EclipseSource - initial API and implementation
+******************************************************************************/
+package org.eclipse.ecf.tests.remoteservice.generic;
+
+import org.eclipse.ecf.core.ContainerFactory;
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.remoteservice.IRemoteService;
+import org.eclipse.ecf.remoteservice.IRemoteServiceContainer;
+import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
+import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
+import org.eclipse.ecf.remoteservice.RemoteServiceContainer;
+import org.eclipse.ecf.tests.remoteservice.IConcatService;
+import org.eclipse.osgi.util.NLS;
+
+public class SimpleConcatClient {
+
+ public static final String CLIENT_TYPE = "ecf.generic.client";
+
+ private IRemoteServiceContainer rsContainer;
+
+ protected String SERVER_ID = "ecftcp://localhost:{0}"+SimpleConcatServer.PATH;
+
+ private IRemoteServiceReference rsReference;
+ private IRemoteService remoteService;
+
+ public synchronized IRemoteService getRemoteService() {
+ if (remoteService == null) {
+ remoteService = rsContainer.getContainerAdapter().getRemoteService(rsReference);
+ }
+ return remoteService;
+ }
+
+ public void start() throws Exception {
+ IContainer client = ContainerFactory.getDefault().createContainer(
+ CLIENT_TYPE);
+ // Get adapter for accessing remote services
+ IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter) client
+ .getAdapter(IRemoteServiceContainerAdapter.class);
+
+ rsContainer = new RemoteServiceContainer(client,adapter);
+
+ System.out.println("Client created with ID=" + client.getID());
+
+ ID connectTargetID = IDFactory.getDefault().createStringID(
+ NLS.bind(SERVER_ID, new Integer(SimpleConcatServer.PORT)));
+
+ client.connect(connectTargetID, null);
+ System.out.println("Client connected to connectTargetID="
+ + connectTargetID);
+
+ Thread.sleep(1000);
+
+
+ // Get remote service reference
+ IRemoteServiceReference[] refs = adapter.getRemoteServiceReferences(
+ null, IConcatService.class.getName(), null);
+
+ rsReference = refs[0];
+
+ System.out.println("Remote service with ref=" + refs[0]);
+ }
+
+ public void stop() {
+ if (rsContainer != null) {
+ rsContainer.getContainerAdapter().ungetRemoteService(rsReference);
+ remoteService = null;
+ rsReference = null;
+ rsContainer.getContainer().disconnect();
+ rsContainer = null;
+ }
+
+ }
+
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatServer.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatServer.java
new file mode 100644
index 000000000..e859cb539
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleConcatServer.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+* Copyright (c) 2009 EclipseSource 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:
+* EclipseSource - initial API and implementation
+******************************************************************************/
+package org.eclipse.ecf.tests.remoteservice.generic;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
+import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration;
+import org.eclipse.ecf.server.generic.GenericServerContainer;
+import org.eclipse.ecf.server.generic.SimpleGenericServer;
+import org.eclipse.ecf.tests.remoteservice.IConcatService;
+
+public class SimpleConcatServer {
+
+ public static final int PORT = 32100;
+ public static final String PATH = "/server";
+ public static final String HOST = "localhost";
+ public static final int KEEPALIVE = 30000;
+
+ private IRemoteServiceRegistration registration = null;
+ private SimpleGenericServer server;
+
+ public class ConcatService implements IConcatService {
+
+ public String concat(String string1, String string2) {
+ System.out.println("server.concat("+string1+","+string2+")");
+ return string1+string2;
+ }
+
+ }
+ public void start() throws Exception {
+ // Start server
+ server = new SimpleGenericServer(HOST,PORT);
+ server.start(PATH, KEEPALIVE);
+
+ GenericServerContainer serverContainer = server.getServerContainer(0);
+ IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter) serverContainer.getAdapter(IRemoteServiceContainerAdapter.class);
+ Assert.isNotNull(adapter);
+ registration = adapter.registerRemoteService(new String[] { IConcatService.class.getName() }, new ConcatService(), null);
+ Assert.isNotNull(registration);
+ }
+
+ public IRemoteServiceRegistration getConcatServiceRegistration() {
+ return registration;
+ }
+
+ public void stop() {
+ if (registration != null) {
+ registration.unregister();
+ registration = null;
+ }
+ server.stop();
+ server = null;
+ }
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleTest.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleTest.java
new file mode 100644
index 000000000..765ffacaf
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/generic/SimpleTest.java
@@ -0,0 +1,138 @@
+/*******************************************************************************
+* Copyright (c) 2009 EclipseSource 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:
+* EclipseSource - initial API and implementation
+******************************************************************************/
+package org.eclipse.ecf.tests.remoteservice.generic;
+
+import org.eclipse.ecf.remoteservice.IRemoteCall;
+import org.eclipse.ecf.remoteservice.IRemoteCallListener;
+import org.eclipse.ecf.remoteservice.IRemoteService;
+import org.eclipse.ecf.remoteservice.events.IRemoteCallCompleteEvent;
+import org.eclipse.ecf.remoteservice.events.IRemoteCallEvent;
+import org.eclipse.ecf.tests.remoteservice.IConcatService;
+import org.eclipse.equinox.concurrent.future.IFuture;
+
+import junit.framework.TestCase;
+
+public class SimpleTest extends TestCase {
+
+ public static final String TEST_STRING_1 = "foo";
+ public static final String TEST_STRING_2 = "bar";
+
+ SimpleConcatServer server;
+ SimpleConcatClient client;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ server = new SimpleConcatServer();
+ server.start();
+ client = new SimpleConcatClient();
+ client.start();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ client.stop();
+ client = null;
+ server.stop();
+ server = null;
+ }
+
+ public void testSimpleClientAndServerWithProxy() throws Exception {
+
+ IRemoteService remoteService = client.getRemoteService();
+ assertNotNull(remoteService);
+ // Use proxy
+ String result = ((IConcatService) remoteService.getProxy()).concat(TEST_STRING_1,TEST_STRING_2);
+ assertTrue(result != null && result.equals(TEST_STRING_1+TEST_STRING_2));
+
+ }
+
+ private IRemoteCall getRemoteConcatCall(final String first, final String second) {
+ return new IRemoteCall() {
+
+ public String getMethod() {
+ return "concat";
+ }
+
+ public Object[] getParameters() {
+ return new String[] { first, second };
+ }
+
+ public long getTimeout() {
+ return 3000;
+ }};
+ }
+
+ public void testSimpleClientAndServerWithCallSync() throws Exception {
+
+ IRemoteService remoteService = client.getRemoteService();
+ assertNotNull(remoteService);
+ // Use callSync
+ String result = (String) remoteService.callSync(getRemoteConcatCall(TEST_STRING_2, TEST_STRING_1));
+ assertTrue(result != null && result.equals(TEST_STRING_2+TEST_STRING_1));
+
+ }
+
+ public void testSimpleClientAndServerWithFireAsync() throws Exception {
+
+ IRemoteService remoteService = client.getRemoteService();
+ assertNotNull(remoteService);
+ // Use callSync
+ remoteService.fireAsync(getRemoteConcatCall(TEST_STRING_2, TEST_STRING_1));
+
+ Thread.sleep(1000);
+
+ }
+
+ public void testSimpleClientAndServerWithCallAsync() throws Exception {
+
+ IRemoteService remoteService = client.getRemoteService();
+ assertNotNull(remoteService);
+ // Use callSync
+ remoteService.callAsync(getRemoteConcatCall(TEST_STRING_2, TEST_STRING_1));
+
+ Thread.sleep(1000);
+
+ }
+
+ String result = null;
+
+ public void testSimpleClientAndServerWithCallAsyncListener() throws Exception {
+
+ IRemoteService remoteService = client.getRemoteService();
+ assertNotNull(remoteService);
+ // Use callSync
+ remoteService.callAsync(getRemoteConcatCall(TEST_STRING_2, TEST_STRING_1),new IRemoteCallListener(){
+ public void handleEvent(IRemoteCallEvent event) {
+ if (event instanceof IRemoteCallCompleteEvent) {
+ result = (String) ((IRemoteCallCompleteEvent) event).getResponse();
+ }
+ }
+ });
+
+ Thread.sleep(1000);
+
+ assertNotNull(result);
+ assertTrue(result.equals(TEST_STRING_2+TEST_STRING_1));
+
+ }
+
+ public void testSimpleClientAndServerWithFuture() throws Exception {
+
+ IRemoteService remoteService = client.getRemoteService();
+ assertNotNull(remoteService);
+ // Use callSync
+ IFuture future = remoteService.callAsync(getRemoteConcatCall(TEST_STRING_2, TEST_STRING_1));
+ assertNotNull(future);
+ String result = (String) future.get();
+ assertTrue(result.equals(TEST_STRING_2+TEST_STRING_1));
+ }
+
+
+}

Back to the top