use of org.osgi.framework.wiring.BundleWire in project aries by apache.
the class ProviderBundleTrackerCustomizerGenericCapabilityTest method testCapReqHeadersInFragment.
@Test
public void testCapReqHeadersInFragment() throws Exception {
Bundle mediatorBundle = EasyMock.createMock(Bundle.class);
EasyMock.expect(mediatorBundle.getBundleId()).andReturn(42l).anyTimes();
EasyMock.replay(mediatorBundle);
BaseActivator activator = new BaseActivator() {
@Override
public void start(BundleContext context) throws Exception {
}
};
ProviderBundleTrackerCustomizer customizer = new ProviderBundleTrackerCustomizer(activator, mediatorBundle);
ServiceRegistration<?> sreg = EasyMock.createNiceMock(ServiceRegistration.class);
EasyMock.replay(sreg);
BundleContext implBC = mockSPIBundleContext(sreg);
Dictionary<String, String> headers = new Hashtable<String, String>();
// A typical requirement that is not for us...
headers.put(SpiFlyConstants.REQUIRE_CAPABILITY, "osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(version=1.6))\"");
List<BundleWire> wires = new ArrayList<BundleWire>();
BundleWire wire = EasyMock.createMock(BundleWire.class);
Bundle fragment = EasyMock.createMock(Bundle.class);
BundleRevision frev = EasyMock.createMock(BundleRevision.class);
EasyMock.expect(frev.getBundle()).andReturn(fragment).anyTimes();
EasyMock.replay(frev);
BundleRequirement req = EasyMock.createMock(BundleRequirement.class);
EasyMock.expect(req.getRevision()).andReturn(frev).anyTimes();
EasyMock.replay(req);
EasyMock.expect(wire.getRequirement()).andReturn(req).anyTimes();
EasyMock.replay(wire);
wires.add(wire);
BundleWiring bw = EasyMock.createMock(BundleWiring.class);
EasyMock.expect(bw.getProvidedWires("osgi.wiring.host")).andReturn(wires).anyTimes();
EasyMock.replay(bw);
BundleRevision rev = EasyMock.createMock(BundleRevision.class);
EasyMock.expect(rev.getWiring()).andReturn(bw).anyTimes();
EasyMock.replay(rev);
Bundle implBundle = mockSPIBundle(implBC, headers, rev);
Dictionary<String, String> fheaders = new Hashtable<String, String>();
fheaders.put(SpiFlyConstants.REQUIRE_CAPABILITY, SpiFlyConstants.PROVIDER_REQUIREMENT);
fheaders.put(SpiFlyConstants.PROVIDE_CAPABILITY, SpiFlyConstants.SERVICELOADER_CAPABILITY_NAMESPACE + "; " + SpiFlyConstants.SERVICELOADER_CAPABILITY_NAMESPACE + "=org.apache.aries.mytest.MySPI");
EasyMock.expect(fragment.getHeaders()).andReturn(fheaders).anyTimes();
EasyMock.replay(fragment);
assertEquals("Precondition", 0, activator.findProviderBundles("org.apache.aries.mytest.MySPI").size());
customizer.addingBundle(implBundle, null);
Collection<Bundle> bundles = activator.findProviderBundles("org.apache.aries.mytest.MySPI");
assertEquals(1, bundles.size());
assertSame(implBundle, bundles.iterator().next());
}
use of org.osgi.framework.wiring.BundleWire in project aries by apache.
the class SubsystemDependencyTestBase method verifySinglePackageWiring.
/**
* Check that wiredBundleName in subsystem s is wired to a single package,
* expectedPackage, from expectedProvidingBundle
* @param s
* @param wiredBundleName
* @param expectedPackage
* @param expectedProvidingBundle
*/
protected void verifySinglePackageWiring(Subsystem s, String wiredBundleName, String expectedPackage, String expectedProvidingBundle) {
Bundle wiredBundle = context(s).getBundleByName(wiredBundleName);
assertNotNull("Bundle not found", wiredBundleName);
BundleWiring wiring = (BundleWiring) wiredBundle.adapt(BundleWiring.class);
List<BundleWire> wiredPackages = wiring.getRequiredWires(PACKAGE_NAMESPACE);
assertEquals("Only one package expected", 1, wiredPackages.size());
String packageName = (String) wiredPackages.get(0).getCapability().getAttributes().get(PACKAGE_NAMESPACE);
assertEquals("Wrong package found", expectedPackage, packageName);
String providingBundle = wiredPackages.get(0).getProvider().getSymbolicName();
assertEquals("Package provided by wrong bundle", expectedProvidingBundle, providingBundle);
}
use of org.osgi.framework.wiring.BundleWire in project aries by apache.
the class SubsystemDependencyTestBase method verifyCapabilityWiring.
/**
* Verify that a bundle with wiredBundleName imports a single capability in namespace
* from expectedProvidingBundleName
* @param s
* @param wiredBundleName
* @param namespace
* @param expectedProvidingBundleName
*/
protected void verifyCapabilityWiring(Subsystem s, String wiredBundleName, String namespace, String expectedProvidingBundleName) {
Bundle wiredBundle = context(s).getBundleByName(wiredBundleName);
assertNotNull("Targt bundle " + wiredBundleName + " not found", wiredBundleName);
BundleWiring wiring = (BundleWiring) wiredBundle.adapt(BundleWiring.class);
List<BundleWire> wiredProviders = wiring.getRequiredWires(namespace);
assertEquals("Only one wire for capability namespace " + namespace + " expected", 1, wiredProviders.size());
String capabilityNamespace = (String) wiredProviders.get(0).getCapability().getNamespace();
assertEquals("Wrong namespace", namespace, capabilityNamespace);
String providingBundle = wiredProviders.get(0).getProvider().getSymbolicName();
assertEquals("Wrong bundle provider", expectedProvidingBundleName, providingBundle);
}
use of org.osgi.framework.wiring.BundleWire in project karaf by apache.
the class BundleWiresTest method testFromBundle.
@Test
public void testFromBundle() throws IOException {
BundleWire wire = packageWire(packageFilter, bundleCap(targetBundleId, targetBundleVersion));
Bundle bundle = wiredBundle(Arrays.asList(wire));
c.replay();
BundleWires bwires = new BundleWires(bundle);
bwires.save(BASE_PATH);
c.verify();
Iterator<String> lines = Files.lines(new File("target/bundles/1").toPath()).iterator();
Assert.assertEquals(PackageNamespace.PACKAGE_NAMESPACE + "; " + packageFilter, lines.next());
Assert.assertEquals(targetBundleId + "; version=" + targetBundleVersion, lines.next());
bwires.delete(BASE_PATH);
}
use of org.osgi.framework.wiring.BundleWire in project logging-log4j2 by apache.
the class Activator method start.
@Override
public void start(final BundleContext context) throws Exception {
ProviderUtil.STARTUP_LOCK.lock();
lockingProviderUtil = true;
final BundleWiring self = context.getBundle().adapt(BundleWiring.class);
List<BundleWire> required = self.getRequiredWires(LoggerContextFactory.class.getName());
for (final BundleWire wire : required) {
loadProvider(wire.getProviderWiring());
}
context.addBundleListener(this);
final Bundle[] bundles = context.getBundles();
for (final Bundle bundle : bundles) {
loadProvider(bundle);
}
unlockIfReady();
}
Aggregations