Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2009-05-01 19:27:33 +0000
committerslewis2009-05-01 19:27:33 +0000
commitc3f0d56fd79f23a9325069e36913eeeb316612e7 (patch)
tree4c8c251d3120d07c855e40ff02df4096ca1aa324
parent1f463a2120cdb951416adf5687db7ae37dffdc18 (diff)
downloadorg.eclipse.ecf-c3f0d56fd79f23a9325069e36913eeeb316612e7.tar.gz
org.eclipse.ecf-c3f0d56fd79f23a9325069e36913eeeb316612e7.tar.xz
org.eclipse.ecf-c3f0d56fd79f23a9325069e36913eeeb316612e7.zip
Added new API: IHostDistributionListener, IProxyDistributionListener, IHostDiscoveryListener, IProxyDiscoveryListener to allow notification of discovery and distribution for host and proxy events.
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.osgi.services.discovery/src/org/eclipse/ecf/tests/osgi/services/discovery/ListenerTest.java67
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.osgi.services.discovery/src/org/eclipse/ecf/tests/osgi/services/discovery/PublishTest.java34
2 files changed, 79 insertions, 22 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.osgi.services.discovery/src/org/eclipse/ecf/tests/osgi/services/discovery/ListenerTest.java b/tests/bundles/org.eclipse.ecf.tests.osgi.services.discovery/src/org/eclipse/ecf/tests/osgi/services/discovery/ListenerTest.java
new file mode 100644
index 000000000..5a490214b
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.osgi.services.discovery/src/org/eclipse/ecf/tests/osgi/services/discovery/ListenerTest.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+* 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.osgi.services.discovery;
+
+import org.eclipse.ecf.discovery.IServiceInfo;
+import org.eclipse.ecf.osgi.services.discovery.IHostDiscoveryListener;
+import org.eclipse.ecf.osgi.services.discovery.IProxyDiscoveryListener;
+import org.eclipse.ecf.tests.internal.osgi.discovery.Activator;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+public class ListenerTest extends PublishTest {
+
+ ServiceRegistration hostDiscoveryListenerRegistration;
+ ServiceRegistration proxyDiscoveryListenerRegistration;
+
+ protected IHostDiscoveryListener createHostDiscoveryListener() {
+ return new IHostDiscoveryListener() {
+
+ public void publish(ServiceReference publicationServiceReference,
+ IServiceInfo serviceInfo) {
+ System.out.println("hostPublish\n\tpublicationServiceReference="+publicationServiceReference+"\n\tserviceInfo="+serviceInfo);
+ }
+
+ public void unpublish(ServiceReference publicationServiceReference,
+ IServiceInfo serviceInfo) {
+ System.out.println("hostUnpublish\n\tpublicationServiceReference="+publicationServiceReference+"\n\tserviceInfo="+serviceInfo);
+ }
+
+ };
+ }
+
+ protected IProxyDiscoveryListener createProxyDiscoveryListener() {
+ return new IProxyDiscoveryListener() {
+
+ public void discovered(IServiceInfo serviceInfo) {
+ System.out.println("proxyDiscovered serviceInfo="+serviceInfo);
+ }
+
+ public void undiscovered(IServiceInfo serviceInfo) {
+ System.out.println("proxyUndiscovered serviceInfo="+serviceInfo);
+ }
+
+ };
+ }
+
+ protected void setUp() throws Exception {
+ // Register listeners
+ hostDiscoveryListenerRegistration = Activator.getDefault().getContext().registerService(IHostDiscoveryListener.class.getName(), createHostDiscoveryListener(), null);
+ proxyDiscoveryListenerRegistration = Activator.getDefault().getContext().registerService(IProxyDiscoveryListener.class.getName(), createProxyDiscoveryListener(), null);
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ hostDiscoveryListenerRegistration.unregister();
+ proxyDiscoveryListenerRegistration.unregister();
+ }
+
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.osgi.services.discovery/src/org/eclipse/ecf/tests/osgi/services/discovery/PublishTest.java b/tests/bundles/org.eclipse.ecf.tests.osgi.services.discovery/src/org/eclipse/ecf/tests/osgi/services/discovery/PublishTest.java
index 64fa2244e..da1f4008c 100644
--- a/tests/bundles/org.eclipse.ecf.tests.osgi.services.discovery/src/org/eclipse/ecf/tests/osgi/services/discovery/PublishTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.osgi.services.discovery/src/org/eclipse/ecf/tests/osgi/services/discovery/PublishTest.java
@@ -10,12 +10,13 @@
package org.eclipse.ecf.tests.osgi.services.discovery;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import junit.framework.TestCase;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.util.Trace;
import org.eclipse.ecf.osgi.services.discovery.RemoteServicePublication;
import org.eclipse.ecf.tests.internal.osgi.discovery.Activator;
@@ -23,25 +24,23 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.discovery.DiscoveredServiceNotification;
-import org.osgi.service.discovery.ServicePublication;
import org.osgi.service.discovery.DiscoveredServiceTracker;
+import org.osgi.service.discovery.ServicePublication;
public class PublishTest extends TestCase {
BundleContext context;
- List serviceRegistrations = new ArrayList();
-
+ ID endpointID;
+
protected void setUp() throws Exception {
super.setUp();
context = Activator.getDefault().getContext();
+ endpointID = IDFactory.getDefault().createStringID("myid");
}
protected void tearDown() throws Exception {
super.tearDown();
- for(Iterator i=serviceRegistrations.iterator(); i.hasNext(); ) {
- ServiceRegistration reg = (ServiceRegistration) i.next();
- reg.unregister();
- }
+ endpointID = null;
context = null;
}
@@ -65,6 +64,7 @@ public class PublishTest extends TestCase {
protected Properties createServicePublicationProperties(List interfaces) {
Properties props = new Properties();
props.put(RemoteServicePublication.SERVICE_INTERFACE_NAME, interfaces);
+ props.put(RemoteServicePublication.ENDPOINT_CONTAINERID, endpointID);
return props;
}
@@ -72,23 +72,13 @@ public class PublishTest extends TestCase {
return new TestServicePublication();
}
- protected DiscoveredServiceTracker createDiscoveredServiceTracker() {
- return new DiscoveredServiceTrackerImpl();
- }
-
- public void testDiscoveryTrackerPublish() throws Exception {
- serviceRegistrations.add(context.registerService(DiscoveredServiceTracker.class.getName(), createDiscoveredServiceTracker(), null));
- }
-
public void testServicePublish() throws Exception {
List interfaces = new ArrayList();
interfaces.add("foo.bar");
- serviceRegistrations.add(context.registerService(ServicePublication.class.getName(), createServicePublication(), createServicePublicationProperties(interfaces)));
- Thread.sleep(5000);
+ ServiceRegistration reg = context.registerService(ServicePublication.class.getName(), createServicePublication(), createServicePublicationProperties(interfaces));
+ Thread.sleep(60000);
+ reg.unregister();
+ Thread.sleep(60000);
}
- public void testDiscoveryTrackerAndServicePublish() throws Exception {
- testDiscoveryTrackerPublish();
- testServicePublish();
- }
}

Back to the top