Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSopot Cela2016-04-11 15:25:22 +0000
committerSopot Cela2016-04-11 16:26:33 +0000
commit38938123d4863de34bd96be5a722dcc50422641e (patch)
tree80c7d2925bec699b029b891d9312bee9bc9fc27d
parenta868d83fe61587702f7da4864999db8853549b8f (diff)
downloadrt.equinox.bundles-38938123d4863de34bd96be5a722dcc50422641e.tar.gz
rt.equinox.bundles-38938123d4863de34bd96be5a722dcc50422641e.tar.xz
rt.equinox.bundles-38938123d4863de34bd96be5a722dcc50422641e.zip
Bug 490273 - Move tests to JUnit 4I20160412-0800
Port of the region tests, plus minor improvements. Change-Id: Id2be2464a958f08c9fe603470ff13704ee022de8 Signed-off-by: Sopot Cela <scela@redhat.com>
-rw-r--r--bundles/org.eclipse.equinox.region.tests/META-INF/MANIFEST.MF3
-rw-r--r--bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/Bug395334Test.java4
-rw-r--r--bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/AllTests.java25
-rw-r--r--bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/AbstractRegionSystemTest.java19
-rw-r--r--bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/Bug346127Test.java11
-rw-r--r--bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java56
6 files changed, 79 insertions, 39 deletions
diff --git a/bundles/org.eclipse.equinox.region.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.region.tests/META-INF/MANIFEST.MF
index 8676b1da3..44fbdc38a 100644
--- a/bundles/org.eclipse.equinox.region.tests/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.region.tests/META-INF/MANIFEST.MF
@@ -16,6 +16,9 @@ Import-Package: junit.framework;version="4.8.1",
org.eclipse.equinox.region;version="1.1.0",
org.eclipse.osgi.service.urlconversion;version="1.0.0",
org.junit;version="4.8.1",
+ org.junit.rules;version="4.12.0",
+ org.junit.runner;version="4.12.0",
+ org.junit.runners;version="4.12.0",
org.osgi.framework;version="1.8.0",
org.osgi.framework.hooks.bundle;version="1.1.0",
org.osgi.framework.hooks.resolver;version="1.0.0",
diff --git a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/Bug395334Test.java b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/Bug395334Test.java
index 774359c11..49c1dfb44 100644
--- a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/Bug395334Test.java
+++ b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/Bug395334Test.java
@@ -10,9 +10,12 @@
*******************************************************************************/
package org.eclipse.equinox.region.internal.tests;
+import static org.junit.Assert.assertTrue;
+
import org.eclipse.equinox.region.RegionFilter;
import org.eclipse.equinox.region.RegionFilterBuilder;
import org.eclipse.equinox.region.tests.system.AbstractRegionSystemTest;
+import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.wiring.BundleRevision;
@@ -22,6 +25,7 @@ import org.osgi.framework.wiring.BundleRevision;
* the bundle-symbolic-name attribute as per the RegionFilter API.
*/
public class Bug395334Test extends AbstractRegionSystemTest {
+ @Test
public void testBug395334() throws Exception {
RegionFilterBuilder filterBuilder = digraph.createRegionFilterBuilder();
filterBuilder.allow(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, "(bundle-symbolic-name=org.eclipse.osgi)");
diff --git a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/AllTests.java b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/AllTests.java
index c579c38a0..fdc30cd24 100644
--- a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/AllTests.java
+++ b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/AllTests.java
@@ -10,27 +10,18 @@
*******************************************************************************/
package org.eclipse.equinox.region.tests;
-import junit.framework.*;
import org.eclipse.equinox.region.internal.tests.*;
import org.eclipse.equinox.region.internal.tests.hook.*;
import org.eclipse.equinox.region.tests.system.Bug346127Test;
import org.eclipse.equinox.region.tests.system.RegionSystemTests;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+@RunWith(Suite.class)
+@SuiteClasses({RegionBundleCollisionHookTests.class, RegionBundleEventHookTests.class, RegionBundleFindHookTests.class, RegionResolverHookTests.class, RegionServiceEventHookTests.class, RegionServiceFindHookTests.class, BundleIdBasedRegionTests.class, StandardRegionDigraphPeristenceTests.class, StandardRegionDigraphTests.class, StandardRegionFilterTests.class, RegionSystemTests.class, Bug346127Test.class
+
+})
public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("Equinox Region Tests");
- suite.addTest(new JUnit4TestAdapter(RegionBundleCollisionHookTests.class));
- suite.addTest(new JUnit4TestAdapter(RegionBundleEventHookTests.class));
- suite.addTest(new JUnit4TestAdapter(RegionBundleFindHookTests.class));
- suite.addTest(new JUnit4TestAdapter(RegionResolverHookTests.class));
- suite.addTest(new JUnit4TestAdapter(RegionServiceEventHookTests.class));
- suite.addTest(new JUnit4TestAdapter(RegionServiceFindHookTests.class));
- suite.addTest(new JUnit4TestAdapter(BundleIdBasedRegionTests.class));
- suite.addTest(new JUnit4TestAdapter(StandardRegionDigraphPeristenceTests.class));
- suite.addTest(new JUnit4TestAdapter(StandardRegionDigraphTests.class));
- suite.addTest(new JUnit4TestAdapter(StandardRegionFilterTests.class));
- suite.addTest(new TestSuite(RegionSystemTests.class));
- suite.addTest(new TestSuite(Bug346127Test.class));
- return suite;
- }
+ // see @SuiteClasses
}
diff --git a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/AbstractRegionSystemTest.java b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/AbstractRegionSystemTest.java
index be902c5bc..9f6173503 100644
--- a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/AbstractRegionSystemTest.java
+++ b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/AbstractRegionSystemTest.java
@@ -10,12 +10,15 @@
*******************************************************************************/
package org.eclipse.equinox.region.tests.system;
+import static org.junit.Assert.assertNotNull;
+
import java.util.Arrays;
import java.util.List;
-import junit.framework.TestCase;
import org.eclipse.equinox.region.Region;
import org.eclipse.equinox.region.RegionDigraph;
import org.eclipse.equinox.region.tests.BundleInstaller;
+import org.junit.After;
+import org.junit.Before;
import org.osgi.framework.*;
/*
@@ -33,7 +36,7 @@ import org.osgi.framework.*;
* SC1 -- package pkg2.* --> PP2
* CC1 -- capability CP2 --> CP2
*/
-public class AbstractRegionSystemTest extends TestCase {
+public class AbstractRegionSystemTest {
public static final String PP1 = "PackageProvider1";
public static final String SP1 = "ServiceProvider1";
public static final String CP1 = "CapabilityProvider1";
@@ -54,21 +57,21 @@ public class AbstractRegionSystemTest extends TestCase {
protected Bundle testsBundle;
ServiceReference<RegionDigraph> digraphReference;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
testsBundle = FrameworkUtil.getBundle(this.getClass());;
BundleContext context = getContext();
digraphReference = context.getServiceReference(RegionDigraph.class);
- assertNotNull("No digraph found", digraphReference);
+ assertNotNull("No digraph reference found", digraphReference);
digraph = context.getService(digraphReference);
- assertNotNull("No digraph found");
+ assertNotNull("No digraph found", digraph);
bundleInstaller = new BundleInstaller("bundle_tests", testsBundle); //$NON-NLS-1$
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
for (Region region : digraph) {
if (!region.contains(0)) {
digraph.removeRegion(region);
diff --git a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/Bug346127Test.java b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/Bug346127Test.java
index 495f8d2b0..16b4387e2 100644
--- a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/Bug346127Test.java
+++ b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/Bug346127Test.java
@@ -10,12 +10,17 @@
*******************************************************************************/
package org.eclipse.equinox.region.tests.system;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Hashtable;
import org.eclipse.equinox.region.Region;
+import org.junit.Before;
+import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.service.url.*;
@@ -28,6 +33,8 @@ import org.osgi.service.url.*;
* which there is a compatible URL Handler.
*/
public class Bug346127Test extends AbstractRegionSystemTest {
+
+ @Test
public void testBug346127() throws Exception {
String location = bundleInstaller.getBundleLocation(PP1);
location = "regiondigraphtest:" + location;
@@ -41,8 +48,8 @@ public class Bug346127Test extends AbstractRegionSystemTest {
}
}
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
super.setUp();
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put(URLConstants.URL_HANDLER_PROTOCOL, new String[] {"regiondigraphtest"});
diff --git a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java
index b9a1170f0..c9480bf89 100644
--- a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java
+++ b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java
@@ -10,6 +10,13 @@
*******************************************************************************/
package org.eclipse.equinox.region.tests.system;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.net.MalformedURLException;
@@ -19,6 +26,9 @@ import java.util.concurrent.CopyOnWriteArrayList;
import javax.management.*;
import org.eclipse.equinox.region.*;
import org.eclipse.equinox.region.RegionDigraph.FilteredRegion;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
import org.osgi.framework.*;
import org.osgi.framework.hooks.bundle.CollisionHook;
import org.osgi.framework.hooks.bundle.EventHook;
@@ -29,13 +39,17 @@ import org.osgi.util.tracker.ServiceTracker;
public class RegionSystemTests extends AbstractRegionSystemTest {
+ @Rule
+ public TestName testName = new TestName();
+
private static final long TEST_BUNDLE_ID = 452345245L;
+ @Test
public void testBasic() throws BundleException, InvalidSyntaxException, InterruptedException {
// get the system region
Region systemRegion = digraph.getRegion(0);
// create a disconnected test region
- Region testRegion = digraph.createRegion(getName());
+ Region testRegion = digraph.createRegion(testName.getMethodName());
List<Bundle> bundles = new ArrayList<Bundle>();
// Install all test bundles
Bundle pp1, cp2, sc1;
@@ -80,6 +94,7 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
sc1Tracker.close();
}
+ @Test
public void testSingleBundleRegions() throws BundleException, InvalidSyntaxException, InterruptedException {
// get the system region
Region systemRegion = digraph.getRegion(0);
@@ -234,21 +249,24 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
// assertEquals("Wrong number of test ids.", 0, testIds.size());
// }
+ @Test
public void testCyclicRegions0() throws BundleException, InvalidSyntaxException, InterruptedException {
doCyclicRegions(0);
}
+ @Test
public void testCyclicRegions10() throws BundleException, InvalidSyntaxException, InterruptedException {
doCyclicRegions(10);
}
+ @Test
public void testCyclicRegions100() throws BundleException, InvalidSyntaxException, InterruptedException {
doCyclicRegions(100);
}
private void doCyclicRegions(int numLevels) throws BundleException, InvalidSyntaxException, InterruptedException {
- String regionName1 = getName() + "_1";
- String regionName2 = getName() + "_2";
+ String regionName1 = testName.getMethodName() + "_1";
+ String regionName2 = testName.getMethodName() + "_2";
// get the system region
Region systemRegion = digraph.getRegion(0);
// create two regions to hold the bundles
@@ -298,7 +316,7 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
Region r1, r2 = null;
for (int i = 0; i <= numLevels; i++) {
r1 = (i > 0) ? r2 : testRegion1;
- r2 = (i < numLevels) ? digraph.createRegion(getName() + "_level_" + i) : testRegion2;
+ r2 = (i < numLevels) ? digraph.createRegion(testName.getMethodName() + "_level_" + i) : testRegion2;
r1.connectRegion(r2, testRegionFilter1.build());
r2.connectRegion(r1, testRegionFilter2.build());
}
@@ -354,9 +372,10 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
}, null);
}
+ @Test
public void testSingletons() throws BundleException {
- Region region1 = digraph.createRegion(getName() + "_1");
- Region region2 = digraph.createRegion(getName() + "_2");
+ Region region1 = digraph.createRegion(testName.getMethodName() + "_1");
+ Region region2 = digraph.createRegion(testName.getMethodName() + "_2");
// first install into the same region; higher version 2 should resolve
Bundle singleton1 = bundleInstaller.installBundle(SINGLETON1, region1);
@@ -422,6 +441,7 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
private static final String REGION_DOMAIN_PROP = "org.eclipse.equinox.region.domain";
+ @Test
public void testMbeans() throws MalformedObjectNameException, BundleException, InstanceNotFoundException, ReflectionException, MBeanException, AttributeNotFoundException {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName digraphName = new ObjectName(REGION_DOMAIN_PROP + ":type=RegionDigraph,*");
@@ -465,6 +485,7 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
assertEquals("Wrong name", SP1, name);
}
+ @Test
public void testBundleCollisionDisconnectedRegions() throws BundleException, InvalidSyntaxException {
// get the system region
Region systemRegion = digraph.getRegion(0);
@@ -493,7 +514,7 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
for (String name : ALL) {
String location = bundleInstaller.getBundleLocation(name);
try {
- Bundle b = region.installBundle(getName() + "_expectToFail", new URL(location).openStream());
+ Bundle b = region.installBundle(testName.getMethodName() + "_expectToFail", new URL(location).openStream());
b.uninstall();
fail("Expected a bundle exception on duplicate bundle installation: " + name);
} catch (BundleException e) {
@@ -534,10 +555,11 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
}
}
+ @Test
public void testBundleCollisionUninstalledBundle() throws BundleException {
- Region region1 = digraph.createRegion(getName() + 1);
- Region region2 = digraph.createRegion(getName() + 2);
- Region region3 = digraph.createRegion(getName() + 3);
+ Region region1 = digraph.createRegion(testName.getMethodName() + 1);
+ Region region2 = digraph.createRegion(testName.getMethodName() + 2);
+ Region region3 = digraph.createRegion(testName.getMethodName() + 3);
// install the same bundle into the first two regions. Should be no collision
bundleInstaller.installBundle(PP1, region1);
bundleInstaller.installBundle(PP1, region2);
@@ -561,6 +583,7 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
}
}
+ @Test
public void testBundleCollisionConnectedRegions() throws BundleException, InvalidSyntaxException {
// get the system region
Region systemRegion = digraph.getRegion(0);
@@ -613,6 +636,7 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
}
}
+ @Test
public void testDefaultRegion() throws BundleException {
digraph.setDefaultRegion(null);
@@ -633,6 +657,7 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
digraph.setDefaultRegion(null);
}
+ @Test
public void testRemoveDefaultRegion() throws BundleException {
digraph.setDefaultRegion(null);
@@ -642,6 +667,7 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
assertEquals("DefaultRegion is not null", null, digraph.getDefaultRegion());
}
+ @Test
public void testSetNotExistingDefaultRegion() throws BundleException {
Region pp1Region = digraph.createRegion(PP1);
digraph.removeRegion(pp1Region);
@@ -653,6 +679,7 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
}
}
+ @Test
public void testRemoveRegion() throws BundleException {
Region pp1Region = digraph.createRegion(PP1);
pp1Region.addBundle(TEST_BUNDLE_ID);
@@ -682,10 +709,11 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
assertEquals("Wrong region found for the bundle id", pp2Region, digraph.getRegion(TEST_BUNDLE_ID));
}
+ @Test
public void testInstallAtLocation() throws BundleException, MalformedURLException, IOException {
// create disconnected test regions
- Region r1 = digraph.createRegion(getName() + ".1");
- Region r2 = digraph.createRegion(getName() + ".2");
+ Region r1 = digraph.createRegion(testName.getMethodName() + ".1");
+ Region r2 = digraph.createRegion(testName.getMethodName() + ".2");
String location = bundleInstaller.getBundleLocation(PP1);
Bundle b1 = null;
@@ -718,6 +746,7 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
assertEquals("Wrong location found.", location + ".2", l2);
}
+ @Test
public void testInvalidRegionName() {
Collection<String> invalidNames = new ArrayList<String>();
invalidNames.addAll(Arrays.asList(":", "bad:Name", ":bad::name:", ":badname", "badname:"));
@@ -742,6 +771,7 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
}
+ @Test
public void testHigherRankedEventHookResolve() throws BundleException {
final List<BundleEvent> events = new CopyOnWriteArrayList<BundleEvent>();
SynchronousBundleListener listener = new SynchronousBundleListener() {
@@ -782,6 +812,7 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
}
}
+ @Test
public void testHigherRankedEventHookUninstall() throws BundleException {
// register a higher ranked bundle EventHook that causes a bundle to resolve while processing INSTALLED events
ServiceRegistration<EventHook> bundleEventHook = getContext().registerService(EventHook.class, new EventHook() {
@@ -808,6 +839,7 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
assertNull("Found region for uninstalled bundle.", digraph.getRegion(b));
}
+ @Test
public void testReplaceConnection() throws BundleException, InvalidSyntaxException {
// get the system region
Region systemRegion = digraph.getRegion(0);

Back to the top