use of test.lib.MockRegistry in project bnd by bndtools.
the class BndrunResolveContextTest method testResolveSystemBundleAlias.
public static void testResolveSystemBundleAlias() {
MockRegistry registry = new MockRegistry();
registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
BndEditModel runModel = new BndEditModel();
runModel.setRunFw("org.apache.felix.framework");
runModel.setEE(EE.JavaSE_1_6);
BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
Requirement req = new CapReqBuilder("osgi.wiring.host").addDirective("filter", "(osgi.wiring.host=system.bundle)").buildSyntheticRequirement();
List<Capability> providers = context.findProviders(req);
assertEquals(1, providers.size());
assertEquals(IO.getFile("testdata/repo3/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
}
use of test.lib.MockRegistry in project bnd by bndtools.
the class BndrunResolveContextTest method testJREPackageNotResolved.
public static void testJREPackageNotResolved() {
MockRegistry registry = new MockRegistry();
registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
BndEditModel runModel = new BndEditModel();
runModel.setRunFw("org.apache.felix.framework");
// javax.annotation added in Java 6
runModel.setEE(EE.J2SE_1_5);
BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
Requirement req = CapReqBuilder.createPackageRequirement("javax.annotation", null).buildSyntheticRequirement();
List<Capability> providers = context.findProviders(req);
assertEquals(0, providers.size());
}
use of test.lib.MockRegistry in project bnd by bndtools.
the class BndrunResolveContextTest method testFrameworkCapabilitiesPreferredOverRepository.
public static void testFrameworkCapabilitiesPreferredOverRepository() {
MockRegistry registry = new MockRegistry();
registry.addPlugin(createRepo(IO.getFile("testdata/osgi.cmpn-4.3.0.index.xml")));
registry.addPlugin(createRepo(IO.getFile("testdata/org.apache.felix.framework-4.0.2.index.xml")));
BndEditModel runModel = new BndEditModel();
runModel.setRunFw("org.apache.felix.framework");
Requirement requirement = new CapReqBuilder("osgi.wiring.package").addDirective("filter", "(&(osgi.wiring.package=org.osgi.util.tracker)(version>=1.5)(!(version>=1.6)))").buildSyntheticRequirement();
BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
List<Capability> providers = context.findProviders(requirement);
assertEquals(2, providers.size());
assertEquals(IO.getFile("testdata/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
assertEquals(IO.getFile("testdata/osgi.cmpn-4.3.0.jar").toURI(), findContentURI(providers.get(1).getResource()));
}
use of test.lib.MockRegistry in project bnd by bndtools.
the class BndrunResolveContextTest method testResolverHookCannotFilterFrameworkCapabilities.
public static void testResolverHookCannotFilterFrameworkCapabilities() {
MockRegistry registry = new MockRegistry();
registry.addPlugin(createRepo(IO.getFile("testdata/osgi.cmpn-4.3.0.index.xml")));
registry.addPlugin(createRepo(IO.getFile("testdata/org.apache.felix.framework-4.0.2.index.xml")));
// Add a hook that tries to remove all capabilities from resource with
// id "org.apache.felix.framework"
registry.addPlugin(new ResolverHook() {
public void filterMatches(Requirement requirement, List<Capability> candidates) {
for (Iterator<Capability> iter = candidates.iterator(); iter.hasNext(); ) {
Object id = iter.next().getResource().getCapabilities("osgi.identity").get(0).getAttributes().get("osgi.identity");
if ("org.apache.felix.framework".equals(id)) {
fail("this line should not be reached");
}
}
}
});
BndEditModel runModel = new BndEditModel();
runModel.setRunFw("org.apache.felix.framework");
Requirement requirement = new CapReqBuilder("osgi.wiring.package").addDirective("filter", "(&(osgi.wiring.package=org.osgi.util.tracker)(version>=1.5)(!(version>=1.6)))").buildSyntheticRequirement();
BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
List<Capability> providers = context.findProviders(requirement);
// The filter was ineffective
assertEquals(2, providers.size());
assertEquals(IO.getFile("testdata/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
assertEquals(IO.getFile("testdata/osgi.cmpn-4.3.0.jar").toURI(), findContentURI(providers.get(1).getResource()));
}
use of test.lib.MockRegistry in project bnd by bndtools.
the class BndrunResolveContextTest method testEffective3.
public static void testEffective3() {
BndEditModel model = new BndEditModel();
model.genericSet(BndrunResolveContext.RUN_EFFECTIVE_INSTRUCTION, "active;skip:=\"filtered.ns,another.filtered.ns\", arbitrary");
BndrunResolveContext context = new BndrunResolveContext(model, new MockRegistry(), log);
Requirement resolveReq = new CapReqBuilder("dummy.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, Namespace.EFFECTIVE_RESOLVE).buildSyntheticRequirement();
Requirement activeReq = new CapReqBuilder("dummy.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, Namespace.EFFECTIVE_ACTIVE).buildSyntheticRequirement();
Requirement filteredActiveReq = new CapReqBuilder("filtered.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, Namespace.EFFECTIVE_ACTIVE).buildSyntheticRequirement();
Requirement anotherFilteredActiveReq = new CapReqBuilder("another.filtered.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, Namespace.EFFECTIVE_ACTIVE).buildSyntheticRequirement();
Requirement arbitrary1Req = new CapReqBuilder("dummy.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, "arbitrary").buildSyntheticRequirement();
Requirement noEffectiveDirectiveReq = new CapReqBuilder("dummy.ns").buildSyntheticRequirement();
assertTrue(context.isEffective(resolveReq));
assertTrue(context.isEffective(activeReq));
assertTrue(context.isEffective(arbitrary1Req));
assertFalse(context.isEffective(filteredActiveReq));
assertFalse(context.isEffective(anotherFilteredActiveReq));
assertTrue(context.isEffective(noEffectiveDirectiveReq));
}
Aggregations