public String translateToMessage(BundleException e) { switch (e.getType()) { case BundleException.ACTIVATOR_ERROR: Throwable t = e.getCause(); StackTraceElement[] stackTrace = t.getStackTrace(); if (stackTrace == null || stackTrace.length == 0) return "activator error " + t.getMessage(); StackTraceElement top = stackTrace[0]; return "activator error " + t.getMessage() + " from: " + top.getClassName() + ":" + top.getMethodName() + "#" + top.getLineNumber(); case BundleException.DUPLICATE_BUNDLE_ERROR: case BundleException.RESOLVE_ERROR: case BundleException.INVALID_OPERATION: case BundleException.MANIFEST_ERROR: case BundleException.NATIVECODE_ERROR: case BundleException.STATECHANGE_ERROR: case BundleException.UNSUPPORTED_OPERATION: case BundleException.UNSPECIFIED: default: return e.getMessage(); } }
@Test public void testInstallModule() throws Exception { // Try to start the bundle and verify the expected ResolutionException XBundle bundleA = (XBundle) installBundle(getBundleA()); try { bundleA.start(); Assert.fail("BundleException expected"); } catch (BundleException ex) { ResolutionException cause = (ResolutionException) ex.getCause(); Collection<Requirement> reqs = cause.getUnresolvedRequirements(); Assert.assertEquals(1, reqs.size()); Requirement req = reqs.iterator().next(); String namespace = req.getNamespace(); Assert.assertEquals(PackageNamespace.PACKAGE_NAMESPACE, namespace); } Module moduleB = loadModule(getModuleB()); XBundleRevision brevB = installResource(moduleB); try { XBundle bundleB = brevB.getBundle(); Assert.assertEquals(bundleA.getBundleId() + 1, bundleB.getBundleId()); bundleA.start(); assertLoadClass(bundleA, ModuleServiceX.class.getName(), bundleB); // verify wiring for A XBundleRevision brevA = bundleA.getBundleRevision(); Assert.assertSame(bundleA, brevA.getBundle()); BundleWiring wiringA = brevA.getWiring(); List<BundleWire> requiredA = wiringA.getRequiredWires(null); Assert.assertEquals(1, requiredA.size()); BundleWire wireA = requiredA.get(0); Assert.assertSame(brevA, wireA.getRequirer()); Assert.assertSame(bundleB, wireA.getProvider().getBundle()); List<BundleWire> providedA = wiringA.getProvidedWires(null); Assert.assertEquals(0, providedA.size()); // verify wiring for B Assert.assertSame(bundleB, brevB.getBundle()); BundleWiring wiringB = brevB.getWiring(); List<BundleWire> requiredB = wiringB.getRequiredWires(null); Assert.assertEquals(0, requiredB.size()); List<BundleWire> providedB = wiringB.getProvidedWires(null); Assert.assertEquals(1, providedB.size()); BundleWire wireB = providedB.get(0); Assert.assertSame(brevA, wireB.getRequirer()); Assert.assertSame(bundleB, wireB.getProvider().getBundle()); } finally { removeModule(moduleB); } }
@Test public void testExtensionFragmentFramework() throws Exception { try { installBundle(getFragmentG4()); fail("BundleException expected"); } catch (BundleException ex) { Throwable cause = ex.getCause(); assertNotNull("BundleException cause not null", cause); assertEquals( "UnsupportedOperationException expected", UnsupportedOperationException.class, cause.getClass()); } }