Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests.discovery/META-INF/MANIFEST.MF6
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/AbstractDiscoveryTest.java100
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/DiscoveryTest.java147
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/listener/AbstractTestListener.java18
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/listener/TestListener.java (renamed from tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/listener/TestServiceListener.java)30
5 files changed, 206 insertions, 95 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery/META-INF/MANIFEST.MF b/tests/bundles/org.eclipse.ecf.tests.discovery/META-INF/MANIFEST.MF
index 4c31cf216..417318bac 100755
--- a/tests/bundles/org.eclipse.ecf.tests.discovery/META-INF/MANIFEST.MF
+++ b/tests/bundles/org.eclipse.ecf.tests.discovery/META-INF/MANIFEST.MF
@@ -6,13 +6,13 @@ Bundle-Version: 2.0.0.qualifier
Bundle-Activator: org.eclipse.ecf.tests.discovery.Activator
Bundle-Vendor: %plugin.provider
Bundle-Localization: plugin
-Require-Bundle: org.junit,
+Require-Bundle: org.eclipse.equinox.common,
+ org.junit,
org.eclipse.ecf,
org.eclipse.ecf.discovery,
- org.eclipse.equinox.common,
org.eclipse.ecf.provider.jslp
Eclipse-LazyStart: true
-Import-Package: org.osgi.framework;version="1.4.0"
Export-Package: org.eclipse.ecf.tests.discovery,
org.eclipse.ecf.tests.discovery.identity,
org.eclipse.ecf.tests.discovery.listener
+Import-Package: org.osgi.framework
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/AbstractDiscoveryTest.java b/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/AbstractDiscoveryTest.java
new file mode 100755
index 000000000..dfaa26e49
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/AbstractDiscoveryTest.java
@@ -0,0 +1,100 @@
+/****************************************************************************
+ * Copyright (c) 2008 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.net.URI;
+import java.util.Comparator;
+
+import junit.framework.TestCase;
+
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.discovery.IDiscoveryContainerAdapter;
+import org.eclipse.ecf.discovery.IServiceInfo;
+import org.eclipse.ecf.discovery.IServiceProperties;
+import org.eclipse.ecf.discovery.ServiceInfo;
+import org.eclipse.ecf.discovery.ServiceProperties;
+import org.eclipse.ecf.discovery.identity.IServiceID;
+import org.eclipse.ecf.discovery.identity.ServiceIDFactory;
+
+/**
+ *
+ */
+public abstract class AbstractDiscoveryTest extends TestCase {
+
+ protected IContainer container = null;
+ protected IDiscoveryContainerAdapter discoveryContainer = null;
+ protected String containerUnderTest;
+ protected long waitTimeForProvider;
+ protected Comparator comparator;
+
+ /**
+ *
+ */
+ public AbstractDiscoveryTest() {
+ super();
+ }
+
+ /**
+ * @param name
+ */
+ public AbstractDiscoveryTest(String name) {
+ super(name);
+ }
+
+ protected IDiscoveryContainerAdapter getAdapter(Class clazz) {
+ final IDiscoveryContainerAdapter adapter = (IDiscoveryContainerAdapter) container.getAdapter(clazz);
+ assertNotNull("Adapter must not be null", adapter);
+ return adapter;
+ }
+
+ protected IServiceID createServiceID(String serviceType, String serviceName) throws Exception {
+ return ServiceIDFactory.getDefault().createServiceID(discoveryContainer.getServicesNamespace(), serviceType, serviceName);
+ }
+
+ protected URI createURI(String uri) throws Exception {
+ return new URI(uri);
+ }
+
+ protected String getAuthority() throws Exception {
+ return System.getProperty("user.name") + "@" + InetAddress.getLocalHost().getHostAddress();
+ }
+
+ protected int getPort() {
+ return ITestConstants.PORT;
+ }
+
+ protected URI createDefaultURI() throws Exception {
+ return createURI("foo://" + getAuthority() + ":" + getPort() + "/");
+ }
+
+ protected IServiceProperties createServiceProperties() throws Exception {
+ return new ServiceProperties();
+ }
+
+ protected IServiceInfo createServiceInfo(URI uri, IServiceID serviceID, IServiceProperties serviceProperties) throws Exception {
+ return new ServiceInfo(uri, serviceID, 0, 0, serviceProperties);
+ }
+
+ protected void registerService(IServiceInfo serviceInfo) throws Exception {
+ assertNotNull(serviceInfo);
+ assertNotNull(discoveryContainer);
+ discoveryContainer.registerService(serviceInfo);
+ }
+
+ protected void unregisterService(IServiceInfo serviceInfo) throws Exception {
+ assertNotNull(serviceInfo);
+ assertNotNull(discoveryContainer);
+ discoveryContainer.unregisterService(serviceInfo);
+ }
+
+} \ No newline at end of file
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/DiscoveryTest.java b/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/DiscoveryTest.java
index 5ef949770..b44db79e4 100755
--- a/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/DiscoveryTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/DiscoveryTest.java
@@ -15,34 +15,33 @@ import java.net.URI;
import java.util.Comparator;
import java.util.Properties;
-import junit.framework.TestCase;
-
import org.eclipse.core.runtime.AssertionFailedException;
import org.eclipse.ecf.core.ContainerConnectException;
import org.eclipse.ecf.core.ContainerFactory;
-import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.core.util.ECFException;
import org.eclipse.ecf.discovery.IDiscoveryContainerAdapter;
+import org.eclipse.ecf.discovery.IServiceEvent;
import org.eclipse.ecf.discovery.IServiceInfo;
+import org.eclipse.ecf.discovery.IServiceTypeEvent;
+import org.eclipse.ecf.discovery.IServiceTypeListener;
import org.eclipse.ecf.discovery.ServiceInfo;
import org.eclipse.ecf.discovery.ServiceProperties;
import org.eclipse.ecf.discovery.identity.IServiceID;
+import org.eclipse.ecf.discovery.identity.IServiceTypeID;
import org.eclipse.ecf.discovery.identity.ServiceIDFactory;
-import org.eclipse.ecf.tests.discovery.listener.TestServiceListener;
+import org.eclipse.ecf.tests.discovery.listener.TestListener;
-public abstract class DiscoveryTest extends TestCase {
+public abstract class DiscoveryTest extends AbstractDiscoveryTest {
- protected IContainer container = null;
- protected IDiscoveryContainerAdapter discoveryContainer = null;
- protected String containerUnderTest;
- protected ServiceInfo serviceInfo;
- protected ServiceInfo serviceInfo2;
- protected ServiceInfo serviceInfo3;
- protected long waitTimeForProvider;
- protected Comparator comparator;
+ protected IServiceInfo serviceInfo;
+ protected IServiceID serviceID;
+ protected IServiceInfo serviceInfo2;
+ protected IServiceID serviceID2;
+ protected IServiceInfo serviceInfo3;
+ protected IServiceID serviceID3;
/**
* @param name
@@ -79,21 +78,21 @@ public abstract class DiscoveryTest extends TestCase {
final Properties props = new Properties();
final URI uri = new URI(ITestConstants.URI);
- final IServiceID serviceID = (IServiceID) IDFactory.getDefault().createID(discoveryContainer.getServicesNamespace(), new Object[] {ITestConstants.SERVICE_TYPE, ITestConstants.HOST});
+ serviceID = (IServiceID) IDFactory.getDefault().createID(discoveryContainer.getServicesNamespace(), new Object[] {ITestConstants.SERVICE_TYPE, ITestConstants.HOST});
assertNotNull(serviceID);
final ServiceProperties serviceProperties = new ServiceProperties(props);
serviceProperties.setPropertyString("serviceProperties", "serviceProperties");
serviceInfo = new ServiceInfo(uri, serviceID, 0, 0, serviceProperties);
assertNotNull(serviceInfo);
- final IServiceID serviceID2 = (IServiceID) IDFactory.getDefault().createID(discoveryContainer.getServicesNamespace(), new Object[] {ITestConstants.SERVICE_TYPE2, ITestConstants.HOST});
+ serviceID2 = (IServiceID) IDFactory.getDefault().createID(discoveryContainer.getServicesNamespace(), new Object[] {ITestConstants.SERVICE_TYPE2, ITestConstants.HOST});
assertNotNull(serviceID);
final ServiceProperties serviceProperties2 = new ServiceProperties(props);
serviceProperties2.setPropertyString("serviceProperties2", "serviceProperties2");
serviceInfo2 = new ServiceInfo(uri, serviceID2, 2, 2, serviceProperties2);
assertNotNull(serviceInfo2);
- final IServiceID serviceID3 = (IServiceID) IDFactory.getDefault().createID(discoveryContainer.getServicesNamespace(), new Object[] {ITestConstants.SERVICE_TYPE3, ITestConstants.HOST});
+ serviceID3 = (IServiceID) IDFactory.getDefault().createID(discoveryContainer.getServicesNamespace(), new Object[] {ITestConstants.SERVICE_TYPE3, ITestConstants.HOST});
assertNotNull(serviceID);
final ServiceProperties serviceProperties3 = new ServiceProperties(props);
serviceProperties3.setPropertyString("serviceProperties3", "serviceProperties3");
@@ -101,12 +100,6 @@ public abstract class DiscoveryTest extends TestCase {
assertNotNull(serviceInfo3);
}
- protected IDiscoveryContainerAdapter getAdapter(Class clazz) {
- final IDiscoveryContainerAdapter adapter = (IDiscoveryContainerAdapter) container.getAdapter(clazz);
- assertNotNull("Adapter must not be null", adapter);
- return adapter;
- }
-
/*
* (non-Javadoc)
*
@@ -121,6 +114,22 @@ public abstract class DiscoveryTest extends TestCase {
container = null;
}
+ protected void registerService() {
+ try {
+ discoveryContainer.registerService(serviceInfo);
+ } catch (final ECFException e) {
+ fail("IServiceInfo may be valid with this IDCA");
+ }
+ }
+
+ protected void unregisterService() {
+ try {
+ discoveryContainer.unregisterService(serviceInfo);
+ } catch (final ECFException e) {
+ fail("unregistering of " + serviceInfo + " should just work");
+ }
+ }
+
public void testConnect() {
assertNull(container.getConnectedID());
try {
@@ -158,11 +167,7 @@ public abstract class DiscoveryTest extends TestCase {
*/
public void testGetServiceInfo() {
testConnect();
- try {
- discoveryContainer.registerService(serviceInfo);
- } catch (final ECFException e) {
- fail("IServiceInfo may be valid with this IDCA");
- }
+ registerService();
final IServiceInfo info = discoveryContainer.getServiceInfo(serviceInfo.getServiceID());
assertTrue("IServiceInfo should match, expected:\n" + serviceInfo + " but:\n" + info, comparator.compare(info, serviceInfo) == 0);
}
@@ -185,7 +190,10 @@ public abstract class DiscoveryTest extends TestCase {
* {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServiceTypes()}.
*/
public void testGetServiceTypes() {
- fail("Not yet implemented");
+ testConnect();
+ registerService();
+ final IServiceTypeID[] serviceTypeIDs = discoveryContainer.getServiceTypes();
+ assertTrue(serviceTypeIDs.length > 0);
}
/**
@@ -194,11 +202,7 @@ public abstract class DiscoveryTest extends TestCase {
*/
public void testGetServices() {
testConnect();
- try {
- discoveryContainer.registerService(serviceInfo);
- } catch (final ECFException e) {
- fail("IServiceInfo may be valid with this IDCA");
- }
+ registerService();
final IServiceInfo[] services = discoveryContainer.getServices();
assertTrue(services.length >= 1);
}
@@ -208,7 +212,10 @@ public abstract class DiscoveryTest extends TestCase {
* {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServices(org.eclipse.ecf.discovery.identity.IServiceTypeID)}.
*/
public void testGetServicesIServiceTypeID() {
- fail("Not yet implemented");
+ testConnect();
+ registerService();
+ final IServiceInfo serviceInfo[] = discoveryContainer.getServices(serviceID.getServiceTypeID());
+ assertTrue(serviceInfo.length > 0);
}
/**
@@ -230,11 +237,7 @@ public abstract class DiscoveryTest extends TestCase {
*/
public void testRegisterService() {
testConnect();
- try {
- discoveryContainer.registerService(serviceInfo);
- } catch (final ECFException e) {
- fail("IServiceInfo may be valid with this IDCA");
- }
+ registerService();
final IServiceInfo[] services = discoveryContainer.getServices();
assertTrue(services.length >= 1);
for (int i = 0; i < services.length; i++) {
@@ -268,11 +271,7 @@ public abstract class DiscoveryTest extends TestCase {
*/
public void testUnregisterService() {
testRegisterService();
- try {
- discoveryContainer.unregisterService(serviceInfo);
- } catch (final ECFException e) {
- fail("unregistering of " + serviceInfo + " should just work");
- }
+ unregisterService();
final IServiceInfo[] services = discoveryContainer.getServices();
for (int i = 0; i < services.length; i++) {
final IServiceInfo service = services[i];
@@ -310,12 +309,21 @@ public abstract class DiscoveryTest extends TestCase {
fail("A disposed container must not be reusable");
}
+ protected void addServiceListener(TestListener serviceListener) {
+ discoveryContainer.addServiceListener(serviceListener);
+ addListenerRegisterAndWait(serviceListener, serviceInfo);
+ assertTrue("IServiceInfo mismatch", comparator.compare(((IServiceEvent) serviceListener.getEvent()).getServiceInfo(), serviceInfo) == 0);
+ }
+
/**
* Test method for
* {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#addServiceListener(org.eclipse.ecf.discovery.IServiceListener)}.
*/
public void testAddServiceListenerIServiceListener() {
- addListener(new TestServiceListener(), serviceInfo);
+ testConnect();
+ assertTrue("No Services must be registerd at this point", discoveryContainer.getServices().length == 0);
+ final TestListener tsl = new TestListener();
+ addServiceListener(tsl);
}
/**
@@ -336,22 +344,19 @@ public abstract class DiscoveryTest extends TestCase {
* {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#addServiceListener(org.eclipse.ecf.discovery.identity.IServiceTypeID, org.eclipse.ecf.discovery.IServiceListener)}.
*/
public void testAddServiceListenerIServiceTypeIDIServiceListener() {
- addListener(new TestServiceListener(), serviceInfo);
- }
-
- private void addListener(TestServiceListener testServiceListener, IServiceInfo aServiceInfo) {
testConnect();
assertTrue("No Services must be registerd at this point", discoveryContainer.getServices().length == 0);
- discoveryContainer.addServiceListener(testServiceListener);
+ final TestListener tsl = new TestListener();
+ discoveryContainer.addServiceListener(serviceID.getServiceTypeID(), tsl);
+ addListenerRegisterAndWait(tsl, serviceInfo);
+ assertTrue("IServiceInfo mismatch", comparator.compare(((IServiceEvent) tsl.getEvent()).getServiceInfo(), serviceInfo) == 0);
+ }
+ private void addListenerRegisterAndWait(TestListener testServiceListener, IServiceInfo aServiceInfo) {
synchronized (testServiceListener) {
// register a service which we expect the test listener to get notified of
- try {
- discoveryContainer.registerService(serviceInfo);
- } catch (final ECFException e) {
- fail("IServiceInfo may be valid with this IDCA");
- }
+ registerService();
int i = 0;
while (!testServiceListener.isDone() && i++ < 10) {
try {
@@ -366,7 +371,6 @@ public abstract class DiscoveryTest extends TestCase {
}
assertNotNull("Test listener didn't receive discovery", testServiceListener.getEvent());
assertTrue("Container mismatch", testServiceListener.getEvent().getLocalContainerID().equals(container.getConnectedID()));
- assertTrue("IServiceInfo mismatch", comparator.compare(testServiceListener.getEvent().getServiceInfo(), aServiceInfo) == 0);
}
/**
@@ -387,7 +391,21 @@ public abstract class DiscoveryTest extends TestCase {
* {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#addServiceTypeListener(org.eclipse.ecf.discovery.IServiceTypeListener)}.
*/
public void testAddServiceTypeListener() {
- fail("Not yet implemented");
+ testConnect();
+ final IServiceTypeListener serviceTypeListener = createServiceTypeListener();
+ discoveryContainer.addServiceTypeListener(serviceTypeListener);
+ }
+
+ /**
+ * @return
+ */
+ protected IServiceTypeListener createServiceTypeListener() {
+ return new IServiceTypeListener() {
+
+ public void serviceTypeDiscovered(IServiceTypeEvent event) {
+ System.out.println("serviceTypeDiscovered(" + event + ")");
+ }
+ };
}
/**
@@ -442,7 +460,10 @@ public abstract class DiscoveryTest extends TestCase {
* {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#removeServiceListener(org.eclipse.ecf.discovery.IServiceListener)}.
*/
public void testRemoveServiceListenerIServiceListener() {
- fail("Not yet implemented");
+ testConnect();
+ final TestListener serviceListener = new TestListener();
+ addServiceListener(serviceListener);
+ discoveryContainer.removeServiceListener(serviceListener);
}
/**
@@ -463,7 +484,10 @@ public abstract class DiscoveryTest extends TestCase {
* {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#removeServiceListener(org.eclipse.ecf.discovery.identity.IServiceTypeID, org.eclipse.ecf.discovery.IServiceListener)}.
*/
public void testRemoveServiceListenerIServiceTypeIDIServiceListener() {
- fail("Not yet implemented");
+ testConnect();
+ final TestListener serviceListener = new TestListener();
+ addServiceListener(serviceListener);
+ discoveryContainer.removeServiceListener(serviceID.getServiceTypeID(), serviceListener);
}
/**
@@ -484,7 +508,10 @@ public abstract class DiscoveryTest extends TestCase {
* {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#removeServiceTypeListener(org.eclipse.ecf.discovery.IServiceTypeListener)}.
*/
public void testRemoveServiceTypeListener() {
- fail("Not yet implemented");
+ testConnect();
+ final TestListener serviceTypeListener = new TestListener();
+ addServiceListener(serviceTypeListener);
+ discoveryContainer.removeServiceTypeListener(serviceTypeListener);
}
/**
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/listener/AbstractTestListener.java b/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/listener/AbstractTestListener.java
deleted file mode 100755
index 4680b64a1..000000000
--- a/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/listener/AbstractTestListener.java
+++ /dev/null
@@ -1,18 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Versant Corp.
- * 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:
- * Markus Kuppe (mkuppe <at> versant <dot> com) - initial API and implementation
- ******************************************************************************/
-package org.eclipse.ecf.tests.discovery.listener;
-
-
-public abstract class AbstractTestListener {
-
- public AbstractTestListener() {
- }
-}
diff --git a/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/listener/TestServiceListener.java b/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/listener/TestListener.java
index 64b848470..cbd56aa96 100755
--- a/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/listener/TestServiceListener.java
+++ b/tests/bundles/org.eclipse.ecf.tests.discovery/src/org/eclipse/ecf/tests/discovery/listener/TestListener.java
@@ -10,40 +10,42 @@
******************************************************************************/
package org.eclipse.ecf.tests.discovery.listener;
+import org.eclipse.ecf.core.events.IContainerEvent;
import org.eclipse.ecf.discovery.IServiceEvent;
import org.eclipse.ecf.discovery.IServiceListener;
+import org.eclipse.ecf.discovery.IServiceTypeEvent;
+import org.eclipse.ecf.discovery.IServiceTypeListener;
-public class TestServiceListener extends AbstractTestListener implements IServiceListener {
+public class TestListener implements IServiceListener, IServiceTypeListener {
- private IServiceEvent event;
+ private IContainerEvent event;
- public TestServiceListener() {
- super();
+ public TestListener() {
}
public boolean isDone() {
return event != null;
}
- /* (non-Javadoc)
- * @see org.eclipse.ecf.discovery.IServiceListener#serviceDiscovered(org.eclipse.ecf.discovery.IServiceEvent)
+ /**
+ * @return the event
*/
+ public IContainerEvent getEvent() {
+ return event;
+ }
+
public void serviceDiscovered(IServiceEvent anEvent) {
event = anEvent;
}
- /* (non-Javadoc)
- * @see org.eclipse.ecf.discovery.IServiceListener#serviceUndiscovered(org.eclipse.ecf.discovery.IServiceEvent)
- */
public void serviceUndiscovered(IServiceEvent anEvent) {
- //TODO-mkuppe implement TestServiceListener#serviceUndiscovered
throw new java.lang.UnsupportedOperationException("TestServiceListener#serviceUndiscovered not yet implemented");
}
- /**
- * @return the event
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IServiceTypeListener#serviceTypeDiscovered(org.eclipse.ecf.discovery.IServiceTypeEvent)
*/
- public IServiceEvent getEvent() {
- return event;
+ public void serviceTypeDiscovered(IServiceTypeEvent event) {
+ this.event = event;
}
}

Back to the top