David M. Karr
David M. Karr

Reputation: 15235

How do I specify a feature to paxexam instead of a maven artifact?

I work on a large codebase whose build produces OSGi bundles that are loaded in Karaf. We have a bunch of PaxExam tests. All of these existing tests load features by their maven GAV.

I'd like to write a test whose only purpose is to verify that all the required bundles load. The test method itself could be empty.

I'd like to specify the feature to load just by the feature name, not by the maven artifact associated with that feature.

For instance, here is an existing config Option block that is similar to all of the other blocks in other tests:

@Configuration
public Option[] config() {
    return new Option[] {
            karafDistributionConfiguration()
            .frameworkUrl(maven().groupId("org.apache.karaf").artifactId("apache-karaf").type("zip")
                    .versionAsInProject())
                    .useDeployFolder(false).unpackDirectory(new File("target/paxexam/unpack/")),
                    systemProperty("sl.config.dir").value("${karaf.etc}"),
                    features(maven().groupId("com.att.detsusl").artifactId("usl-servicefactory-impl").type("xml")
                            .classifier("features").versionAsInProject(), "webconsole", "usl-servicefactory"),
                            logLevel(LogLevelOption.LogLevel.WARN), 
                            when(Boolean.parseBoolean(System.getProperty("debug"))).useOptions(KarafDistributionOption.debugConfiguration("5005", true)),
                            keepRuntimeFolder()
    };
}

Here is the body of a relevant features.xml file:

<feature name='usl-all'>
    <feature>usl-servicefactory</feature>
</feature>

How can I morph the previous config Option block to have it specify the "usl-all" feature, without having to specify a Maven GAV?

Update:

It's unfortunate that I can't write a test that just verifies that a particular feature loads, without going through that non-obvious route.

Nevertheless, I suppose this is the best I can do, except for another problem that I'm having here.

The solution that is provided doesn't actually work, because the POM for this bundle doesn't specify that artifact as a dependency, so "versionAsInProject()" essentially fails. The purpose of the bundle is just to declare the feature, and the feature it includes, which comes from a different bundle, which does declare that artifact as a dependency.

My intention was to write the test in the bundle that declares the containing feature, even though it doesn't have any maven dependencies, or produces any artifact except for the feature declaration.

I did try simply hardcoding the version string, ala 'version("...")', to provide the version that "versionAsInProject()" would have provided. That does work, but that's not an acceptable solution.

So I then tried using the GA of the module POM itself, along with "versionAsInProject()". This actually works, but I really need to understand what this is actually doing. The referenced GA and the feature name don't have much to do with each other. Is the basic idea that it doesn't matter at all which GA is referenced, as long as it exists in the POM somewhere, and the feature name just looks at all the declared features?

Upvotes: 0

Views: 75

Answers (1)

Achim Nierbeck
Achim Nierbeck

Reputation: 5285

You can't, you always need to specify a Maven GAV. So what you need to do is: replace the existing features definition block with this one.

features(
  maven()
    .groupId("com.att.detsusl")
    .artifactId("usl-servicefactory-impl")
    .type("xml")
    .classifier("features").versionAsInProject(), "usl-all"
)

Upvotes: 0

Related Questions