Вопрос

In Karaf, I can install the OBR feature and use obr:addUrl to add a repository.xml and obr:deploy to deploy a bundle along with all the transitive dependencies. I have documented it in https://stackoverflow.com/a/10989017/242042

However, now I want to create a JUnit test using PaxExam, but I can't seem to emulate what I did with Karaf on PaxExam.

Any code snippet that would show how to point to an OBR repository and do a deploy with all the transitive calculations done automatically?

Это было полезно?

Решение 2

I actually found the answer to this a while back. I don't use the obr: protocol handler, instead I actually use an OBR implementation (Apache Aries).

This is how I configured my test case

@Configuration
public static Option[] configuration() throws Exception {
    return options(
            systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level")
                    .value("WARN"),
            frameworkProperty("obr.repository.url").value(
                    new File("target/dependency/repository.xml").toURI()
                            .toASCIIString()),
            bundle("mvn:org.apache.felix/org.osgi.service.obr/1.0.2"),
            bundle("mvn:org.apache.felix/org.apache.felix.bundlerepository/1.6.6"),
            bundle("mvn:org.apache.aries/org.apache.aries.util/0.4"),
            bundle("mvn:org.apache.aries.proxy/org.apache.aries.proxy/0.4"),
            junitBundles());
}

I then have a convenience method in the class to deploy from OBR using an OBR search string

private void obrDeploy(final String filter) throws Exception {
    final Resolver resolver = repositoryAdmin.resolver();
    final Resource[] discoverResources = repositoryAdmin
            .discoverResources(filter);
    for (final Resource r : discoverResources) {
        resolver.add(r);
    }
    assertTrue(resolver.resolve());
    resolver.deploy(true);
}

Then my test cases look like this. This ensures that the tests load up the services it exposes correctly.

@Test
public void testBlueprintBundle() throws Exception {
    obrDeploy("(symbolicname=net.trajano.maven-jee6.blueprint.producer)");
    getService(bundleContext, MongoDbFactory.class);
    getService(bundleContext, BlockingQueue.class);
    getService(bundleContext, Executor.class);
}

Note that this deploys only the bundles at have transitive links as designed. If you have other dependencies that are not present like the implementation bundles then they need to be deployed as well. The following shows a line on how to deploy multiple bundles from OBR with wildcards as well to simplify the tests.

obrDeploy("(|(symbolicname=*.blueprint.consumer)(symbolicname=*.blueprint.producer)(symbolicname=*.hello.osgi))");

The full source is in https://github.com/trajano/maven-jee6/blob/emerging-technologies/osgi-sample/assembly/src/test/java/net/trajano/osgi/test/PaxTest.java

Другие советы

You can use the Pax URL obr: protocol handler to provision individual bundles from an OBR repository in a Pax Exam test, but this won't pull in any transitive dependencies.

In Pax Exam, you always need to provision each bundle by itself. But you can group bundles by composite options to support reuse of test configurations.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top