Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorslewis2016-01-12 01:18:16 -0500
committerslewis2016-01-12 01:18:16 -0500
commiteb6a0e835f7d2be728be6de7674e0cc483a78e2e (patch)
treebb7842c92b14b8df161fe8009edba5a6ba73ef51 /tests
parent09083a599c071c9429924619fa9745b205900f1d (diff)
downloadorg.eclipse.ecf-eb6a0e835f7d2be728be6de7674e0cc483a78e2e.tar.gz
org.eclipse.ecf-eb6a0e835f7d2be728be6de7674e0cc483a78e2e.tar.xz
org.eclipse.ecf-eb6a0e835f7d2be728be6de7674e0cc483a78e2e.zip
Removed CompositeDiscoveryContainer tests from AllTests suite in
org.eclipse.ecf.tests.provider.discovery Change-Id: I0000000000000000000000000000000000000000
Diffstat (limited to 'tests')
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/META-INF/MANIFEST.MF1
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/AllTests.java (renamed from tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/AllTests.java)0
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/CompositeDiscoveryContainerTest.java127
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/CompositeDiscoveryContainerWithoutRegTest.java (renamed from tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeDiscoveryContainerWithoutRegTest.java)6
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/CompositeDiscoveryServiceContainerTest.java121
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/CompositeServiceInfoComporator.java (renamed from tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeServiceInfoComporator.java)0
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/SingleCompositeDiscoveryServiceContainerTest.java198
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/TestDiscoveryContainer.java (renamed from tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/TestDiscoveryContainer.java)0
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/WithoutJMDNSCompositeDiscoveryServiceContainerTest.java (renamed from tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/WithoutJMDNSCompositeDiscoveryServiceContainerTest.java)0
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/WithoutJSLPCompositeDiscoveryServiceContainerTest.java (renamed from tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/WithoutJSLPCompositeDiscoveryServiceContainerTest.java)0
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeDiscoveryContainerTest.java126
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeDiscoveryServiceContainerTest.java121
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/SingleCompositeDiscoveryServiceContainerTest.java198
13 files changed, 449 insertions, 449 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/META-INF/MANIFEST.MF b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/META-INF/MANIFEST.MF
index 62b210376..48a0ae60c 100644
--- a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/META-INF/MANIFEST.MF
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/META-INF/MANIFEST.MF
@@ -18,4 +18,3 @@ Require-Bundle: org.junit,
Bundle-Vendor: %plugin.provider
Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
J2SE-1.4
-Export-Package: org.eclipse.ecf.tests.provider.discovery;version="2.1.0"
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/AllTests.java b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/AllTests.java
index 98d77368a..98d77368a 100644
--- a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/AllTests.java
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/AllTests.java
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/CompositeDiscoveryContainerTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/CompositeDiscoveryContainerTest.java
new file mode 100644
index 000000000..3f51b4f6e
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/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/CompositeDiscoveryContainerWithoutRegTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/CompositeDiscoveryContainerWithoutRegTest.java
index 8e6f585ac..5ee9bd5e7 100644
--- a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeDiscoveryContainerWithoutRegTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/CompositeDiscoveryContainerWithoutRegTest.java
@@ -16,8 +16,8 @@ import org.eclipse.ecf.tests.discovery.DiscoveryTestsWithoutRegister;
public class CompositeDiscoveryContainerWithoutRegTest extends
DiscoveryTestsWithoutRegister {
- public CompositeDiscoveryContainerWithoutRegTest() {
- super(CompositeDiscoveryContainer.NAME);
- }
+// public CompositeDiscoveryContainerWithoutRegTest() {
+// super(CompositeDiscoveryContainer.NAME);
+// }
}
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/CompositeDiscoveryServiceContainerTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/CompositeDiscoveryServiceContainerTest.java
new file mode 100644
index 000000000..ecb914db0
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/CompositeDiscoveryServiceContainerTest.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * 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.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.events.IContainerEvent;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.discovery.IDiscoveryLocator;
+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.DiscoveryServiceTest;
+import org.eclipse.ecf.tests.discovery.listener.TestServiceListener;
+
+public class CompositeDiscoveryServiceContainerTest extends
+ DiscoveryServiceTest {
+
+// private IContainer container;
+//
+// public CompositeDiscoveryServiceContainerTest() {
+// super("ecf.discovery.composite");
+// 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.DiscoveryServiceTest#setUp()
+// */
+// protected void setUp() throws Exception {
+// super.setUp();
+// container = (IContainer) discoveryLocator;
+//
+// final Collection discoveryContainers = ((CompositeDiscoveryContainer) discoveryLocator)
+// .getDiscoveryContainers();
+// final Set s = new HashSet();
+// for (final Iterator itr = discoveryContainers.iterator(); itr.hasNext();) {
+// final IDiscoveryLocator object = (IDiscoveryLocator) itr.next();
+// final IContainer adapter = (IContainer) object
+// .getAdapter(IContainer.class);
+// s.add(adapter.getID());
+// }
+// // make sure it's never (accidentally) modified by a test
+// idsToExpect = Collections.unmodifiableSet(s);
+//
+// eventsToExpect = discoveryContainers.size();
+//
+// assertTrue("zero events make no sense", eventsToExpect > 0);
+// }
+//
+// 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());
+// }
+//
+// protected Collection getContainerIds(IContainerEvent[] events) {
+// final Collection originalIds = new ArrayList();
+// for (int i = 0; i < events.length; i++) {
+// final IContainerEvent iContainerEvent = events[i];
+// if (iContainerEvent instanceof CompositeServiceContainerEvent) {
+// final CompositeServiceContainerEvent csce = (CompositeServiceContainerEvent) iContainerEvent;
+// originalIds.add(csce.getOriginalLocalContainerID());
+// } else {
+// System.err.println("WARNING: Skipping non CompositeServiceContainerEvent in CompositeDiscoveryServiceContainerTest#getContainerIds(IContainerEvent[])");
+// //originalIds.add(iContainerEvent.getLocalContainerID());
+// }
+// }
+// return originalIds;
+// }
+}
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/archive/CompositeServiceInfoComporator.java
index 7654383ec..7654383ec 100644
--- 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/archive/CompositeServiceInfoComporator.java
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/SingleCompositeDiscoveryServiceContainerTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/SingleCompositeDiscoveryServiceContainerTest.java
new file mode 100644
index 000000000..aa9f526e1
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/SingleCompositeDiscoveryServiceContainerTest.java
@@ -0,0 +1,198 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 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.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
+import org.eclipse.ecf.discovery.IDiscoveryLocator;
+import org.eclipse.ecf.provider.discovery.CompositeDiscoveryContainer;
+import org.eclipse.ecf.tests.discovery.Activator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.hooks.service.EventHook;
+import org.osgi.framework.hooks.service.FindHook;
+
+public abstract class SingleCompositeDiscoveryServiceContainerTest extends
+ CompositeDiscoveryServiceContainerTest {
+
+ // Whether the OSGi hooks should be de-/registered after and before each
+ // individual test and not just after/before the test class.
+ // E.g. when tests are executed in random order and thus are interleaved
+ // with other tests, setUp/tearDown has to run after each test. Otherwise
+ // expect test failures.
+// public static boolean SETUP_OSGI_HOOKS_PER_TEST = false;
+//
+// private static int testMethods;
+// private static int testMethodsLeft;
+// private static ServiceRegistration findHook;
+//
+// // count all test methods
+// static {
+// Method[] methods = SingleCompositeDiscoveryServiceContainerTest.class.getMethods();
+// for (int i = 0; i < methods.length; i++) {
+// Method method = methods[i];
+// if (method.getName().startsWith("test") && method.getModifiers() == Modifier.PUBLIC) {
+// testMethods++;
+// }
+// }
+// testMethodsLeft = testMethods;
+// }
+//
+// private final String ecfDiscoveryContainerName;
+// private final String className;
+//
+// public SingleCompositeDiscoveryServiceContainerTest(String anECFDiscoveryContainerName, String aClassName) {
+// ecfDiscoveryContainerName = anECFDiscoveryContainerName;
+// className = aClassName;
+// }
+//
+// private boolean doSetUp() {
+// return SETUP_OSGI_HOOKS_PER_TEST || testMethodsLeft == testMethods;
+// }
+//
+// private boolean doTearDown() {
+// return SETUP_OSGI_HOOKS_PER_TEST || --testMethodsLeft == 0;
+// }
+//
+// /* (non-Javadoc)
+// * @see org.eclipse.ecf.tests.provider.discovery.CompositeDiscoveryServiceContainerTest#setUp()
+// */
+// protected void setUp() throws Exception {
+// // HACK: @BeforeClass JUnit4 functionality
+// if(doSetUp()) {
+// // HACK: forcefully start the (nested) discovery container if it hasn't been started yet
+// // assuming the bundle declares a lazy start buddy policy
+// Class.forName(className);
+//
+// // initially close the existing CDC to get rid of other test left overs
+// Activator.getDefault().closeServiceTracker(containerUnderTest);
+//
+// final BundleContext context = Activator.getDefault().getContext();
+// final String[] clazzes = new String[]{FindHook.class.getName(), EventHook.class.getName()};
+// findHook = context.registerService(clazzes, new DiscoveryContainerFilterHook(ecfDiscoveryContainerName), null);
+// }
+// super.setUp();
+// }
+//
+// /* (non-Javadoc)
+// * @see org.eclipse.ecf.tests.discovery.DiscoveryTest#tearDown()
+// */
+// protected void tearDown() throws Exception {
+// super.tearDown();
+// // HACK: @BeforeClass JUnit4 functionality
+// if(doTearDown()) {
+// if(findHook != null) {
+// findHook.unregister();
+// findHook = null;
+// }
+// // close tracker to force creation of a new CDC instance
+// Activator.getDefault().closeServiceTracker(containerUnderTest);
+//
+// // reset so other instances can reuse
+// testMethodsLeft = testMethods;
+// }
+// }
+//
+// /* (non-Javadoc)
+// * @see org.eclipse.ecf.tests.discovery.DiscoveryServiceTest#getDiscoveryLocator()
+// */
+// protected IDiscoveryLocator getDiscoveryLocator() {
+// final IDiscoveryLocator idl = super.getDiscoveryLocator();
+// checkCompositeDiscoveryContainer(className, (CompositeDiscoveryContainer)idl);
+// return idl;
+// }
+//
+//
+// /* (non-Javadoc)
+// * @see org.eclipse.ecf.tests.discovery.DiscoveryServiceTest#getDiscoveryAdvertiser()
+// */
+// protected IDiscoveryAdvertiser getDiscoveryAdvertiser() {
+// final IDiscoveryAdvertiser ida = super.getDiscoveryAdvertiser();
+// checkCompositeDiscoveryContainer(className, (CompositeDiscoveryContainer)ida);
+// return ida;
+// }
+//
+// // make sure the CDC has only a single IDC registered with the correct type
+// private static void checkCompositeDiscoveryContainer(final String aClassName, final CompositeDiscoveryContainer cdc) {
+// final Collection discoveryContainers = cdc.getDiscoveryContainers();
+// assertTrue("One IDiscoveryContainer must be registered with the CDC at this point: " + discoveryContainers, discoveryContainers.size() == 1);
+// for (final Iterator iterator = discoveryContainers.iterator(); iterator.hasNext();) {
+// final IDiscoveryLocator dl = (IDiscoveryLocator) iterator.next();
+// assertEquals(aClassName, dl.getClass().getName());
+// }
+// }
+//
+// // Filters the corresponding IDC from the result set that is _not_ supposed to be part of the test
+// // we need an EventHook too because due to ECF's namespaces the "other" bundle is started asynchronously
+// // and consequently registered with the CDC
+// private class DiscoveryContainerFilterHook implements FindHook, EventHook {
+//
+// private static final String BUNDLE_UNDER_TEST = "org.eclipse.ecf.provider.discovery"; // rename if bundle name change
+// private final String containerName;
+//
+// public DiscoveryContainerFilterHook(String anECFDiscoveryContainerName) {
+// containerName = anECFDiscoveryContainerName;
+// }
+//
+// /* (non-Javadoc)
+// * @see org.osgi.framework.hooks.service.FindHook#find(org.osgi.framework.BundleContext, java.lang.String, java.lang.String, boolean, java.util.Collection)
+// */
+// public void find(BundleContext context, String name, String filter, boolean allServices, Collection references) {
+//
+// // is it the composite discovery bundle who tries to find the service?
+// final String symbolicName = context.getBundle().getSymbolicName();
+// final Collection removees = new ArrayList();
+// if(BUNDLE_UNDER_TEST.equals(symbolicName)) {
+// for (final Iterator iterator = references.iterator(); iterator.hasNext();) {
+// // filter the corresponding container
+// final ServiceReference serviceReference = (ServiceReference) iterator.next();
+// final String property = (String) serviceReference.getProperty(IDiscoveryLocator.CONTAINER_NAME);
+// if(property != null && property.equals(containerName)) {
+// removees.add(serviceReference);
+// System.out.println("Removed reference: " + property);
+// break;
+// }
+// }
+// references.removeAll(removees);
+// }
+// }
+//
+// /* (non-Javadoc)
+// * @see org.osgi.framework.hooks.service.EventHook#event(org.osgi.framework.ServiceEvent, java.util.Collection)
+// */
+// public void event(ServiceEvent aServiceEvent, Collection aCollection) {
+// if (aServiceEvent.getType() == ServiceEvent.REGISTERED) {
+// final ServiceReference serviceReference = aServiceEvent.getServiceReference();
+// final String property = (String) serviceReference.getProperty(IDiscoveryLocator.CONTAINER_NAME);
+// if(property != null && property.equals(containerName)) {
+// final Collection removees = new ArrayList();
+// for (Iterator iterator = aCollection.iterator(); iterator.hasNext();) {
+// final BundleContext bundleContext = (BundleContext) iterator.next();
+// final String symbolicName = bundleContext.getBundle().getSymbolicName();
+// if(BUNDLE_UNDER_TEST.equals(symbolicName)) {
+// removees.add(bundleContext);
+// System.out.println("Filtered reference: " + property);
+// break;
+// }
+// }
+// aCollection.removeAll(removees);
+// }
+// }
+// }
+// }
+}
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/archive/TestDiscoveryContainer.java
index 822c6c9e3..822c6c9e3 100644
--- 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/archive/TestDiscoveryContainer.java
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/WithoutJMDNSCompositeDiscoveryServiceContainerTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/WithoutJMDNSCompositeDiscoveryServiceContainerTest.java
index d83a4c7a3..d83a4c7a3 100644
--- a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/WithoutJMDNSCompositeDiscoveryServiceContainerTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/WithoutJMDNSCompositeDiscoveryServiceContainerTest.java
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/WithoutJSLPCompositeDiscoveryServiceContainerTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/WithoutJSLPCompositeDiscoveryServiceContainerTest.java
index b54b1f105..b54b1f105 100644
--- a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/WithoutJSLPCompositeDiscoveryServiceContainerTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/archive/WithoutJSLPCompositeDiscoveryServiceContainerTest.java
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
deleted file mode 100644
index c846a4016..000000000
--- a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeDiscoveryContainerTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*******************************************************************************
- * 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/CompositeDiscoveryServiceContainerTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeDiscoveryServiceContainerTest.java
deleted file mode 100644
index 37917c44a..000000000
--- a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/CompositeDiscoveryServiceContainerTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*******************************************************************************
- * 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.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.ecf.core.IContainer;
-import org.eclipse.ecf.core.events.IContainerEvent;
-import org.eclipse.ecf.core.identity.ID;
-import org.eclipse.ecf.discovery.IDiscoveryLocator;
-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.DiscoveryServiceTest;
-import org.eclipse.ecf.tests.discovery.listener.TestServiceListener;
-
-public class CompositeDiscoveryServiceContainerTest extends
- DiscoveryServiceTest {
-
- private IContainer container;
-
- public CompositeDiscoveryServiceContainerTest() {
- super("ecf.discovery.composite");
- 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.DiscoveryServiceTest#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- container = (IContainer) discoveryLocator;
-
- final Collection discoveryContainers = ((CompositeDiscoveryContainer) discoveryLocator)
- .getDiscoveryContainers();
- final Set s = new HashSet();
- for (final Iterator itr = discoveryContainers.iterator(); itr.hasNext();) {
- final IDiscoveryLocator object = (IDiscoveryLocator) itr.next();
- final IContainer adapter = (IContainer) object
- .getAdapter(IContainer.class);
- s.add(adapter.getID());
- }
- // make sure it's never (accidentally) modified by a test
- idsToExpect = Collections.unmodifiableSet(s);
-
- eventsToExpect = discoveryContainers.size();
-
- assertTrue("zero events make no sense", eventsToExpect > 0);
- }
-
- 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());
- }
-
- protected Collection getContainerIds(IContainerEvent[] events) {
- final Collection originalIds = new ArrayList();
- for (int i = 0; i < events.length; i++) {
- final IContainerEvent iContainerEvent = events[i];
- if (iContainerEvent instanceof CompositeServiceContainerEvent) {
- final CompositeServiceContainerEvent csce = (CompositeServiceContainerEvent) iContainerEvent;
- originalIds.add(csce.getOriginalLocalContainerID());
- } else {
- System.err.println("WARNING: Skipping non CompositeServiceContainerEvent in CompositeDiscoveryServiceContainerTest#getContainerIds(IContainerEvent[])");
- //originalIds.add(iContainerEvent.getLocalContainerID());
- }
- }
- return originalIds;
- }
-}
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/SingleCompositeDiscoveryServiceContainerTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/SingleCompositeDiscoveryServiceContainerTest.java
deleted file mode 100644
index 58150d614..000000000
--- a/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/SingleCompositeDiscoveryServiceContainerTest.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2010 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.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-
-import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
-import org.eclipse.ecf.discovery.IDiscoveryLocator;
-import org.eclipse.ecf.provider.discovery.CompositeDiscoveryContainer;
-import org.eclipse.ecf.tests.discovery.Activator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.framework.hooks.service.EventHook;
-import org.osgi.framework.hooks.service.FindHook;
-
-public abstract class SingleCompositeDiscoveryServiceContainerTest extends
- CompositeDiscoveryServiceContainerTest {
-
- // Whether the OSGi hooks should be de-/registered after and before each
- // individual test and not just after/before the test class.
- // E.g. when tests are executed in random order and thus are interleaved
- // with other tests, setUp/tearDown has to run after each test. Otherwise
- // expect test failures.
- public static boolean SETUP_OSGI_HOOKS_PER_TEST = false;
-
- private static int testMethods;
- private static int testMethodsLeft;
- private static ServiceRegistration findHook;
-
- // count all test methods
- static {
- Method[] methods = SingleCompositeDiscoveryServiceContainerTest.class.getMethods();
- for (int i = 0; i < methods.length; i++) {
- Method method = methods[i];
- if (method.getName().startsWith("test") && method.getModifiers() == Modifier.PUBLIC) {
- testMethods++;
- }
- }
- testMethodsLeft = testMethods;
- }
-
- private final String ecfDiscoveryContainerName;
- private final String className;
-
- public SingleCompositeDiscoveryServiceContainerTest(String anECFDiscoveryContainerName, String aClassName) {
- ecfDiscoveryContainerName = anECFDiscoveryContainerName;
- className = aClassName;
- }
-
- private boolean doSetUp() {
- return SETUP_OSGI_HOOKS_PER_TEST || testMethodsLeft == testMethods;
- }
-
- private boolean doTearDown() {
- return SETUP_OSGI_HOOKS_PER_TEST || --testMethodsLeft == 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ecf.tests.provider.discovery.CompositeDiscoveryServiceContainerTest#setUp()
- */
- protected void setUp() throws Exception {
- // HACK: @BeforeClass JUnit4 functionality
- if(doSetUp()) {
- // HACK: forcefully start the (nested) discovery container if it hasn't been started yet
- // assuming the bundle declares a lazy start buddy policy
- Class.forName(className);
-
- // initially close the existing CDC to get rid of other test left overs
- Activator.getDefault().closeServiceTracker(containerUnderTest);
-
- final BundleContext context = Activator.getDefault().getContext();
- final String[] clazzes = new String[]{FindHook.class.getName(), EventHook.class.getName()};
- findHook = context.registerService(clazzes, new DiscoveryContainerFilterHook(ecfDiscoveryContainerName), null);
- }
- super.setUp();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ecf.tests.discovery.DiscoveryTest#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- // HACK: @BeforeClass JUnit4 functionality
- if(doTearDown()) {
- if(findHook != null) {
- findHook.unregister();
- findHook = null;
- }
- // close tracker to force creation of a new CDC instance
- Activator.getDefault().closeServiceTracker(containerUnderTest);
-
- // reset so other instances can reuse
- testMethodsLeft = testMethods;
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ecf.tests.discovery.DiscoveryServiceTest#getDiscoveryLocator()
- */
- protected IDiscoveryLocator getDiscoveryLocator() {
- final IDiscoveryLocator idl = super.getDiscoveryLocator();
- checkCompositeDiscoveryContainer(className, (CompositeDiscoveryContainer)idl);
- return idl;
- }
-
-
- /* (non-Javadoc)
- * @see org.eclipse.ecf.tests.discovery.DiscoveryServiceTest#getDiscoveryAdvertiser()
- */
- protected IDiscoveryAdvertiser getDiscoveryAdvertiser() {
- final IDiscoveryAdvertiser ida = super.getDiscoveryAdvertiser();
- checkCompositeDiscoveryContainer(className, (CompositeDiscoveryContainer)ida);
- return ida;
- }
-
- // make sure the CDC has only a single IDC registered with the correct type
- private static void checkCompositeDiscoveryContainer(final String aClassName, final CompositeDiscoveryContainer cdc) {
- final Collection discoveryContainers = cdc.getDiscoveryContainers();
- assertTrue("One IDiscoveryContainer must be registered with the CDC at this point: " + discoveryContainers, discoveryContainers.size() == 1);
- for (final Iterator iterator = discoveryContainers.iterator(); iterator.hasNext();) {
- final IDiscoveryLocator dl = (IDiscoveryLocator) iterator.next();
- assertEquals(aClassName, dl.getClass().getName());
- }
- }
-
- // Filters the corresponding IDC from the result set that is _not_ supposed to be part of the test
- // we need an EventHook too because due to ECF's namespaces the "other" bundle is started asynchronously
- // and consequently registered with the CDC
- private class DiscoveryContainerFilterHook implements FindHook, EventHook {
-
- private static final String BUNDLE_UNDER_TEST = "org.eclipse.ecf.provider.discovery"; // rename if bundle name change
- private final String containerName;
-
- public DiscoveryContainerFilterHook(String anECFDiscoveryContainerName) {
- containerName = anECFDiscoveryContainerName;
- }
-
- /* (non-Javadoc)
- * @see org.osgi.framework.hooks.service.FindHook#find(org.osgi.framework.BundleContext, java.lang.String, java.lang.String, boolean, java.util.Collection)
- */
- public void find(BundleContext context, String name, String filter, boolean allServices, Collection references) {
-
- // is it the composite discovery bundle who tries to find the service?
- final String symbolicName = context.getBundle().getSymbolicName();
- final Collection removees = new ArrayList();
- if(BUNDLE_UNDER_TEST.equals(symbolicName)) {
- for (final Iterator iterator = references.iterator(); iterator.hasNext();) {
- // filter the corresponding container
- final ServiceReference serviceReference = (ServiceReference) iterator.next();
- final String property = (String) serviceReference.getProperty(IDiscoveryLocator.CONTAINER_NAME);
- if(property != null && property.equals(containerName)) {
- removees.add(serviceReference);
- System.out.println("Removed reference: " + property);
- break;
- }
- }
- references.removeAll(removees);
- }
- }
-
- /* (non-Javadoc)
- * @see org.osgi.framework.hooks.service.EventHook#event(org.osgi.framework.ServiceEvent, java.util.Collection)
- */
- public void event(ServiceEvent aServiceEvent, Collection aCollection) {
- if (aServiceEvent.getType() == ServiceEvent.REGISTERED) {
- final ServiceReference serviceReference = aServiceEvent.getServiceReference();
- final String property = (String) serviceReference.getProperty(IDiscoveryLocator.CONTAINER_NAME);
- if(property != null && property.equals(containerName)) {
- final Collection removees = new ArrayList();
- for (Iterator iterator = aCollection.iterator(); iterator.hasNext();) {
- final BundleContext bundleContext = (BundleContext) iterator.next();
- final String symbolicName = bundleContext.getBundle().getSymbolicName();
- if(BUNDLE_UNDER_TEST.equals(symbolicName)) {
- removees.add(bundleContext);
- System.out.println("Filtered reference: " + property);
- break;
- }
- }
- aCollection.removeAll(removees);
- }
- }
- }
- }
-}

Back to the top