Search in sources :

Example 21 with MockRegistry

use of test.lib.MockRegistry in project bnd by bndtools.

the class BndrunResolveContextTest method testEffective2.

public static void testEffective2() {
    BndEditModel model = new BndEditModel();
    model.genericSet(BndrunResolveContext.RUN_EFFECTIVE_INSTRUCTION, "active, 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 arbitrary1Req = new CapReqBuilder("dummy.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, "arbitrary").buildSyntheticRequirement();
    Requirement arbitrary2Req = new CapReqBuilder("dummy.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, "VeryArbitrary").buildSyntheticRequirement();
    Requirement noEffectiveDirectiveReq = new CapReqBuilder("dummy.ns").buildSyntheticRequirement();
    assertTrue(context.isEffective(resolveReq));
    assertTrue(context.isEffective(activeReq));
    assertTrue(context.isEffective(arbitrary1Req));
    assertFalse(context.isEffective(arbitrary2Req));
    assertTrue(context.isEffective(noEffectiveDirectiveReq));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) MockRegistry(test.lib.MockRegistry) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 22 with MockRegistry

use of test.lib.MockRegistry in project bnd by bndtools.

the class BndrunResolveContextTest method testSelfCapabilityPreferredOverRepository.

public static void testSelfCapabilityPreferredOverRepository() {
    MockRegistry registry = new MockRegistry();
    Repository repo = createRepo(IO.getFile("testdata/repo4.index.xml"));
    registry.addPlugin(repo);
    Requirement resourceReq = new CapReqBuilder("osgi.identity").addDirective("filter", "(osgi.identity=dummy-selfcap)").buildSyntheticRequirement();
    Resource resource = repo.findProviders(Collections.singleton(resourceReq)).get(resourceReq).iterator().next().getResource();
    Requirement packageReq = resource.getRequirements("osgi.wiring.package").get(0);
    BndEditModel runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework");
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    List<Capability> providers = context.findProviders(packageReq);
    assertNotNull(providers);
    assertEquals(2, providers.size());
    assertEquals(IO.getFile("testdata/repo4/dummy.jar").toURI(), findContentURI(providers.get(0).getResource()));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Repository(org.osgi.service.repository.Repository) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) MockRegistry(test.lib.MockRegistry) Resource(org.osgi.resource.Resource) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 23 with MockRegistry

use of test.lib.MockRegistry in project bnd by bndtools.

the class BndrunResolveContextTest method testEffective.

public static void testEffective() {
    BndrunResolveContext context = new BndrunResolveContext(new BndEditModel(), 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 noEffectiveDirectiveReq = new CapReqBuilder("dummy.ns").buildSyntheticRequirement();
    assertTrue(context.isEffective(resolveReq));
    assertFalse(context.isEffective(activeReq));
    assertTrue(context.isEffective(noEffectiveDirectiveReq));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) MockRegistry(test.lib.MockRegistry) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 24 with MockRegistry

use of test.lib.MockRegistry in project bnd by bndtools.

the class TestLocalIndexGeneration method testFailToGenerate.

public void testFailToGenerate() throws Exception {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(new FailingGeneratingProvider());
    LocalIndexedRepo repo = new LocalIndexedRepo();
    repo.setRegistry(registry);
    repo.setReporter(reporter);
    Map<String, String> config = new HashMap<String, String>();
    config.put("local", outputDir.getAbsolutePath());
    config.put("type", "Fail");
    repo.setProperties(config);
    repo.put(new BufferedInputStream(new FileInputStream("testdata/bundles/name.njbartlett.osgi.emf.minimal-2.6.1.jar")), new RepositoryPlugin.PutOptions());
    assertTrue(reporter.getErrors().size() > 0);
    assertEquals(0, reporter.getWarnings().size());
    reporter.clear();
}
Also used : FailingGeneratingProvider(test.repository.FailingGeneratingProvider) HashMap(java.util.HashMap) BufferedInputStream(java.io.BufferedInputStream) MockRegistry(test.lib.MockRegistry) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) FileInputStream(java.io.FileInputStream)

Example 25 with MockRegistry

use of test.lib.MockRegistry in project bnd by bndtools.

the class TestMultipleLocalIndexGeneration method setUp.

protected void setUp() throws Exception {
    // Ensure output directory exists and is empty
    outputDir = IO.getFile("generated/tmp/test/" + getName());
    IO.deleteWithException(outputDir);
    if (!outputDir.exists() && !outputDir.mkdirs()) {
        throw new IOException("Could not create directory " + outputDir);
    }
    // Setup the repo
    reporter = new Processor();
    repo = new LocalIndexedRepo();
    Map<String, String> config = new HashMap<String, String>();
    config.put("local", outputDir.getAbsolutePath());
    config.put("type", "OBR|R5");
    repo.setProperties(config);
    // Add the BundleIndexer plugin
    registry = new MockRegistry();
    BundleIndexerImpl obrIndexer = new BundleIndexerImpl();
    registry.addPlugin(obrIndexer);
    repo.setRegistry(registry);
    repo.setReporter(reporter);
}
Also used : Processor(aQute.bnd.osgi.Processor) HashMap(java.util.HashMap) MockRegistry(test.lib.MockRegistry) IOException(java.io.IOException) BundleIndexerImpl(org.osgi.impl.bundle.bindex.BundleIndexerImpl)

Aggregations

MockRegistry (test.lib.MockRegistry)41 BndEditModel (aQute.bnd.build.model.BndEditModel)34 Requirement (org.osgi.resource.Requirement)32 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)28 Capability (org.osgi.resource.Capability)26 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)25 Resource (org.osgi.resource.Resource)15 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)7 List (java.util.List)6 Resolver (org.osgi.service.resolver.Resolver)6 Processor (aQute.bnd.osgi.Processor)5 File (java.io.File)4 ExportedPackage (aQute.bnd.build.model.clauses.ExportedPackage)2 Parameters (aQute.bnd.header.Parameters)2 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)2 ResolverHook (aQute.bnd.service.resolve.hook.ResolverHook)2 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 Iterator (java.util.Iterator)2