Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/internal/region/hook/RegionBundleEventHookTests.java56
-rw-r--r--bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java41
2 files changed, 97 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/internal/region/hook/RegionBundleEventHookTests.java b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/internal/region/hook/RegionBundleEventHookTests.java
index c6cc79f71..38b09bf22 100644
--- a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/internal/region/hook/RegionBundleEventHookTests.java
+++ b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/internal/region/hook/RegionBundleEventHookTests.java
@@ -17,6 +17,7 @@ import static org.junit.Assert.assertTrue;
import java.util.Collection;
import java.util.HashSet;
import org.easymock.EasyMock;
+import org.eclipse.equinox.internal.region.StandardRegionDigraph;
import org.eclipse.equinox.region.Region;
import org.eclipse.equinox.region.RegionDigraph;
import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
@@ -38,15 +39,48 @@ public class RegionBundleEventHookTests {
private ThreadLocal<Region> threadLocal;
+ private StandardRegionDigraph digraph;
+
+ private Region mockRegion1;
+
+ private Region mockRegion2;
+
+ private BundleEvent installedEvent1;
+
+ private BundleEvent installedEvent2;
+
+ private StubBundle eventBundle1;
+
+ private StubBundle eventBundle2;
+
@Before
public void setUp() throws Exception {
this.mockRegionDigraph = EasyMock.createMock(RegionDigraph.class);
this.eventBundle = new StubBundle();
+
+ this.eventBundle1 = new StubBundle(1L, "my.bundle1", new Version("0"), "loc1");
+ this.eventBundle2 = new StubBundle(2L, "my.bundle2", new Version("0"), "loc2");
+
this.bundleEvent = new BundleEvent(BundleEvent.STARTED, this.eventBundle, this.eventBundle);
+
+ this.installedEvent1 = new BundleEvent(BundleEvent.INSTALLED, eventBundle1, this.eventBundle);
+ this.installedEvent2 = new BundleEvent(BundleEvent.INSTALLED, eventBundle2, this.eventBundle);
+
this.contexts = new HashSet<BundleContext>();
StubBundleContext stubListenerBundleContext = new StubBundleContext();
this.contexts.add(stubListenerBundleContext);
this.threadLocal = new ThreadLocal<Region>();
+
+ StubBundle stubSystemBundle = new StubBundle(0L, "osgi.framework", new Version("0"), "loc");
+ StubBundleContext stubBundleContext = new StubBundleContext();
+ stubBundleContext.addInstalledBundle(stubSystemBundle);
+ this.digraph = new StandardRegionDigraph(stubBundleContext, new ThreadLocal<Region>());
+ this.digraph.createRegion("mockRegion1");
+ this.digraph.createRegion("mockRegion2");
+ this.mockRegion1 = digraph.getRegion("mockRegion1");
+ this.mockRegion2 = digraph.getRegion("mockRegion2");
+ this.mockRegion1.addBundle(this.eventBundle);
+
}
@After
@@ -82,4 +116,26 @@ public class RegionBundleEventHookTests {
assertTrue(this.contexts.isEmpty());
}
+ @Test
+ public void testDefaultRegion() {
+ FindHook mockFindHook = new FindHook() {
+
+ @Override
+ public void find(BundleContext context, Collection<Bundle> bundles) {
+ bundles.clear();
+ }
+ };
+
+ this.digraph.setDefaultRegion(null);
+ EventHook eventHook = new RegionBundleEventHook(this.digraph, mockFindHook, this.threadLocal);
+ eventHook.event(this.installedEvent1, this.contexts);
+ assertTrue(this.digraph.getRegion(this.eventBundle1).equals(this.mockRegion1));
+
+ this.digraph.setDefaultRegion(this.mockRegion2);
+ eventHook = new RegionBundleEventHook(this.digraph, mockFindHook, this.threadLocal);
+ eventHook.event(this.installedEvent2, this.contexts);
+ assertTrue(this.digraph.getRegion(this.eventBundle2).equals(this.mockRegion2));
+
+ }
+
}
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 6e9decfcf..9897d470d 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
@@ -545,4 +545,45 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
assertEquals("Wrong exception type.", BundleException.DUPLICATE_BUNDLE_ERROR, e.getType());
}
}
+
+ public void testDefaultRegion() throws BundleException {
+ digraph.setDefaultRegion(null);
+
+ Region systemRegion = digraph.getRegion(regionBundle);
+ Region pp1Region = digraph.createRegion(PP1);
+
+ Bundle pp1Bundle = bundleInstaller.installBundle(PP1, null);
+ Region result = digraph.getRegion(pp1Bundle);
+ assertEquals("Wrong region", systemRegion, result);
+
+ pp1Bundle.uninstall();
+
+ digraph.setDefaultRegion(pp1Region);
+ pp1Bundle = bundleInstaller.installBundle(PP1, null);
+ result = digraph.getRegion(pp1Bundle);
+ assertEquals("Wrong region", pp1Region, result);
+
+ digraph.setDefaultRegion(null);
+ }
+
+ public void testRemoveDefaultRegion() throws BundleException {
+ digraph.setDefaultRegion(null);
+
+ Region pp1Region = digraph.createRegion(PP1);
+ digraph.setDefaultRegion(pp1Region);
+ digraph.removeRegion(pp1Region);
+ assertEquals("DefaultRegion is not null", null, digraph.getDefaultRegion());
+ }
+
+ public void testSetNotExistingDefaultRegion() throws BundleException {
+ Region pp1Region = digraph.createRegion(PP1);
+ digraph.removeRegion(pp1Region);
+ try {
+ digraph.setDefaultRegion(pp1Region);
+ assertFalse("IllegalArgumentException not thrown for setting non-existing region as default", true);
+ } catch (IllegalArgumentException iae) {
+ assertNull("DefaultRegion is not null", digraph.getDefaultRegion());
+ }
+ }
+
}

Back to the top