use of org.osgi.resource.Requirement in project aries by apache.
the class RepositoryServiceRepositoryTest method testFindProviders.
@Test
public void testFindProviders() throws Exception {
BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
RepositoryServiceRepository rsr = new RepositoryServiceRepository(bc);
@SuppressWarnings("unchecked") ServiceReference<Object> sr = EasyMock.createMock(ServiceReference.class);
@SuppressWarnings("unchecked") ServiceReference<Object> sr2 = EasyMock.createMock(ServiceReference.class);
@SuppressWarnings("unchecked") ServiceReference<Object> sr3 = EasyMock.createMock(ServiceReference.class);
EasyMock.expect(bc.getAllServiceReferences("org.osgi.service.repository.Repository", null)).andReturn(new ServiceReference[] { sr, sr2, sr3 }).anyTimes();
TestRepository tr = new TestRepository();
EasyMock.expect(bc.getService(sr)).andReturn(tr).anyTimes();
ToastRepository tr2 = new ToastRepository();
EasyMock.expect(bc.getService(sr2)).andReturn(tr2).anyTimes();
Repository tr3 = Creator.create();
EasyMock.expect(bc.getService(sr3)).andReturn(tr3).anyTimes();
EasyMock.replay(bc);
Map<String, String> dirs = Collections.singletonMap("filter", "(org.foo=bar)");
Requirement req = new TestRequirement("org.foo", dirs);
Collection<Capability> res = rsr.findProviders(req);
assertEquals(1, res.size());
Capability cap = res.iterator().next();
assertEquals("org.foo", cap.getNamespace());
assertEquals(1, cap.getAttributes().size());
assertEquals("bar", cap.getAttributes().get("org.foo"));
Map<String, String> dirs2 = Collections.singletonMap("filter", "(org.foo=b)");
Requirement req2 = new TestRequirement("poing", dirs2);
Collection<Capability> res2 = rsr.findProviders(req2);
assertEquals(1, res2.size());
Capability cap2 = res2.iterator().next();
assertEquals("poing", cap2.getNamespace());
assertEquals(1, cap2.getAttributes().size());
assertEquals("b", cap2.getAttributes().get("org.foo"));
Map<String, String> dirs3 = Collections.singletonMap("filter", "(x=y)");
Requirement req3 = new TestRequirement("ns1", dirs3);
Collection<Capability> res3 = rsr.findProviders(req3);
assertEquals(1, res3.size());
Capability cap3 = res3.iterator().next();
assertEquals("ns1", cap3.getNamespace());
assertEquals(1, cap3.getAttributes().size());
assertEquals("y", cap3.getAttributes().get("x"));
}
use of org.osgi.resource.Requirement in project aries by apache.
the class ResourceHelperTest method testMandatoryDirectiveAndNullFilterDirective.
@Test
public void testMandatoryDirectiveAndNullFilterDirective() {
Capability cap = new BasicCapability.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).attribute(PackageNamespace.PACKAGE_NAMESPACE, "com.foo").attribute("a", "b").attribute("b", "c").attribute("c", "d").directive(PackageNamespace.CAPABILITY_MANDATORY_DIRECTIVE, "b").resource(EasyMock.createNiceMock(Resource.class)).build();
Requirement req = new BasicRequirement.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).resource(EasyMock.createNiceMock(Resource.class)).build();
assertFalse("Capability should not match requirement", ResourceHelper.matches(req, cap));
}
use of org.osgi.resource.Requirement in project aries by apache.
the class SubTestRepository method findProviders.
@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
Map<Requirement, Collection<Capability>> res = new HashMap<Requirement, Collection<Capability>>();
for (Requirement req : requirements) {
if (req.getNamespace().equals("ns1") && req.getDirectives().equals(Collections.singletonMap("filter", "(x=y)"))) {
TestCapability cap = new TestCapability("ns1", Collections.<String, Object>singletonMap("x", "y"));
Collection<Capability> caps = Collections.<Capability>singleton(cap);
res.put(req, caps);
}
}
return res;
}
use of org.osgi.resource.Requirement in project aries by apache.
the class BundleRequiredExecutionEnvironmentHeaderTest method assertRequirement.
private void assertRequirement(Requirement requirement, String filter, Resource resource) {
Requirement r = new BasicRequirement.Builder().namespace(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE).directive(ExecutionEnvironmentNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter).resource(resource).build();
assertEquals("Wrong requirement", r, requirement);
}
use of org.osgi.resource.Requirement in project bndtools by bndtools.
the class WorkspaceR5Repository method findProviders.
@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
Map<Requirement, Collection<Capability>> result = new HashMap<Requirement, Collection<Capability>>();
for (Requirement requirement : requirements) {
List<Capability> matches = new LinkedList<Capability>();
result.put(requirement, matches);
for (Entry<IProject, CapabilityIndex> entry : projectMap.entrySet()) {
IProject project = entry.getKey();
if (project.exists() && project.isOpen()) {
CapabilityIndex capabilityIndex = entry.getValue();
capabilityIndex.appendMatchingCapabilities(requirement, matches);
}
}
}
return result;
}
Aggregations