diff options
author | slewis | 2009-05-09 22:49:46 +0000 |
---|---|---|
committer | slewis | 2009-05-09 22:49:46 +0000 |
commit | 3bb91ab69530999e93e2a35221d4f221fb942367 (patch) | |
tree | 81f3c7477c00ed237f998776cf73f3421be0d14f /tests | |
parent | 734807438679d0340042420dd1778936d3ecb341 (diff) | |
download | org.eclipse.ecf-3bb91ab69530999e93e2a35221d4f221fb942367.tar.gz org.eclipse.ecf-3bb91ab69530999e93e2a35221d4f221fb942367.tar.xz org.eclipse.ecf-3bb91ab69530999e93e2a35221d4f221fb942367.zip |
Added AbstractConcatServerApplication and AbstractConcatClientTestCase. also added R-OSGI Concat Server launch config
Diffstat (limited to 'tests')
6 files changed, 436 insertions, 211 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice/R-OSGi Concat Server.launch b/tests/bundles/org.eclipse.ecf.tests.remoteservice/R-OSGi Concat Server.launch new file mode 100644 index 000000000..7bbc9b4fe --- /dev/null +++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice/R-OSGi Concat Server.launch @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<launchConfiguration type="org.eclipse.pde.ui.RuntimeWorkbench"> +<booleanAttribute key="append.args" value="true"/> +<stringAttribute key="application" value="org.eclipse.ecf.tests.remoteservice.ROsgiConcatServer"/> +<booleanAttribute key="askclear" value="true"/> +<booleanAttribute key="automaticAdd" value="true"/> +<booleanAttribute key="automaticValidate" value="false"/> +<stringAttribute key="bootstrap" value=""/> +<stringAttribute key="checked" value="[NONE]"/> +<booleanAttribute key="clearConfig" value="false"/> +<booleanAttribute key="clearws" value="false"/> +<booleanAttribute key="clearwslog" value="false"/> +<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/R-OSGi Concat Server"/> +<booleanAttribute key="default" value="true"/> +<booleanAttribute key="includeOptional" value="true"/> +<stringAttribute key="location" value="${workspace_loc}/../runtime-New_configuration"/> +<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl}"/> +<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/> +<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms40m -Xmx256m"/> +<stringAttribute key="pde.version" value="3.3"/> +<stringAttribute key="product" value="org.eclipse.sdk.ide"/> +<booleanAttribute key="show_selected_only" value="false"/> +<stringAttribute key="templateConfig" value="${target_home}\configuration\config.ini"/> +<booleanAttribute key="tracing" value="false"/> +<booleanAttribute key="useDefaultConfig" value="true"/> +<booleanAttribute key="useDefaultConfigArea" value="true"/> +<booleanAttribute key="useProduct" value="false"/> +<booleanAttribute key="usefeatures" value="false"/> +</launchConfiguration> diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/AbstractConcatClientTestCase.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/AbstractConcatClientTestCase.java new file mode 100644 index 000000000..45ebc184d --- /dev/null +++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/AbstractConcatClientTestCase.java @@ -0,0 +1,267 @@ +/******************************************************************************* +* 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; + +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import org.eclipse.ecf.core.ContainerConnectException; +import org.eclipse.ecf.core.ContainerCreateException; +import org.eclipse.ecf.core.ContainerFactory; +import org.eclipse.ecf.core.IContainer; +import org.eclipse.ecf.core.IContainerManager; +import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.core.identity.IDFactory; +import org.eclipse.ecf.core.identity.Namespace; +import org.eclipse.ecf.remoteservice.IRemoteCall; +import org.eclipse.ecf.remoteservice.IRemoteCallListener; +import org.eclipse.ecf.remoteservice.IRemoteService; +import org.eclipse.ecf.remoteservice.IRemoteServiceContainer; +import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter; +import org.eclipse.ecf.remoteservice.IRemoteServiceID; +import org.eclipse.ecf.remoteservice.IRemoteServiceReference; +import org.eclipse.ecf.remoteservice.RemoteServiceContainer; +import org.eclipse.ecf.remoteservice.events.IRemoteCallEvent; +import org.eclipse.ecf.tests.remoteservice.r_osgi.R_OSGi; +import org.eclipse.equinox.concurrent.future.IFuture; +import org.osgi.framework.InvalidSyntaxException; + +public abstract class AbstractConcatClientTestCase extends TestCase { + + protected IRemoteServiceContainer rsContainer; + protected ID targetID; + + protected abstract String getContainerType(); + + protected ID createStringID(String value) { + return IDFactory.getDefault().createStringID(value); + } + + protected ID createID(IContainer container, String value) { + return IDFactory.getDefault().createID(container.getConnectNamespace(),value); + } + + protected IContainer createContainer() throws ContainerCreateException { + return Activator.getDefault().getContainerManager() + .getContainerFactory().createContainer(getContainerType()); + } + + protected IContainer createContainer(ID containerID) throws ContainerCreateException { + return Activator.getDefault().getContainerManager() + .getContainerFactory().createContainer(getContainerType(),containerID); + } + + protected IContainer createContainer(String containerID) throws ContainerCreateException { + return Activator.getDefault().getContainerManager() + .getContainerFactory().createContainer(getContainerType(),createStringID(containerID)); + } + + protected IRemoteServiceContainer createRemoteServiceContainer( + IContainer container) { + return new RemoteServiceContainer(container, + (IRemoteServiceContainerAdapter) container + .getAdapter(IRemoteServiceContainerAdapter.class)); + } + + protected void setUp() throws Exception { + super.setUp(); + IContainer container = createContainer("r-osgi://localhost:9279"); + rsContainer = createRemoteServiceContainer(container); + targetID = createID(container, R_OSGi.SERVER_IDENTITY); + } + + protected void tearDown() throws Exception { + rsContainer.getContainer().disconnect(); + rsContainer.getContainer().dispose(); + ((IContainerManager) ContainerFactory.getDefault()).removeAllContainers(); + rsContainer = null; + targetID = null; + } + + protected IRemoteService getRemoteService(ID target, String clazz, String filter) { + final IRemoteServiceReference[] refs = getRemoteServiceReferences(target, clazz, filter); + if (refs == null || refs.length == 0) + return null; + return rsContainer.getContainerAdapter().getRemoteService(refs[0]); + } + + protected IRemoteServiceReference[] getRemoteServiceReferences(ID target, String clazz, + String filter) { + try { + return rsContainer.getContainerAdapter().getRemoteServiceReferences(target, clazz, filter); + } catch (final InvalidSyntaxException e) { + fail("should not happen"); + } catch (final ContainerConnectException e) { + fail("connect problem"); + } + return null; + } + + public void testGetServiceReferences() throws Exception { + final IRemoteServiceReference[] refs = getRemoteServiceReferences(targetID, getRemoteServiceClass().getName(), getRemoteServiceFilter()); + assertTrue(refs != null); + assertTrue(refs.length > 0); + } + + public void testGetRemoteServiceIDs() throws Exception { + final IRemoteServiceReference[] refs = getRemoteServiceReferences(targetID, getRemoteServiceClass().getName(), getRemoteServiceFilter()); + assertTrue(refs != null); + assertTrue(refs.length > 0); + for(int i=0; i < refs.length; i++) { + IRemoteServiceID rsid = refs[i].getID(); + assertNotNull(rsid); + } + } + + public void testGetRemoteServiceReferenceObjectClass() throws Exception { + String className = getRemoteServiceClass().getName(); + final IRemoteServiceReference[] refs = getRemoteServiceReferences(targetID, className, getRemoteServiceFilter()); + assertTrue(refs != null); + assertTrue(refs.length > 0); + for(int i=0; i < refs.length; i++) { + String[] intfClasses = (String[]) refs[i].getProperty(org.eclipse.ecf.remoteservice.Constants.OBJECTCLASS); + List classNames = Arrays.asList(intfClasses); + assertTrue(classNames.contains(className)); + } + } + + public void testGetRemoteServiceReferenceServiceID() throws Exception { + final IRemoteServiceReference[] refs = getRemoteServiceReferences(targetID, getRemoteServiceClass().getName(), getRemoteServiceFilter()); + assertTrue(refs != null); + assertTrue(refs.length > 0); + for(int i=0; i < refs.length; i++) { + IRemoteServiceID rsid = refs[i].getID(); + Long sid = (Long) refs[i].getProperty(org.eclipse.ecf.remoteservice.Constants.SERVICE_ID); + assertNotNull(sid); + assertTrue(sid.longValue() > 0); + assertTrue(sid.longValue() == rsid.getContainerRelativeID()); + } + } + + public void testGetService() throws Exception { + final IRemoteService service = getRemoteService(targetID, IConcatService.class.getName(), null); + assertNotNull(service); + } + + public void testCallSynch() throws Exception { + final IRemoteService service = getRemoteService(targetID, IConcatService.class.getName(), null); + assertNotNull(service); + traceCallStart("callSynch"); + final Object result = service.callSync(createRemoteConcat("Eclipse ", + "is cool")); + traceCallEnd("callSynch", result); + + assertNotNull(result); + assertTrue(result.equals("Eclipse ".concat("is cool"))); + } + + protected void traceCallStart(String callType) { + System.out.println(callType + " start"); + } + + protected void traceCallEnd(String callType, Object result) { + System.out.println(callType + " end"); + System.out.println(" result=" + result); + } + + protected void traceCallEnd(String callType) { + System.out.println(callType + " end."); + } + + protected IRemoteCallListener createRemoteCallListener() { + return new IRemoteCallListener() { + public void handleEvent(IRemoteCallEvent event) { + System.out.println("CLIENT.handleEvent(" + event + ")"); + } + }; + } + + protected IRemoteCall createRemoteCall(final String method, final Object[] params) { + return new IRemoteCall() { + public String getMethod() { + return method; + } + + public Object[] getParameters() { + return params; + } + + public long getTimeout() { + return 3000; + } + }; + } + + protected IRemoteCall createRemoteConcat(String first, String second) { + return createRemoteCall("concat", new Object[] { first, second }); + } + + protected Class getRemoteServiceClass() { + return IConcatService.class; + } + + protected String getRemoteServiceFilter() { + return null; + } + + public void testGetNamespace() throws Exception { + Namespace ns = rsContainer.getContainer().getConnectNamespace(); + assertNotNull(ns); + } + + public void testGetRSNamespace() throws Exception { + Namespace ns = rsContainer.getContainerAdapter().getRemoteServiceNamespace(); + assertNotNull(ns); + } + + public void testGetRSReference() throws Exception { + + } + public void testCallAsynch() throws Exception { + final IRemoteService service = getRemoteService(targetID, getRemoteServiceClass().getName(), getRemoteServiceFilter()); + assertNotNull(service); + traceCallStart("callAsynch"); + service.callAsync(createRemoteConcat("ECF ", "is cool"), + createRemoteCallListener()); + traceCallEnd("callAsynch"); + } + + public void testFireAsynch() throws Exception { + final IRemoteService service = getRemoteService(targetID, getRemoteServiceClass().getName(), getRemoteServiceFilter()); + assertNotNull(service); + traceCallStart("fireAsynch"); + service.fireAsync(createRemoteConcat("Eclipse ", "sucks")); + traceCallEnd("fireAsynch"); + } + + public void testProxy() throws Exception { + final IRemoteService service = getRemoteService(targetID, getRemoteServiceClass().getName(), getRemoteServiceFilter()); + assertNotNull(service); + final IConcatService proxy = (IConcatService) service.getProxy(); + assertNotNull(proxy); + traceCallStart("getProxy"); + final String result = proxy.concat("ECF ", "sucks"); + traceCallEnd("getProxy", result); + } + + public void testAsyncResult() throws Exception { + final IRemoteService service = getRemoteService(targetID, getRemoteServiceClass().getName(), getRemoteServiceFilter()); + assertNotNull(service); + traceCallStart("callAsynchResult"); + final IFuture result = service.callAsync(createRemoteConcat( + "ECF AsynchResults ", "are cool")); + traceCallEnd("callAsynchResult", result); + assertNotNull(result); + } + + +} diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/AbstractConcatServerApplication.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/AbstractConcatServerApplication.java new file mode 100644 index 000000000..913c34e95 --- /dev/null +++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/AbstractConcatServerApplication.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * 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; + +import java.util.Dictionary; + +import org.eclipse.ecf.core.ContainerCreateException; +import org.eclipse.ecf.core.ContainerFactory; +import org.eclipse.ecf.core.IContainer; +import org.eclipse.ecf.core.IContainerManager; +import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.remoteservice.IRemoteServiceContainer; +import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter; +import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration; +import org.eclipse.ecf.remoteservice.RemoteServiceContainer; +import org.eclipse.equinox.app.IApplication; +import org.eclipse.equinox.app.IApplicationContext; + +public abstract class AbstractConcatServerApplication implements IApplication { + + protected IRemoteServiceContainer rsContainer; + protected boolean done = false; + + /** + * This is the only method that must be overridden in order to define the + * container type used for running a concat server as an application. + * + * @return String that will be used to create a container instance (e.g. + * "ecf.generic.server" or "ecf.r_osgi.peer") + */ + protected abstract String getContainerType(); + + public Object start(IApplicationContext context) throws Exception { + // First, create container of appropriate type + IContainer container = createContainer(); + // Then, from container create remote service container + rsContainer = createRemoteServiceContainer(container); + // Now register remote service + registerRemoteService(getRemoteServiceClass(), createRemoteService(), + createRemoteServiceProperties()); + + printStarted(); + // And wait until we're explicitly stopped. + synchronized (this) { + while (!done) + wait(); + } + return new Integer(0); + } + + + public void stop() { + rsContainer.getContainer().disconnect(); + rsContainer.getContainer().dispose(); + ((IContainerManager) ContainerFactory.getDefault()) + .removeAllContainers(); + done = true; + notifyAll(); + } + + protected void printStarted() { + System.out.println("STARTED Concat Server\n\tContainerType="+getContainerType()+"\n\tID="+rsContainer.getContainer().getID()); + } + + protected Class getRemoteServiceClass() { + return IConcatService.class; + } + + protected Object createRemoteService() { + return new IConcatService() { + public String concat(String string1, String string2) { + final String result = string1.concat(string2); + System.out.println("SERVICE.concat(" + string1 + "," + string2 + + ") returning " + result); + return string1.concat(string2); + } + }; + } + + protected Dictionary createRemoteServiceProperties() { + return null; + } + + protected IContainer createContainer() throws ContainerCreateException { + return Activator.getDefault().getContainerManager() + .getContainerFactory().createContainer(getContainerType()); + } + + protected IContainer createContainer(ID containerID) throws ContainerCreateException { + return Activator.getDefault().getContainerManager() + .getContainerFactory().createContainer(getContainerType(),containerID); + } + + protected IRemoteServiceContainer createRemoteServiceContainer( + IContainer container) { + return new RemoteServiceContainer(container, + (IRemoteServiceContainerAdapter) container + .getAdapter(IRemoteServiceContainerAdapter.class)); + } + + protected IRemoteServiceRegistration registerRemoteService(Class clazz, + Object service, Dictionary properties) { + return rsContainer.getContainerAdapter().registerRemoteService( + new String[] { getRemoteServiceClass().getName() }, + createRemoteService(), createRemoteServiceProperties()); + } + +} diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/Activator.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/Activator.java index c7c779f07..3dc39e66c 100755 --- a/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/Activator.java +++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/Activator.java @@ -1,7 +1,9 @@ package org.eclipse.ecf.tests.remoteservice; +import org.eclipse.ecf.core.IContainerManager; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; +import org.osgi.util.tracker.ServiceTracker; /** * The activator class controls the plug-in life cycle @@ -16,6 +18,8 @@ public class Activator implements BundleActivator { private BundleContext context; + private ServiceTracker containerManagerServiceTracker; + /** * The constructor */ @@ -36,6 +40,10 @@ public class Activator implements BundleActivator { * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext context) throws Exception { + if (containerManagerServiceTracker != null) { + containerManagerServiceTracker.close(); + containerManagerServiceTracker = null; + } plugin = null; this.context = null; } @@ -57,4 +65,12 @@ public class Activator implements BundleActivator { return context; } + public IContainerManager getContainerManager() { + if (containerManagerServiceTracker == null) { + containerManagerServiceTracker = new ServiceTracker(this.context,IContainerManager.class.getName(),null); + containerManagerServiceTracker.open(); + } + return (IContainerManager) containerManagerServiceTracker.getService(); + } + } diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/r_osgi/ROsgiConcatServerApplication.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/r_osgi/ROsgiConcatServerApplication.java index b9aebb4bf..ca204b8db 100644 --- a/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/r_osgi/ROsgiConcatServerApplication.java +++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/r_osgi/ROsgiConcatServerApplication.java @@ -9,56 +9,14 @@ ******************************************************************************/ package org.eclipse.ecf.tests.remoteservice.r_osgi; -import org.eclipse.ecf.core.ContainerFactory; -import org.eclipse.ecf.core.IContainer; -import org.eclipse.ecf.core.IContainerManager; -import org.eclipse.ecf.remoteservice.IRemoteServiceContainer; -import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter; -import org.eclipse.ecf.remoteservice.RemoteServiceContainer; -import org.eclipse.ecf.tests.remoteservice.IConcatService; -import org.eclipse.equinox.app.IApplication; -import org.eclipse.equinox.app.IApplicationContext; -public class ROsgiConcatServerApplication implements IApplication { +import org.eclipse.ecf.tests.remoteservice.AbstractConcatServerApplication; - IRemoteServiceContainer rsContainer; - boolean done = false; - - public Object start(IApplicationContext context) throws Exception { +public class ROsgiConcatServerApplication extends + AbstractConcatServerApplication { - IContainer container = ContainerFactory.getDefault().createContainer( - R_OSGi.CLIENT_CONTAINER_NAME); - rsContainer = new RemoteServiceContainer(container, - (IRemoteServiceContainerAdapter) container - .getAdapter(IRemoteServiceContainerAdapter.class)); - - rsContainer.getContainerAdapter().registerRemoteService( - new String[] { IConcatService.class.getName() }, - createService(), null); - - synchronized (this) { - while (!done) wait(); - } - return new Integer(0); - } - - protected Object createService() { - return new IConcatService() { - public String concat(String string1, String string2) { - final String result = string1.concat(string2); - System.out.println("SERVICE.concat(" + string1 + "," + string2 - + ") returning " + result); - return string1.concat(string2); - } - }; - } - - public void stop() { - rsContainer.getContainer().disconnect(); - rsContainer.getContainer().dispose(); - ((IContainerManager) ContainerFactory.getDefault()).removeAllContainers(); - done = true; - notifyAll(); + public String getContainerType() { + return R_OSGi.CLIENT_CONTAINER_NAME; } } diff --git a/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/r_osgi/ROsgiConcatServiceTest.java b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/r_osgi/ROsgiConcatServiceTest.java index 9ebd453ce..62747aeb3 100644 --- a/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/r_osgi/ROsgiConcatServiceTest.java +++ b/tests/bundles/org.eclipse.ecf.tests.remoteservice/src/org/eclipse/ecf/tests/remoteservice/r_osgi/ROsgiConcatServiceTest.java @@ -9,172 +9,12 @@ ******************************************************************************/ package org.eclipse.ecf.tests.remoteservice.r_osgi; -import junit.framework.TestCase; +import org.eclipse.ecf.tests.remoteservice.AbstractConcatClientTestCase; -import org.eclipse.ecf.core.ContainerConnectException; -import org.eclipse.ecf.core.ContainerFactory; -import org.eclipse.ecf.core.IContainer; -import org.eclipse.ecf.core.IContainerManager; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.identity.IDFactory; -import org.eclipse.ecf.remoteservice.IRemoteCall; -import org.eclipse.ecf.remoteservice.IRemoteCallListener; -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.remoteservice.events.IRemoteCallEvent; -import org.eclipse.ecf.tests.remoteservice.IConcatService; -import org.eclipse.equinox.concurrent.future.IFuture; -import org.osgi.framework.InvalidSyntaxException; +public class ROsgiConcatServiceTest extends AbstractConcatClientTestCase { -public class ROsgiConcatServiceTest extends TestCase { - - IRemoteServiceContainer rsContainer; - ID targetID; - - protected void setUp() throws Exception { - super.setUp(); - IContainer container = ContainerFactory.getDefault().createContainer(R_OSGi.CLIENT_CONTAINER_NAME,IDFactory.getDefault().createStringID( - "r-osgi://localhost:9279")); - rsContainer = new RemoteServiceContainer(container,(IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class)); - targetID = IDFactory.getDefault().createID(container.getConnectNamespace(), R_OSGi.SERVER_IDENTITY); - } - - protected void tearDown() throws Exception { - rsContainer.getContainer().disconnect(); - rsContainer.getContainer().dispose(); - ((IContainerManager) ContainerFactory.getDefault()).removeAllContainers(); - rsContainer = null; - targetID = null; - } - - protected String getClientContainerName() { - return null; - } - - protected IRemoteService getRemoteService(ID target, String clazz, String filter) { - final IRemoteServiceReference[] refs = getRemoteServiceReferences(target, clazz, filter); - if (refs == null || refs.length == 0) - return null; - return rsContainer.getContainerAdapter().getRemoteService(refs[0]); - } - - protected IRemoteServiceReference[] getRemoteServiceReferences(ID target, String clazz, String filter) { - try { - return rsContainer.getContainerAdapter().getRemoteServiceReferences(target, clazz, filter); - } catch (final InvalidSyntaxException e) { - fail("should not happen"); - } catch (final ContainerConnectException e) { - fail("connect problem"); - } - return null; - } - - - public void testGetServiceReferences() throws Exception { - final IRemoteServiceReference[] refs = getRemoteServiceReferences(targetID, IConcatService.class.getName(), null); - - assertTrue(refs != null); - assertTrue(refs.length > 0); - } - - public void testGetService() throws Exception { - final IRemoteService service = getRemoteService(targetID, IConcatService.class.getName(), null); - assertNotNull(service); - } - - protected IRemoteCallListener createRemoteCallListener() { - return new IRemoteCallListener() { - public void handleEvent(IRemoteCallEvent event) { - System.out.println("CLIENT.handleEvent(" + event + ")"); - } - }; - } - - protected IRemoteCall createRemoteCall(final String method, - final Object[] params) { - return new IRemoteCall() { - public String getMethod() { - return method; - } - - public Object[] getParameters() { - return params; - } - - public long getTimeout() { - return 3000; - } - }; - } - - protected IRemoteCall createRemoteConcat(String first, String second) { - return createRemoteCall("concat", new Object[] { first, second }); - } - - - public void testCallSynch() throws Exception { - final IRemoteService service = getRemoteService(targetID, IConcatService.class.getName(), null); - assertNotNull(service); - traceCallStart("callSynch"); - final Object result = service.callSync(createRemoteConcat("Eclipse ", - "is cool")); - traceCallEnd("callSynch", result); - - assertNotNull(result); - assertTrue(result.equals("Eclipse ".concat("is cool"))); - } - - protected void traceCallStart(String callType) { - System.out.println(callType + " start"); - } - - protected void traceCallEnd(String callType, Object result) { - System.out.println(callType + " end"); - System.out.println(" result=" + result); - } - - protected void traceCallEnd(String callType) { - System.out.println(callType + " end."); - } - - public void testCallAsynch() throws Exception { - final IRemoteService service = getRemoteService(targetID, IConcatService.class.getName(), null); - assertNotNull(service); - traceCallStart("callAsynch"); - service.callAsync(createRemoteConcat("ECF ", "is cool"), - createRemoteCallListener()); - traceCallEnd("callAsynch"); - } - - public void testFireAsynch() throws Exception { - final IRemoteService service = getRemoteService(targetID, IConcatService.class.getName(), null); - assertNotNull(service); - traceCallStart("fireAsynch"); - service.fireAsync(createRemoteConcat("Eclipse ", "sucks")); - traceCallEnd("fireAsynch"); - } - - public void testProxy() throws Exception { - final IRemoteService service = getRemoteService(targetID, IConcatService.class.getName(), null); - assertNotNull(service); - final IConcatService proxy = (IConcatService) service.getProxy(); - assertNotNull(proxy); - traceCallStart("getProxy"); - final String result = proxy.concat("ECF ", "sucks"); - traceCallEnd("getProxy", result); - } - - public void testAsyncResult() throws Exception { - final IRemoteService service = getRemoteService(targetID, IConcatService.class.getName(), null); - assertNotNull(service); - traceCallStart("callAsynchResult"); - final IFuture result = service.callAsync(createRemoteConcat( - "ECF AsynchResults ", "are cool")); - traceCallEnd("callAsynchResult", result); - assertNotNull(result); + protected String getContainerType() { + return R_OSGi.CLIENT_CONTAINER_NAME; } } |