use of org.osgi.framework.wiring.BundleRequirement in project aries by apache.
the class BundleWiringStateMBeanTest method assertBundleWiring.
private void assertBundleWiring(BundleWiring bundleWiring, CompositeData jmxWiring) {
CompositeData[] jmxCapabilities = (CompositeData[]) jmxWiring.get(BundleWiringStateMBean.CAPABILITIES);
List<BundleCapability> capabilities = bundleWiring.getCapabilities(BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(capabilities.size(), jmxCapabilities.length);
Map<Map<String, Object>, Map<String, String>> expectedCapabilities = capabilitiesToMap(capabilities);
Map<Map<String, Object>, Map<String, String>> actualCapabilities = jmxCapReqToMap(jmxCapabilities);
Assert.assertEquals(expectedCapabilities, actualCapabilities);
CompositeData[] jmxRequirements = (CompositeData[]) jmxWiring.get(BundleWiringStateMBean.REQUIREMENTS);
List<BundleRequirement> requirements = bundleWiring.getRequirements(BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(requirements.size(), jmxRequirements.length);
Map<Map<String, Object>, Map<String, String>> expectedRequirements = requirementsToMap(requirements);
Map<Map<String, Object>, Map<String, String>> actualRequirements = jmxCapReqToMap(jmxRequirements);
Assert.assertEquals(expectedRequirements, actualRequirements);
List<BundleWire> requiredWires = bundleWiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
CompositeData[] jmxRequiredWires = (CompositeData[]) jmxWiring.get(BundleWiringStateMBean.REQUIRED_WIRES);
Assert.assertEquals(requiredWires.size(), jmxRequiredWires.length);
Set<List<Object>> expectedRequiredWires = new HashSet<List<Object>>();
for (BundleWire wire : requiredWires) {
List<Object> data = new ArrayList<Object>();
data.add(wire.getCapability().getRevision().getBundle().getBundleId());
data.add(wire.getCapability().getAttributes());
data.add(wire.getCapability().getDirectives());
data.add(wire.getRequirement().getRevision().getBundle().getBundleId());
data.add(wire.getRequirement().getAttributes());
data.add(wire.getRequirement().getDirectives());
expectedRequiredWires.add(data);
}
Set<List<Object>> actualRequiredWires = new HashSet<List<Object>>();
for (CompositeData wire : jmxRequiredWires) {
List<Object> data = new ArrayList<Object>();
data.add(wire.get(BundleWiringStateMBean.PROVIDER_BUNDLE_ID));
// TODO bundle revision id
data.add(getJmxAttributes((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_CAPABILITY)));
data.add(getJmxDirectives((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_CAPABILITY)));
data.add(wire.get(BundleWiringStateMBean.REQUIRER_BUNDLE_ID));
data.add(getJmxAttributes((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_REQUIREMENT)));
data.add(getJmxDirectives((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_REQUIREMENT)));
actualRequiredWires.add(data);
}
Assert.assertEquals(expectedRequiredWires, actualRequiredWires);
List<BundleWire> providedWires = bundleWiring.getProvidedWires(BundleRevision.PACKAGE_NAMESPACE);
CompositeData[] jmxProvidedWires = (CompositeData[]) jmxWiring.get(BundleWiringStateMBean.PROVIDED_WIRES);
Assert.assertEquals(providedWires.size(), jmxProvidedWires.length);
HashSet<List<Object>> expectedProvidedWires = new HashSet<List<Object>>();
for (BundleWire wire : providedWires) {
List<Object> data = new ArrayList<Object>();
data.add(wire.getCapability().getRevision().getBundle().getBundleId());
data.add(wire.getCapability().getAttributes());
data.add(wire.getCapability().getDirectives());
data.add(wire.getRequirement().getRevision().getBundle().getBundleId());
data.add(wire.getRequirement().getAttributes());
data.add(wire.getRequirement().getDirectives());
expectedProvidedWires.add(data);
}
Set<List<Object>> actualProvidedWires = new HashSet<List<Object>>();
for (CompositeData wire : jmxProvidedWires) {
List<Object> data = new ArrayList<Object>();
data.add(wire.get(BundleWiringStateMBean.PROVIDER_BUNDLE_ID));
data.add(getJmxAttributes((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_CAPABILITY)));
data.add(getJmxDirectives((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_CAPABILITY)));
data.add(wire.get(BundleWiringStateMBean.REQUIRER_BUNDLE_ID));
data.add(getJmxAttributes((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_REQUIREMENT)));
data.add(getJmxDirectives((CompositeData) wire.get(BundleWiringStateMBean.BUNDLE_REQUIREMENT)));
actualProvidedWires.add(data);
}
Assert.assertEquals(expectedProvidedWires, actualProvidedWires);
}
use of org.osgi.framework.wiring.BundleRequirement in project aries by apache.
the class ClientWeavingHookGenericCapabilityTest method testHeadersFromFragment.
@Test
public void testHeadersFromFragment() throws Exception {
// Register the bundle that provides the SPI implementation.
Bundle providerBundle = mockProviderBundle("impl1", 1);
activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle, new HashMap<String, Object>());
Dictionary<String, String> fragmentConsumerHeaders = new Hashtable<String, String>();
fragmentConsumerHeaders.put(SpiFlyConstants.REQUIRE_CAPABILITY, SpiFlyConstants.CLIENT_REQUIREMENT);
Bundle fragment = EasyMock.createMock(Bundle.class);
EasyMock.expect(fragment.getHeaders()).andReturn(fragmentConsumerHeaders).anyTimes();
EasyMock.replay(fragment);
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);
BundleWire wire = EasyMock.createMock(BundleWire.class);
EasyMock.expect(wire.getRequirement()).andReturn(req).anyTimes();
EasyMock.replay(wire);
List<BundleWire> wires = Collections.singletonList(wire);
BundleWiring wiring = EasyMock.createMock(BundleWiring.class);
EasyMock.expect(wiring.getProvidedWires("osgi.wiring.host")).andReturn(wires).anyTimes();
EasyMock.replay(wiring);
BundleRevision rev = EasyMock.createMock(BundleRevision.class);
EasyMock.expect(rev.getWiring()).andReturn(wiring).anyTimes();
EasyMock.replay(rev);
Bundle consumerBundle = mockConsumerBundle(new Hashtable<String, String>(), rev, providerBundle);
activator.addConsumerWeavingData(consumerBundle, SpiFlyConstants.REQUIRE_CAPABILITY);
Bundle spiFlyBundle = mockSpiFlyBundle("spifly", Version.parseVersion("1.9.4"), consumerBundle, providerBundle);
WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext(), activator);
// Weave the TestClient class.
URL clsUrl = getClass().getResource("TestClient.class");
Assert.assertNotNull("Precondition", clsUrl);
String clientClassName = "org.apache.aries.spifly.dynamic.TestClient";
WovenClass wc = new MyWovenClass(clsUrl, clientClassName, consumerBundle);
Assert.assertEquals("Precondition", 0, wc.getDynamicImports().size());
wh.weave(wc);
Assert.assertEquals(1, wc.getDynamicImports().size());
String di1 = "org.apache.aries.spifly";
String di = wc.getDynamicImports().get(0);
Assert.assertTrue("Weaving should have added a dynamic import", di1.equals(di));
// Invoke the woven class and check that it properly sets the TCCL so that the
// META-INF/services/org.apache.aries.mytest.MySPI file from impl1 is visible.
Class<?> cls = wc.getDefinedClass();
Method method = cls.getMethod("test", new Class[] { String.class });
Object result = method.invoke(cls.getDeclaredConstructor().newInstance(), "hello");
Assert.assertEquals(Collections.singleton("olleh"), result);
}
use of org.osgi.framework.wiring.BundleRequirement in project aries by apache.
the class BundleWiringState method getRevisionWiring.
private CompositeData getRevisionWiring(BundleRevision revision, int revisionID, String namespace, Map<BundleRevision, Integer> revisionIDMap) {
BundleWiring wiring = revision.getWiring();
List<BundleCapability> capabilities = wiring.getCapabilities(namespace);
List<BundleRequirement> requirements = wiring.getRequirements(namespace);
List<BundleWire> providedWires = wiring.getProvidedWires(namespace);
List<BundleWire> requiredWires = wiring.getRequiredWires(namespace);
BundleWiringData data = new BundleWiringData(wiring.getBundle().getBundleId(), revisionID, capabilities, requirements, providedWires, requiredWires, revisionIDMap);
return data.toCompositeData();
}
use of org.osgi.framework.wiring.BundleRequirement in project aries by apache.
the class Aries1383Test method test11.
/*
* (11) Subsystem with apache-aries-provision-dependencies:=resolve undergoes
* the following state transitions when starting fails due to a runtime
* resolution failure: INSTALLING -> INSTALLED -> RESOLVING -> INSTALLED.
*/
@Test
public void test11() throws Exception {
Subsystem root = getRootSubsystem();
subsystemEvents.clear();
Subsystem subsystem = root.install(APPLICATION_DEPENDENCY_IN_ARCHIVE, applicationDependencyInArchive());
ServiceRegistration<ResolverHookFactory> registration = bundleContext.registerService(ResolverHookFactory.class, new ResolverHookFactory() {
@Override
public ResolverHook begin(Collection<BundleRevision> triggers) {
return new ResolverHook() {
@Override
public void filterResolvable(Collection<BundleRevision> candidates) {
for (Iterator<BundleRevision> i = candidates.iterator(); i.hasNext(); ) {
BundleRevision revision = i.next();
if (revision.getSymbolicName().equals(BUNDLE_B)) {
i.remove();
}
}
}
@Override
public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) {
// Nothing.
}
@Override
public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
// Nothing.
}
@Override
public void end() {
// Nothing.
}
};
}
}, null);
try {
subsystem.start();
stopSubsystemSilently(subsystem);
fail("Subsystem should not have started");
} catch (SubsystemException e) {
e.printStackTrace();
long id = lastSubsystemId();
assertEvent(id, APPLICATION_DEPENDENCY_IN_ARCHIVE, Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.INSTALLING, subsystemEvents.poll(id, 5000), ServiceEvent.REGISTERED);
assertEvent(id, APPLICATION_DEPENDENCY_IN_ARCHIVE, Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.INSTALLED, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertEvent(id, APPLICATION_DEPENDENCY_IN_ARCHIVE, Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.RESOLVING, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertEvent(id, APPLICATION_DEPENDENCY_IN_ARCHIVE, Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.INSTALLED, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
} finally {
registration.unregister();
uninstallSubsystemSilently(subsystem);
}
}
use of org.osgi.framework.wiring.BundleRequirement in project aries by apache.
the class BundleWiringData method getRequirements.
private static CompositeData[] getRequirements(List<BundleRequirement> requirementList) throws OpenDataException {
CompositeData[] reqData = new CompositeData[requirementList.size()];
for (int i = 0; i < requirementList.size(); i++) {
BundleRequirement requirement = requirementList.get(i);
reqData[i] = getCapReqCompositeData(BundleWiringStateMBean.BUNDLE_REQUIREMENT_TYPE, requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet());
}
return reqData;
}
Aggregations