Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2007-03-06 22:42:27 -0500
committerslewis2007-03-06 22:42:27 -0500
commite28cc356bb342aeca84a43935574cdd54467685a (patch)
tree871a54d70b56ddc25d2dff7dc1bdc1aa6517d8a4 /tests/bundles/org.eclipse.ecf.tests.discovery
parentbd1447ce8722a694a3a05d584a75b88e18aa7124 (diff)
downloadorg.eclipse.ecf-e28cc356bb342aeca84a43935574cdd54467685a.tar.gz
org.eclipse.ecf-e28cc356bb342aeca84a43935574cdd54467685a.tar.xz
org.eclipse.ecf-e28cc356bb342aeca84a43935574cdd54467685a.zip
Added IDiscoveryService service interface and service jmdns implementation, also added client test code in org.eclipse.ecf.tests.discovery.
Diffstat (limited to 'tests/bundles/org.eclipse.ecf.tests.discovery')
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/Activator.java17
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/DiscoveryServiceTest.java113
2 files changed, 130 insertions, 0 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/Activator.java b/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/Activator.java
index f73dd5913..9c91ad341 100755
--- a/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/Activator.java
+++ b/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/Activator.java
@@ -1,7 +1,9 @@
package org.eclipse.ecf.tests.discovery;
import org.eclipse.core.runtime.Plugin;
+import org.eclipse.ecf.discovery.service.IDiscoveryService;
import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
/**
* The activator class controls the plug-in life cycle
@@ -14,6 +16,8 @@ public class Activator extends Plugin {
// The shared instance
private static Activator plugin;
+ private ServiceTracker tracker;
+
/**
* The constructor
*/
@@ -27,6 +31,8 @@ public class Activator extends Plugin {
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
+ tracker = new ServiceTracker(context,IDiscoveryService.class.getName(),null);
+ tracker.open();
}
/*
@@ -35,6 +41,10 @@ public class Activator extends Plugin {
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
+ if (tracker != null) {
+ tracker.close();
+ tracker = null;
+ }
super.stop(context);
}
@@ -47,4 +57,11 @@ public class Activator extends Plugin {
return plugin;
}
+ /**
+ *
+ */
+ public IDiscoveryService getDiscoveryService() {
+ return (IDiscoveryService) tracker.getService();
+ }
+
}
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/DiscoveryServiceTest.java b/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/DiscoveryServiceTest.java
new file mode 100755
index 000000000..fa3da1615
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/DiscoveryServiceTest.java
@@ -0,0 +1,113 @@
+/****************************************************************************
+* Copyright (c) 2004 Composent, Inc. 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:
+* Composent, Inc. - initial API and implementation
+*****************************************************************************/
+
+package org.eclipse.ecf.tests.discovery;
+
+import java.net.InetAddress;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.eclipse.ecf.discovery.IServiceEvent;
+import org.eclipse.ecf.discovery.IServiceListener;
+import org.eclipse.ecf.discovery.IServiceTypeListener;
+import org.eclipse.ecf.discovery.ServiceInfo;
+import org.eclipse.ecf.discovery.ServiceProperties;
+import org.eclipse.ecf.discovery.identity.ServiceID;
+import org.eclipse.ecf.discovery.service.IDiscoveryService;
+
+public class DiscoveryServiceTest extends TestCase {
+
+ static final String TEST_SERVICE_TYPE = "_ecftcp._tcp.local.";
+ static final String TEST_PROTOCOL = "ecftcp";
+ static final String TEST_HOST = "localhost";
+ static final int TEST_PORT = 3282;
+ static final String TEST_SERVICE_NAME = System.getProperty("user.name") + "." + TEST_PROTOCOL;
+
+ protected IDiscoveryService discoveryInstance = null;
+
+ protected IDiscoveryService getDiscoveryInstance() {
+ return Activator.getDefault().getDiscoveryService();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ discoveryInstance = getDiscoveryInstance();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testAddServiceTypeListener() throws Exception {
+ assertNotNull(discoveryInstance);
+ discoveryInstance
+ .addServiceTypeListener(new CollabServiceTypeListener());
+ }
+
+ public void testRegisterServiceType() throws Exception {
+ discoveryInstance.registerServiceType(TEST_SERVICE_TYPE);
+ System.out.println("registered service type "+TEST_SERVICE_TYPE+" waiting 5s");
+ Thread.sleep(5000);
+ }
+
+ public void testRegisterService() throws Exception {
+ Properties props = new Properties();
+ String protocol = TEST_PROTOCOL;
+ InetAddress host = InetAddress.getByName(TEST_HOST);
+ int port = TEST_PORT;
+ String svcName = System.getProperty("user.name") + "."
+ + protocol;
+ ServiceInfo svcInfo = new ServiceInfo(host, new ServiceID(
+ TEST_SERVICE_TYPE, svcName), port,
+ 0, 0, new ServiceProperties(props));
+ discoveryInstance.registerService(svcInfo);
+ }
+ public final void testDiscovery() throws Exception {
+
+ System.out.println("Discovery started. Waiting 10s for discovered services");
+ Thread.sleep(10000);
+ }
+
+ class CollabServiceTypeListener implements IServiceTypeListener {
+ public void serviceTypeAdded(IServiceEvent event) {
+ System.out.println("serviceTypeAdded(" + event + ")");
+ ServiceID svcID = event.getServiceInfo().getServiceID();
+ discoveryInstance.addServiceListener(svcID,
+ new CollabServiceListener());
+ discoveryInstance.registerServiceType(svcID);
+ }
+ }
+ class CollabServiceListener implements IServiceListener {
+ public void serviceAdded(IServiceEvent event) {
+ System.out.println("serviceAdded(" + event + ")");
+ discoveryInstance.requestServiceInfo(event.getServiceInfo()
+ .getServiceID(), 3000);
+ }
+ public void serviceRemoved(IServiceEvent event) {
+ System.out.println("serviceRemoved(" + event + ")");
+ }
+ public void serviceResolved(IServiceEvent event) {
+ System.out.println("serviceResolved(" + event + ")");
+ }
+ }
+
+}

Back to the top