@SuppressWarnings("deprecation") public void testAllResolved() { assertNotNull("Expected a Bundle Context", context); StringBuilder sb = new StringBuilder(); for (Bundle b : context.getBundles()) { if (b.getState() == Bundle.INSTALLED && b.getHeaders().get(aQute.bnd.osgi.Constants.FRAGMENT_HOST) == null) { try { b.start(); } catch (BundleException e) { sb.append(b.getBundleId()) .append(" ") .append(b.getSymbolicName()) .append(";") .append(b.getVersion()) .append("\n"); sb.append(" ").append(e.getMessage()).append("\n\n"); System.err.println(e.getMessage()); } } } Matcher matcher = IP_P.matcher(sb); String out = matcher.replaceAll( "\n\n " + aQute.bnd.osgi.Constants.IMPORT_PACKAGE + ": $1;version=[$2,$3)\n"); assertTrue("Unresolved bundles\n" + out, sb.length() == 0); }
private void assertInstallFail(String name, Region region) { try { Bundle b = bundleInstaller.installBundle(name, region); b.uninstall(); fail("Expected a bundle exception on duplicate bundle install: " + region); } catch (BundleException e) { // expected assertEquals("Wrong exception type.", BundleException.DUPLICATE_BUNDLE_ERROR, e.getType()); } }
public synchronized void cleanup() { while ((!m_installed.isEmpty())) { try { Long id = m_installed.pop(); Bundle bundle = m_framework.getBundleContext().getBundle(id); bundle.uninstall(); LOG.debug("Uninstalled bundle " + id); } catch (BundleException e) { e.printStackTrace(); } } }
public synchronized long install(InputStream stream) { try { Bundle b = m_framework.getBundleContext().installBundle("local", stream); m_installed.push(b.getBundleId()); LOG.debug("Installed bundle " + b.getSymbolicName() + " as Bundle ID " + b.getBundleId()); setBundleStartLevel(b.getBundleId(), Constants.START_LEVEL_TEST_BUNDLE); // stream.close(); b.start(); return b.getBundleId(); } catch (BundleException e) { e.printStackTrace(); } return -1; }
public void testInvalidRegionName() { Collection<String> invalidNames = new ArrayList<String>(); invalidNames.addAll(Arrays.asList(":", "bad:Name", ":bad::name:", ":badname", "badname:")); invalidNames.addAll(Arrays.asList("=", "bad=Name", "=bad==name=", "=badname", "badname=")); invalidNames.addAll(Arrays.asList("\n", "bad\nName", "\nbad\n\nname\n", "\nbadname", "badname\n")); invalidNames.addAll(Arrays.asList("*", "bad*Name", "*bad**name*", "*badname", "badname*")); invalidNames.addAll(Arrays.asList("?", "bad?Name", "?bad??name?", "?badname", "badname?")); invalidNames.addAll(Arrays.asList(",", "bad,Name", ",bad,,name,", ",badname", "badname,")); invalidNames.addAll(Arrays.asList("\"", "bad\"Name", "\"bad\"\"name\"", "\"badname", "badname\"")); invalidNames.addAll(Arrays.asList("\\", "bad\\Name", "\\bad\\\\name\\", "\\badname", "badname\\")); for (String invalidName : invalidNames) { try { digraph.createRegion(invalidName); fail("Expected failure to create region."); } catch (IllegalArgumentException e) { // expected } catch (BundleException e) { fail("Unexpected bundle exception: " + e.getMessage()); } } }
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()); } } }