Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/empty.txt2
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeDiscoveryContainerTest.java127
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeServiceInfoComporator.java54
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/TestDiscoveryContainer.java236
4 files changed, 417 insertions, 2 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/empty.txt b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/empty.txt
deleted file mode 100644
index cb9bb599a..000000000
--- a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/empty.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-
- \ No newline at end of file
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeDiscoveryContainerTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeDiscoveryContainerTest.java
new file mode 100644
index 000000000..8991012d0
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeDiscoveryContainerTest.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Markus Alexander Kuppe.
+ * 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 Alexander Kuppe (ecf-dev_eclipse.org <at> lemmster <dot> de) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.tests.provider.discovery;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.ecf.core.ContainerConnectException;
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.events.IContainerEvent;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.util.ECFRuntimeException;
+import org.eclipse.ecf.discovery.IServiceEvent;
+import org.eclipse.ecf.discovery.IServiceInfo;
+import org.eclipse.ecf.discovery.identity.IServiceTypeID;
+import org.eclipse.ecf.provider.discovery.CompositeDiscoveryContainer;
+import org.eclipse.ecf.provider.discovery.CompositeServiceContainerEvent;
+import org.eclipse.ecf.tests.discovery.DiscoveryContainerTest;
+import org.eclipse.ecf.tests.discovery.listener.TestServiceListener;
+
+public class CompositeDiscoveryContainerTest extends DiscoveryContainerTest {
+
+ private TestDiscoveryContainer testDiscoveryContainer;
+
+ public CompositeDiscoveryContainerTest() {
+ super(CompositeDiscoveryContainer.NAME);
+ setComparator(new CompositeServiceInfoComporator());
+ //TODO jSLP currently has the longer rediscovery interval
+ setWaitTimeForProvider(Long.parseLong(System.getProperty("net.slp.rediscover", new Long(60L * 1000L).toString()))); //$NON-NLS-1$);
+ //TODO-mkuppe https://bugs.eclipse.org/bugs/show_bug.cgi?id=218308
+ setScope(IServiceTypeID.DEFAULT_SCOPE[0]);
+ setHostname(System.getProperty("net.mdns.interface", "127.0.0.1"));
+ }
+
+// /* (non-Javadoc)
+// * @see org.eclipse.ecf.tests.discovery.DiscoveryTest#setUp()
+// */
+// protected void setUp() throws Exception {
+// super.setUp();
+// eventsToExpect = ((CompositeDiscoveryContainer) discoveryLocator).getDiscoveryContainers().size();
+// }
+//
+// /**
+// * Check if
+// * @throws ContainerConnectException
+// */
+ public void testAddContainerWithRegisteredServices() throws ContainerConnectException {
+// try {
+// try {
+// discoveryAdvertiser.registerService(serviceInfo);
+// } catch (ECFRuntimeException e) {
+// fail("Registering a service failed on a new IDCA");
+// }
+// CompositeDiscoveryContainer cdc = (CompositeDiscoveryContainer) discoveryLocator;
+// testDiscoveryContainer = new TestDiscoveryContainer();
+// assertTrue(cdc.addContainer(testDiscoveryContainer));
+// List registeredServices = testDiscoveryContainer.getRegisteredServices();
+// assertEquals("registerService(aService) wasn't called on TestDiscoveryContainer", serviceInfo, registeredServices.get(0));
+// } finally {
+// CompositeDiscoveryContainer cdc = (CompositeDiscoveryContainer) discoveryLocator;
+// cdc.removeContainer(testDiscoveryContainer);
+// }
+ }
+//
+// public void testAddContainerWithoutRegisteredServices() throws ContainerConnectException {
+// try {
+// try {
+// discoveryAdvertiser.registerService(serviceInfo);
+// discoveryAdvertiser.unregisterService(serviceInfo);
+// } catch (ECFRuntimeException e) {
+// fail("Re-/Unregistering a service failed on a new IDCA");
+// }
+// CompositeDiscoveryContainer cdc = (CompositeDiscoveryContainer) discoveryLocator;
+// testDiscoveryContainer = new TestDiscoveryContainer();
+// assertTrue(cdc.addContainer(testDiscoveryContainer));
+// List registeredServices = testDiscoveryContainer.getRegisteredServices();
+// assertTrue(registeredServices.isEmpty());
+// } finally {
+// CompositeDiscoveryContainer cdc = (CompositeDiscoveryContainer) discoveryLocator;
+// cdc.removeContainer(testDiscoveryContainer);
+// }
+// }
+//
+// protected void addServiceListener(TestServiceListener serviceListener) {
+// discoveryLocator.addServiceListener(serviceListener);
+// addListenerRegisterAndWait(serviceListener, serviceInfo);
+// discoveryLocator.removeServiceListener(serviceListener);
+//
+// // make sure we use a live container;
+// final IContainer ic = (IContainer) serviceListener.getLocator();
+// assertTrue(ic.getConnectedID() != null);
+//
+// // check if we received correct amount of events
+// final IContainerEvent[] events = serviceListener.getEvent();
+// assertNotNull("Test listener didn't receive any discovery events.", events);
+// assertEquals("Test listener received unexpected amount of discovery events: \n\t" + Arrays.asList(events), eventsToExpect, events.length);
+//
+// final List origContainers = new ArrayList();
+// for (int i = 0; i < events.length; i++) {
+// final CompositeServiceContainerEvent event = (CompositeServiceContainerEvent) events[i];
+//
+// // check if the local container is hidden correctly
+// final ID localContainerId = event.getLocalContainerID();
+// final ID connectedId = container.getConnectedID();
+// assertEquals(localContainerId, connectedId);
+//
+// // check the IServiceInfo for correct fields/properties
+// final IServiceInfo serviceInfo2 = ((IServiceEvent) event).getServiceInfo();
+// assertTrue("IServiceInfo should match, expected:\n\t" + serviceInfo + " but was \n\t" + serviceInfo2, comparator.compare(serviceInfo2, serviceInfo) == 0);
+//
+// // add the underlying discovery container the the result set
+// origContainers.add(event.getOriginalLocalContainerID());
+// }
+// // check that all underlying containers fired an event
+// assertEquals("A nested container didn't send an event, but another multiple.", eventsToExpect, origContainers.size());
+// }
+
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeServiceInfoComporator.java b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeServiceInfoComporator.java
new file mode 100644
index 000000000..7654383ec
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeServiceInfoComporator.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.provider.discovery;
+
+import java.net.URI;
+
+import org.eclipse.ecf.discovery.IServiceInfo;
+import org.eclipse.ecf.discovery.identity.IServiceID;
+import org.eclipse.ecf.tests.discovery.ServiceInfoComparator;
+
+public class CompositeServiceInfoComporator extends ServiceInfoComparator {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.tests.discovery.ServiceInfoComparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(Object arg0, Object arg1) {
+ if (arg0 instanceof IServiceInfo && arg1 instanceof IServiceInfo) {
+ final IServiceInfo first = (IServiceInfo) arg0;
+ final IServiceInfo second = (IServiceInfo) arg1;
+ boolean priority = first.getPriority() == second.getPriority();
+ boolean weight = first.getWeight() == second.getWeight();
+
+ final URI uri1 = first.getLocation();
+ final URI uri2 = second.getLocation();
+ boolean port = uri1.getPort() == uri2.getPort();
+ boolean host = uri1.getHost().equals(uri2.getHost());
+
+ final IServiceID firstID = first.getServiceID();
+ final IServiceID secondID = second.getServiceID();
+ boolean serviceType = firstID.getServiceTypeID().equals(secondID.getServiceTypeID());
+ boolean serviceName = firstID.getServiceName().equals(secondID.getServiceName());
+
+ String firstName = firstID.getName();
+ String secondName = secondID.getName();
+ boolean name = firstName.equals(secondName);
+
+ boolean serviceProperties = compareServiceProperties(first.getServiceProperties(), second.getServiceProperties());
+
+ final boolean result = name && serviceType && serviceName && host && port && priority && weight && serviceProperties;
+ if (result == true) {
+ return 0;
+ }
+ }
+ return -1;
+ }
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/TestDiscoveryContainer.java b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/TestDiscoveryContainer.java
new file mode 100644
index 000000000..822c6c9e3
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/TestDiscoveryContainer.java
@@ -0,0 +1,236 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.provider.discovery;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.ecf.core.ContainerConnectException;
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.IContainerListener;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.core.security.IConnectContext;
+import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
+import org.eclipse.ecf.discovery.IDiscoveryLocator;
+import org.eclipse.ecf.discovery.IServiceInfo;
+import org.eclipse.ecf.discovery.IServiceListener;
+import org.eclipse.ecf.discovery.IServiceTypeListener;
+import org.eclipse.ecf.discovery.identity.IServiceID;
+import org.eclipse.ecf.discovery.identity.IServiceTypeID;
+import org.eclipse.equinox.concurrent.future.IFuture;
+
+public class TestDiscoveryContainer implements IDiscoveryLocator, IDiscoveryAdvertiser, IContainer {
+
+ private List services = new ArrayList();
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#addServiceListener(org.eclipse.ecf.discovery.IServiceListener)
+ */
+ public void addServiceListener(IServiceListener listener) {
+ // nop
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#addServiceListener(org.eclipse.ecf.discovery.identity.IServiceTypeID, org.eclipse.ecf.discovery.IServiceListener)
+ */
+ public void addServiceListener(IServiceTypeID type,
+ IServiceListener listener) {
+ // nop
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#addServiceTypeListener(org.eclipse.ecf.discovery.IServiceTypeListener)
+ */
+ public void addServiceTypeListener(IServiceTypeListener listener) {
+ // nop
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServiceInfo(org.eclipse.ecf.discovery.identity.IServiceID)
+ */
+ public IServiceInfo getServiceInfo(IServiceID service) {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServiceTypes()
+ */
+ public IServiceTypeID[] getServiceTypes() {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServices()
+ */
+ public IServiceInfo[] getServices() {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServices(org.eclipse.ecf.discovery.identity.IServiceTypeID)
+ */
+ public IServiceInfo[] getServices(IServiceTypeID type) {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServicesNamespace()
+ */
+ public Namespace getServicesNamespace() {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#registerService(org.eclipse.ecf.discovery.IServiceInfo)
+ */
+ public void registerService(IServiceInfo serviceInfo) {
+ this.services.add(serviceInfo);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#removeServiceListener(org.eclipse.ecf.discovery.IServiceListener)
+ */
+ public void removeServiceListener(IServiceListener listener) {
+ // nop
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#removeServiceListener(org.eclipse.ecf.discovery.identity.IServiceTypeID, org.eclipse.ecf.discovery.IServiceListener)
+ */
+ public void removeServiceListener(IServiceTypeID type,
+ IServiceListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#removeServiceTypeListener(org.eclipse.ecf.discovery.IServiceTypeListener)
+ */
+ public void removeServiceTypeListener(IServiceTypeListener listener) {
+ // nop
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#unregisterService(org.eclipse.ecf.discovery.IServiceInfo)
+ */
+ public void unregisterService(IServiceInfo serviceInfo) {
+ this.services.remove(serviceInfo);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class adapter) {
+ throw new UnsupportedOperationException();
+ }
+
+ public List getRegisteredServices() {
+ return services;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryLocator#purgeCache()
+ */
+ public IServiceInfo[] purgeCache() {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryAsyncLocator#getAsyncServiceInfo(org.eclipse.ecf.discovery.identity.IServiceID)
+ */
+ public IFuture getAsyncServiceInfo(IServiceID aServiceId) {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryAsyncLocator#getAsyncServiceTypes()
+ */
+ public IFuture getAsyncServiceTypes() {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryAsyncLocator#getAsyncServices()
+ */
+ public IFuture getAsyncServices() {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryAsyncLocator#getAsyncServices(org.eclipse.ecf.discovery.identity.IServiceTypeID)
+ */
+ public IFuture getAsyncServices(IServiceTypeID aServiceTypeId) {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.IDiscoveryAdvertiser#unregisterAllServices()
+ */
+ public void unregisterAllServices() {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.IContainer#addListener(org.eclipse.ecf.core.IContainerListener)
+ */
+ public void addListener(IContainerListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void connect(ID targetId, IConnectContext connectContext)
+ throws ContainerConnectException {
+ // nop
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.IContainer#disconnect()
+ */
+ public void disconnect() {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.IContainer#dispose()
+ */
+ public void dispose() {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.IContainer#getConnectNamespace()
+ */
+ public Namespace getConnectNamespace() {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.IContainer#getConnectedID()
+ */
+ public ID getConnectedID() {
+ return IDFactory.getDefault().createStringID(getClass().getName());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.IContainer#removeListener(org.eclipse.ecf.core.IContainerListener)
+ */
+ public void removeListener(IContainerListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.identity.IIdentifiable#getID()
+ */
+ public ID getID() {
+ throw new UnsupportedOperationException();
+ }
+}

Back to the top