Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2009-02-24 01:08:35 +0000
committerslewis2009-02-24 01:08:35 +0000
commit95202ad567b01f46cddf0eb3fef2f03dbe7f6d9b (patch)
treefe0991e34a9be892ef0c931211173d50acb3bafa /tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution
parent2f4a96a38f0681ca1ce439b462139ced24790219 (diff)
downloadorg.eclipse.ecf-95202ad567b01f46cddf0eb3fef2f03dbe7f6d9b.tar.gz
org.eclipse.ecf-95202ad567b01f46cddf0eb3fef2f03dbe7f6d9b.tar.xz
org.eclipse.ecf-95202ad567b01f46cddf0eb3fef2f03dbe7f6d9b.zip
Adding GenericRemoteServiceRegisterTest
Diffstat (limited to 'tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution')
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/META-INF/MANIFEST.MF3
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractDistributionTest.java74
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/GenericRemoteServiceRegisterTest.java (renamed from tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/RegisterTest.java)46
3 files changed, 73 insertions, 50 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/META-INF/MANIFEST.MF b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/META-INF/MANIFEST.MF
index e02b574f9..3d6170300 100644
--- a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/META-INF/MANIFEST.MF
+++ b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/META-INF/MANIFEST.MF
@@ -18,4 +18,5 @@ Require-Bundle: org.eclipse.equinox.common;bundle-version="3.5.0",
org.junit;bundle-version="3.8.2",
org.eclipse.ecf.remoteservice;bundle-version="3.0.0",
org.eclipse.ecf;bundle-version="3.0.0",
- org.eclipse.ecf.tests.remoteservice;bundle-version="2.0.0"
+ org.eclipse.ecf.tests.remoteservice;bundle-version="2.0.0",
+ org.eclipse.ecf.osgi.services.discovery;bundle-version="1.0.0"
diff --git a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractDistributionTest.java b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractDistributionTest.java
index f4a587979..cd4740812 100644
--- a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractDistributionTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractDistributionTest.java
@@ -9,10 +9,13 @@
******************************************************************************/
package org.eclipse.ecf.tests.osgi.services.distribution;
+import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
-import org.eclipse.ecf.remoteservice.IRemoteCall;
import org.eclipse.ecf.remoteservice.IRemoteService;
import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
import org.eclipse.ecf.remoteservice.IRemoteServiceListener;
@@ -21,13 +24,17 @@ import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration;
import org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent;
import org.eclipse.ecf.tests.ContainerAbstractTestCase;
import org.eclipse.ecf.tests.remoteservice.IConcatService;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceRegistration;
public abstract class AbstractDistributionTest extends
ContainerAbstractTestCase {
protected IRemoteServiceContainerAdapter[] adapters = null;
+ protected List /* ServiceRegistration */ registrations = new ArrayList();
+
/*
* (non-Javadoc)
*
@@ -36,6 +43,21 @@ public abstract class AbstractDistributionTest extends
*/
protected abstract String getClientContainerName();
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ for(Iterator i=registrations.iterator(); i.hasNext(); ) {
+ ServiceRegistration reg = (ServiceRegistration) i.next();
+ reg.unregister();
+ }
+ registrations.clear();
+ if (adapters != null) {
+ for(int i=0;i < adapters.length; i++) {
+ adapters[i] = null;
+ }
+ adapters = null;
+ }
+ }
+
protected void setClientCount(int count) {
super.setClientCount(count);
adapters = new IRemoteServiceContainerAdapter[count];
@@ -49,6 +71,10 @@ public abstract class AbstractDistributionTest extends
}
}
+ protected BundleContext getContext() {
+ return Activator.getDefault().getContext();
+ }
+
protected IRemoteServiceContainerAdapter[] getRemoteServiceAdapters() {
return adapters;
}
@@ -67,7 +93,7 @@ public abstract class AbstractDistributionTest extends
}
}
- protected IRemoteServiceRegistration registerService(
+ protected IRemoteServiceRegistration registerRemoteService(
IRemoteServiceContainerAdapter adapter, String serviceInterface,
Object service, Dictionary serviceProperties, int sleepTime) {
final IRemoteServiceRegistration result = adapter
@@ -114,34 +140,11 @@ public abstract class AbstractDistributionTest extends
return (filter == null) ? null : filter.toString();
}
- protected IRemoteService registerAndGetRemoteService(
- IRemoteServiceContainerAdapter server,
- IRemoteServiceContainerAdapter client, String serviceName,
- Dictionary serviceProperties, int sleepTime) {
- registerService(server, serviceName, createService(),
- serviceProperties, sleepTime);
- return getRemoteService(client, serviceName,
- getFilterFromServiceProperties(serviceProperties));
+ protected String[] getDefaultServiceClasses() {
+ return new String[] { IConcatService.class.getName() };
}
-
- 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 Object createService() {
+
+ protected Object createDefaultService() {
return new IConcatService() {
public String concat(String string1, String string2) {
final String result = string1.concat(string2);
@@ -152,5 +155,18 @@ public abstract class AbstractDistributionTest extends
};
}
+ protected void registerService(String[] clazzes, Object service, Properties props) throws Exception {
+ registrations.add(getContext().registerService(clazzes, service, props));
+ }
+
+ protected void registerService(String clazz, Object service, Properties props) throws Exception {
+ registerService(new String[] { clazz }, service, props);
+ }
+
+ protected void registerDefaultService(Properties props) throws Exception {
+ registerService(getDefaultServiceClasses(), createDefaultService(), props);
+ }
+
+
}
diff --git a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/RegisterTest.java b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/GenericRemoteServiceRegisterTest.java
index 3ed03414b..0d7ff5178 100644
--- a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/RegisterTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/GenericRemoteServiceRegisterTest.java
@@ -9,23 +9,19 @@
******************************************************************************/
package org.eclipse.ecf.tests.osgi.services.distribution;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
import java.util.Properties;
import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.osgi.services.discovery.ECFServicePublication;
import org.eclipse.ecf.osgi.services.distribution.ServiceConstants;
import org.eclipse.ecf.remoteservice.Constants;
-import org.eclipse.ecf.tests.remoteservice.IConcatService;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.discovery.ServicePublication;
+import org.osgi.util.tracker.ServiceTracker;
-public class RegisterTest extends AbstractDistributionTest implements ServiceConstants {
+public class GenericRemoteServiceRegisterTest extends AbstractDistributionTest implements ServiceConstants, ECFServicePublication {
- List /* ServiceRegistration */ registrations = new ArrayList();
-
/*
* (non-Javadoc)
*
@@ -36,15 +32,12 @@ public class RegisterTest extends AbstractDistributionTest implements ServiceCon
setClientCount(1);
createServerAndClients();
connectClients();
+ setupRemoteServiceAdapters();
}
protected void tearDown() throws Exception {
super.tearDown();
- for(Iterator i=registrations.iterator(); i.hasNext(); ) {
- ServiceRegistration reg = (ServiceRegistration) i.next();
- reg.unregister();
- }
cleanUpServerAndClients();
}
@@ -52,15 +45,10 @@ public class RegisterTest extends AbstractDistributionTest implements ServiceCon
return "ecf.generic.client";
}
- protected void registerConcatService(Properties props) throws Exception {
- BundleContext bc = Activator.getDefault().getContext();
- registrations.add(bc.registerService(new String[] { IConcatService.class.getName() }, createService(), props));
- }
-
public void testRegisterAllContainers() throws Exception {
Properties props = new Properties();
props.put(OSGI_REMOTE_INTERFACES, new String[] {OSGI_REMOTE_INTERFACES_WILDCARD});
- registerConcatService(props);
+ registerDefaultService(props);
}
public void testRegisterServerContainer() throws Exception {
@@ -68,7 +56,25 @@ public class RegisterTest extends AbstractDistributionTest implements ServiceCon
props.put(OSGI_REMOTE_INTERFACES, new String[] {OSGI_REMOTE_INTERFACES_WILDCARD});
IContainer serverContainer = getServer();
props.put(Constants.SERVICE_CONTAINER_ID, serverContainer.getID());
- registerConcatService(props);
+ registerDefaultService(props);
}
+ public void testRegisterServicePublication() throws Exception {
+ // First set up service tracker for ServicePublication
+ ServiceTracker servicePublicationTracker = new ServiceTracker(getContext(), ServicePublication.class.getName(), null);
+ servicePublicationTracker.open();
+
+ Properties props = new Properties();
+ props.put(OSGI_REMOTE_INTERFACES, new String[] {OSGI_REMOTE_INTERFACES_WILDCARD});
+ IContainer serverContainer = getServer();
+ props.put(Constants.SERVICE_CONTAINER_ID, serverContainer.getID());
+ registerDefaultService(props);
+
+ // Now get ServicePublications from tracker
+ ServiceReference [] servicePublicationSRs = servicePublicationTracker.getServiceReferences();
+ assertTrue(servicePublicationSRs != null);
+ for(int i=0; i < servicePublicationSRs.length; i++) {
+ System.out.println("testRegisterServicePublication["+i+"]="+servicePublicationSRs[i]);
+ }
+ }
}

Back to the top