use of org.osgi.resource.Capability in project aries by apache.
the class Aries1425Test method testToRequirement.
@Test
public void testToRequirement() {
SubsystemContentHeader header = new SubsystemContentHeader(HEADER_1);
Collection<SubsystemContentHeader.Clause> clauses = header.getClauses();
assertEquals("Wrong size", 3, clauses.size());
Map<String, SubsystemContentHeader.Clause> map = new HashMap<String, SubsystemContentHeader.Clause>(3);
for (SubsystemContentHeader.Clause clause : clauses) {
map.put(clause.toString(), clause);
}
Resource resource = new Resource() {
@Override
public List<Capability> getCapabilities(String namespace) {
return Collections.emptyList();
}
@Override
public List<Requirement> getRequirements(String namespace) {
return Collections.emptyList();
}
};
SubsystemContentHeader.Clause clause = map.get(BUNDLE_A);
Requirement requirement = clause.toRequirement(resource);
assertTrue("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, BUNDLE_A, Version.emptyVersion, IdentityNamespace.TYPE_FRAGMENT)));
assertTrue("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, BUNDLE_A, Version.emptyVersion, IdentityNamespace.TYPE_BUNDLE)));
clause = map.get(BUNDLE_B);
requirement = clause.toRequirement(resource);
assertFalse("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, "bundle.b", Version.emptyVersion, IdentityNamespace.TYPE_FRAGMENT)));
assertTrue("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, "bundle.b", Version.emptyVersion, IdentityNamespace.TYPE_BUNDLE)));
clause = map.get(BUNDLE_C);
requirement = clause.toRequirement(resource);
assertTrue("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, "bundle.c", Version.emptyVersion, IdentityNamespace.TYPE_FRAGMENT)));
assertFalse("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, "bundle.c", Version.emptyVersion, IdentityNamespace.TYPE_BUNDLE)));
}
use of org.osgi.resource.Capability in project aries by apache.
the class SubsystemResource method findDependency.
private Resource findDependency(ProvisionResourceHeader.Clause clause) {
Attribute attribute = clause.getAttribute(DeployedContentHeader.Clause.ATTRIBUTE_RESOURCEID);
long resourceId = attribute == null ? -1 : Long.parseLong(String.valueOf(attribute.getValue()));
if (resourceId != -1) {
String type = clause.getType();
if (IdentityNamespace.TYPE_BUNDLE.equals(type) || IdentityNamespace.TYPE_FRAGMENT.equals(type))
return Activator.getInstance().getBundleContext().getBundle(0).getBundleContext().getBundle(resourceId).adapt(BundleRevision.class);
else
return Activator.getInstance().getSubsystems().getSubsystemById(resourceId);
}
OsgiIdentityRequirement requirement = new OsgiIdentityRequirement(clause.getPath(), clause.getDeployedVersion(), clause.getType(), true);
List<Capability> capabilities = createResolveContext().findProviders(requirement);
if (capabilities.isEmpty())
return null;
return capabilities.get(0).getResource();
}
use of org.osgi.resource.Capability 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.Capability in project aries by apache.
the class ResolveContextTest method testInsertHostedCapability.
@Test
public void testInsertHostedCapability() throws Exception {
Activator prev = getActivator();
try {
Activator activator = createActivator();
setActivator(activator);
SubsystemResource res = new SubsystemResource(new File("."));
ResolveContext rc = new ResolveContext(res);
HostedCapability hc = EasyMock.createNiceMock(HostedCapability.class);
List<Capability> caps = new ArrayList<Capability>() {
// Must use add(idx, obj), get the other add() overloads to complain
@Override
public boolean add(Capability e) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends Capability> c) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(int index, Collection<? extends Capability> c) {
throw new UnsupportedOperationException();
}
};
caps.add(0, EasyMock.createNiceMock(HostedCapability.class));
assertEquals(1, rc.insertHostedCapability(caps, hc));
assertSame(hc, caps.get(1));
} finally {
setActivator(prev);
}
}
use of org.osgi.resource.Capability 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));
}
Aggregations