private static StartOptions[] getStartOptions(int options) { if (options == 0) { return new StartOptions[0]; } Collection<StartOptions> result = new ArrayList<Module.StartOptions>(2); if ((options & Bundle.START_TRANSIENT) != 0) { result.add(StartOptions.TRANSIENT); } if ((options & Bundle.START_ACTIVATION_POLICY) != 0) { result.add(StartOptions.USE_ACTIVATION_POLICY); } return result.toArray(new StartOptions[result.size()]); }
public void testBundleCollisionDisconnectedRegions() throws BundleException, InvalidSyntaxException { // get the system region Region systemRegion = digraph.getRegion(0); Collection<Bundle> bundles = new HashSet<Bundle>(); // create 4 disconnected test regions and install each bundle into each region int numRegions = 4; String regionName = "IsolatedRegion_"; for (int i = 0; i < numRegions; i++) { Region region = digraph.createRegion(regionName + i); // Import the system bundle from the systemRegion digraph.connect(region, digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, "(id=0)").build(), systemRegion); // must import Boolean services into systemRegion to test digraph.connect(systemRegion, digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_SERVICE_NAMESPACE, "(objectClass=java.lang.Boolean)").build(), region); for (String location : ALL) { Bundle b = bundleInstaller.installBundle(location, region); bundles.add(b); } } assertEquals("Wrong number of bundles installed", numRegions * ALL.size(), bundles.size()); assertTrue("Could not resolve bundles.", bundleInstaller.resolveBundles(bundles.toArray(new Bundle[bundles.size()]))); // test install of duplicates for (int i = 0; i < numRegions; i++) { Region region = digraph.getRegion(regionName + i); for (String name : ALL) { String location = bundleInstaller.getBundleLocation(name); try { Bundle b = region.installBundle(getName() + "_expectToFail", new URL(location).openStream()); b.uninstall(); fail("Expected a bundle exception on duplicate bundle installation: " + name); } catch (BundleException e) { // expected assertEquals("Wrong exception type.", BundleException.DUPLICATE_BUNDLE_ERROR, e.getType()); } catch (IOException e) { fail("Failed to open bunldle location: " + e.getMessage()); } } } // test update to a duplicate for (int i = 0; i < numRegions; i++) { Region region = digraph.getRegion(regionName + i); Bundle regionPP1 = region.getBundle(PP1, new Version(1, 0, 0)); String locationSP1 = bundleInstaller.getBundleLocation(SP1); try { regionPP1.update(new URL(locationSP1).openStream()); fail("Expected a bundle exception on duplicate bundle update: " + region); } catch (BundleException e) { // expected assertEquals("Wrong exception type.", BundleException.DUPLICATE_BUNDLE_ERROR, e.getType()); } catch (IOException e) { fail("Failed to open bunldle location: " + e.getMessage()); } // now uninstall SP1 and try to update PP1 to SP1 again Bundle regionSP1 = region.getBundle(SP1, new Version(1, 0, 0)); regionSP1.uninstall(); try { regionPP1.update(new URL(locationSP1).openStream()); } catch (IOException e) { fail("Failed to open bunldle location: " + e.getMessage()); } } }