Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2009-03-03 02:30:37 +0000
committerslewis2009-03-03 02:30:37 +0000
commit04885f7f4c11eecb699b64f32679ca20189c5601 (patch)
treeaccc52f8201c9cdc68bf07134244309e359f0186 /tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution
parentad9cdeff16e36c1a279666039569a9cef4de03e1 (diff)
downloadorg.eclipse.ecf-04885f7f4c11eecb699b64f32679ca20189c5601.tar.gz
org.eclipse.ecf-04885f7f4c11eecb699b64f32679ca20189c5601.tar.xz
org.eclipse.ecf-04885f7f4c11eecb699b64f32679ca20189c5601.zip
Added more test cases to AbstractServiceRegisterTest
Diffstat (limited to 'tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution')
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractServiceRegisterTest.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractServiceRegisterTest.java b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractServiceRegisterTest.java
index 72d05746c..e1de19d91 100644
--- a/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractServiceRegisterTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.osgi.services.distribution/src/org/eclipse/ecf/tests/osgi/services/distribution/AbstractServiceRegisterTest.java
@@ -13,6 +13,12 @@ import java.util.Properties;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.remoteservice.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.discovery.DiscoveredServiceNotification;
+import org.osgi.service.discovery.DiscoveredServiceTracker;
+import org.osgi.service.discovery.ServicePublication;
+import org.osgi.util.tracker.ServiceTracker;
public abstract class AbstractServiceRegisterTest extends
AbstractDistributionTest {
@@ -35,4 +41,74 @@ public abstract class AbstractServiceRegisterTest extends
Thread.sleep(60000);
}
+ 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());
+ ServiceRegistration reg = registerDefaultService(props);
+
+ Thread.sleep(10000);
+
+ // Now get ServicePublications from tracker
+ ServiceReference [] servicePublicationSRs = servicePublicationTracker.getServiceReferences();
+ assertTrue(servicePublicationSRs != null);
+ assertTrue(servicePublicationSRs.length > 0);
+
+ // Now unregister
+ registrations.remove(reg);
+ reg.unregister();
+
+ // Now get new service references again.
+ ServiceReference[] servicePublicationSRsNew = servicePublicationTracker.getServiceReferences();
+ if (servicePublicationSRsNew != null) {
+ assertTrue(servicePublicationSRsNew.length < servicePublicationSRs.length);
+ }
+ }
+
+ DiscoveredServiceNotification dsNotification = null;
+
+ DiscoveredServiceTracker createDiscoveredServiceTracker() {
+ return new DiscoveredServiceTracker() {
+ public void serviceChanged(
+ DiscoveredServiceNotification notification) {
+ if (notification.getType()==DiscoveredServiceNotification.AVAILABLE) {
+ System.out.println("serviceAvailable("+notification.getServiceEndpointDescription()+")");
+ if (dsNotification == null) dsNotification = notification;
+ } else {
+ System.out.println("serviceUnavailable("+notification.getServiceEndpointDescription()+")");
+ dsNotification = null;
+ }
+ }
+ };
+ }
+
+ public void testLocalDiscoveredServiceTracker() throws Exception {
+ // First set up discovered service tracker
+ ServiceRegistration dstReg = getContext().registerService(DiscoveredServiceTracker.class.getName(), createDiscoveredServiceTracker(), null);
+
+ 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());
+ ServiceRegistration svcReg = getContext().registerService(getDefaultServiceClasses(), getDefaultService(), props);
+
+ Thread.sleep(10000);
+
+ assertNotNull(dsNotification);
+ // unregister service
+
+ svcReg.unregister();
+
+ Thread.sleep(10000);
+
+ assertNull(dsNotification);
+
+ dstReg.unregister();
+ }
+
}

Back to the top