diff options
author | mkuppe | 2009-03-10 08:30:20 +0000 |
---|---|---|
committer | mkuppe | 2009-03-10 08:30:20 +0000 |
commit | d0332962841ab47e41f8c23bdf93191d182d3ea8 (patch) | |
tree | 10370294f866d52c4fc634c38a05374e5044f780 /tests/bundles/org.eclipse.ecf.tests.provider.discovery/src | |
parent | 73b2fd8622147e841be8c7e46a7b28c3a5926502 (diff) | |
download | org.eclipse.ecf-d0332962841ab47e41f8c23bdf93191d182d3ea8.tar.gz org.eclipse.ecf-d0332962841ab47e41f8c23bdf93191d182d3ea8.tar.xz org.eclipse.ecf-d0332962841ab47e41f8c23bdf93191d182d3ea8.zip |
RESOLVED - bug 267782: [Discovery][jSLP][JmDNS] Providers don't clean up at bundle stop
https://bugs.eclipse.org/bugs/show_bug.cgi?id=267782
Diffstat (limited to 'tests/bundles/org.eclipse.ecf.tests.provider.discovery/src')
3 files changed, 133 insertions, 0 deletions
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 new file mode 100644 index 000000000..32e150d42 --- /dev/null +++ b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/SingleCompositeDiscoveryServiceContainerTest.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * 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.lang.reflect.Method; +import java.lang.reflect.Modifier; + +import org.eclipse.ecf.tests.discovery.Activator; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; + +public abstract class SingleCompositeDiscoveryServiceContainerTest extends + CompositeDiscoveryServiceContainerTest { + + private static int testMethods; + private static int testMethodsLeft; + + // 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 String bundleName; + + public SingleCompositeDiscoveryServiceContainerTest(String aBundleName) { + bundleName = aBundleName; + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.tests.provider.discovery.CompositeDiscoveryServiceContainerTest#setUp() + */ + protected void setUp() throws Exception { + if(testMethodsLeft == testMethods) { + Bundle bundle = null; + // stop the bundle assuming there is only one installed + BundleContext context = Activator.getDefault().getContext(); + Bundle[] bundles = context.getBundles(); + for(int i = 0; i < bundles.length; i++) { + Bundle aBundle = bundles[i]; + if(aBundle.getSymbolicName().equals(bundleName)) { + bundle = aBundle; + break; + } + } + assertNotNull(bundleName + " bundle not found", bundle); + assertTrue(bundle.getState() == Bundle.ACTIVE); + bundle.stop(); + assertTrue(bundle.getState() == Bundle.RESOLVED); + } + super.setUp(); + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.tests.discovery.DiscoveryTest#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + if(--testMethodsLeft == 0) { + Bundle bundle = null; + // stop the bundle assuming there is only one installed + BundleContext context = Activator.getDefault().getContext(); + Bundle[] bundles = context.getBundles(); + for(int i = 0; i < bundles.length; i++) { + Bundle aBundle = bundles[i]; + if(aBundle.getSymbolicName().equals(bundleName)) { + bundle = aBundle; + break; + } + } + assertNotNull(bundleName + " bundle not found", bundle); + assertTrue(bundle.getState() == Bundle.RESOLVED); + bundle.start(); + assertTrue(bundle.getState() == Bundle.ACTIVE); + + // reset so other instances can reuse + testMethodsLeft = testMethods; + } + } +} 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/src/org/eclipse/ecf/tests/provider/discovery/WithoutJMDNSCompositeDiscoveryServiceContainerTest.java new file mode 100644 index 000000000..007f0f0c4 --- /dev/null +++ b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/WithoutJMDNSCompositeDiscoveryServiceContainerTest.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * 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; + +public class WithoutJMDNSCompositeDiscoveryServiceContainerTest extends + SingleCompositeDiscoveryServiceContainerTest { + + public WithoutJMDNSCompositeDiscoveryServiceContainerTest() { + super("org.eclipse.ecf.provider.jmdns"); + } +} 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/src/org/eclipse/ecf/tests/provider/discovery/WithoutJSLPCompositeDiscoveryServiceContainerTest.java new file mode 100644 index 000000000..72d9a21e0 --- /dev/null +++ b/tests/bundles/org.eclipse.ecf.tests.provider.discovery/src/org/eclipse/ecf/tests/provider/discovery/WithoutJSLPCompositeDiscoveryServiceContainerTest.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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; + + +public class WithoutJSLPCompositeDiscoveryServiceContainerTest extends + SingleCompositeDiscoveryServiceContainerTest { + + public WithoutJSLPCompositeDiscoveryServiceContainerTest() { + super("org.eclipse.ecf.provider.jslp"); + } +} |