use of org.osgi.framework.wiring.BundleWiring in project aries by apache.
the class SubsystemDependencyTestBase method verifyRequireBundleWiring.
/**
* Verify that the Require-Bundle of wiredBundleName in subsystem s is met by a wire
* to expectedProvidingBundleName
* @param s
* @param wiredBundleName
* @param expectedProvidingBundleName
*/
protected void verifyRequireBundleWiring(Subsystem s, String wiredBundleName, String expectedProvidingBundleName) {
Bundle wiredBundle = context(s).getBundleByName(BUNDLE_D);
assertNotNull("Target bundle " + wiredBundleName + " not found", wiredBundle);
BundleWiring wiring = (BundleWiring) wiredBundle.adapt(BundleWiring.class);
List<BundleWire> wiredBundles = wiring.getRequiredWires(BUNDLE_NAMESPACE);
assertEquals("Only one bundle expected", 1, wiredBundles.size());
String requiredBundleName = (String) wiredBundles.get(0).getCapability().getAttributes().get(BUNDLE_NAMESPACE);
assertEquals("Wrong bundle requirement", BUNDLE_A, requiredBundleName);
String providingBundle = wiredBundles.get(0).getProvider().getSymbolicName();
assertEquals("Wrong bundle provider", expectedProvidingBundleName, providingBundle);
}
use of org.osgi.framework.wiring.BundleWiring in project aries by apache.
the class BundleStateMBeanTest method getPackageVersion.
private Version getPackageVersion(String packageName) {
Bundle systemBundle = context().getBundle(0);
BundleWiring wiring = (BundleWiring) systemBundle.adapt(BundleWiring.class);
List<BundleCapability> packages = wiring.getCapabilities(BundleRevision.PACKAGE_NAMESPACE);
for (BundleCapability pkg : packages) {
Map<String, Object> attrs = pkg.getAttributes();
if (attrs.get(BundleRevision.PACKAGE_NAMESPACE).equals(packageName)) {
return (Version) attrs.get(Constants.VERSION_ATTRIBUTE);
}
}
throw new IllegalStateException("Package version not found for " + packageName);
}
use of org.osgi.framework.wiring.BundleWiring in project aries by apache.
the class FrameworkMBeanTest method testRefreshBundlesAndWait.
@Test
public void testRefreshBundlesAndWait() throws Exception {
Bundle bundleA = getBundleByName("org.apache.aries.jmx.test.bundlea");
Bundle bundleB = getBundleByName("org.apache.aries.jmx.test.bundleb");
BundleWiring bw = (BundleWiring) bundleB.adapt(BundleWiring.class);
List<BundleWire> initialRequiredWires = bw.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
assertEquals(1, initialRequiredWires.size());
BundleWire wire = initialRequiredWires.get(0);
Map<String, Object> capabilityAttributes = wire.getCapability().getAttributes();
assertEquals("Precondition", bundleA.getSymbolicName(), capabilityAttributes.get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE));
assertEquals("Precondition", new Version("1.0"), capabilityAttributes.get(Constants.BUNDLE_VERSION_ATTRIBUTE));
assertEquals("Precondition", "org.apache.aries.jmx.test.bundlea.api", capabilityAttributes.get(BundleRevision.PACKAGE_NAMESPACE));
// Create an updated version of Bundle A, which an extra export and version 1.1
Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
manifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundlea");
manifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, "1.1");
manifest.getMainAttributes().putValue(Constants.EXPORT_PACKAGE, "org.apache.aries.jmx.test.bundlea.api,org.apache.aries.jmx.test.bundlea.impl");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JarOutputStream jos = new JarOutputStream(baos, manifest);
addResourceToJar("org/apache/aries/jmx/test/bundlea/api/InterfaceA.class", jos, bundleA);
addResourceToJar("org/apache/aries/jmx/test/bundlea/impl/A2.class", jos, bundleA);
jos.close();
assertEquals("Precondition", 1, ((BundleRevisions) bundleA.adapt(BundleRevisions.class)).getRevisions().size());
bundleA.update(new ByteArrayInputStream(baos.toByteArray()));
assertEquals("There should be 2 revisions now", 2, ((BundleRevisions) bundleA.adapt(BundleRevisions.class)).getRevisions().size());
assertEquals("No refresh called, the bundle wiring for B should still be the old one", bw, bundleB.adapt(BundleWiring.class));
FrameworkMBean framework = getMBean(FrameworkMBean.OBJECTNAME, FrameworkMBean.class);
CompositeData result = framework.refreshBundlesAndWait(new long[] { bundleB.getBundleId() });
assertTrue((Boolean) result.get(FrameworkMBean.SUCCESS));
assertTrue(Arrays.equals(new Long[] { bundleB.getBundleId() }, (Long[]) result.get(FrameworkMBean.COMPLETED)));
List<BundleWire> requiredWires = ((BundleWiring) bundleB.adapt(BundleWiring.class)).getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
assertEquals(2, requiredWires.size());
List<String> imported = new ArrayList<String>();
for (BundleWire w : requiredWires) {
Map<String, Object> ca = w.getCapability().getAttributes();
assertEquals(bundleA.getSymbolicName(), ca.get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE));
imported.add(ca.get(BundleRevision.PACKAGE_NAMESPACE).toString());
if ("org.apache.aries.jmx.test.bundlea.impl".equals(ca.get(BundleRevision.PACKAGE_NAMESPACE))) {
// Came across an issue where equinox was reporting the other package as still coming from from the 1.0 bundle
// not sure if this is a bug or not...
assertEquals(new Version("1.1"), ca.get(Constants.BUNDLE_VERSION_ATTRIBUTE));
}
}
assertEquals(Arrays.asList("org.apache.aries.jmx.test.bundlea.api", "org.apache.aries.jmx.test.bundlea.impl"), imported);
}
use of org.osgi.framework.wiring.BundleWiring in project aries by apache.
the class FrameworkMBeanTest method testGetDependencyClosure.
@Test
public void testGetDependencyClosure() throws Exception {
Bundle bundleA = getBundleByName("org.apache.aries.jmx.test.bundlea");
Bundle bundleB = getBundleByName("org.apache.aries.jmx.test.bundleb");
BundleWiring bw = (BundleWiring) bundleB.adapt(BundleWiring.class);
List<BundleWire> initialRequiredWires = bw.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
assertEquals(1, initialRequiredWires.size());
BundleWire wire = initialRequiredWires.get(0);
Map<String, Object> capabilityAttributes = wire.getCapability().getAttributes();
assertEquals("Precondition", bundleA.getSymbolicName(), capabilityAttributes.get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE));
assertEquals("Precondition", new Version("1.0"), capabilityAttributes.get(Constants.BUNDLE_VERSION_ATTRIBUTE));
assertEquals("Precondition", "org.apache.aries.jmx.test.bundlea.api", capabilityAttributes.get(BundleRevision.PACKAGE_NAMESPACE));
Collection<Bundle> expectedDC = ((FrameworkWiring) context().getBundle(0).adapt(FrameworkWiring.class)).getDependencyClosure(Collections.singleton(bundleA));
Set<Long> expectedClosure = new TreeSet<Long>();
for (Bundle b : expectedDC) {
expectedClosure.add(b.getBundleId());
}
long[] actualDC = framework.getDependencyClosure(new long[] { bundleA.getBundleId() });
Set<Long> actualClosure = new TreeSet<Long>();
for (long l : actualDC) {
actualClosure.add(l);
}
assertEquals(expectedClosure, actualClosure);
}
use of org.osgi.framework.wiring.BundleWiring in project aries by apache.
the class BundleWiringStateMBeanTest method testRevisionsWiring.
@Test
public void testRevisionsWiring() throws Exception {
TabularData jmxWiringTable = brsMBean.getRevisionsWiring(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(1, jmxWiringTable.size());
CompositeData jmxWiring = (CompositeData) jmxWiringTable.values().iterator().next();
Assert.assertEquals(BundleWiringStateMBean.BUNDLE_WIRING_TYPE, jmxWiring.getCompositeType());
Assert.assertEquals(bundleA.getBundleId(), jmxWiring.get(BundleWiringStateMBean.BUNDLE_ID));
BundleWiring bw = (BundleWiring) bundleA.adapt(BundleWiring.class);
assertBundleWiring(bw, jmxWiring);
}
Aggregations