Search in sources :

Example 1 with MavenArtifactProvisionOption

use of org.ops4j.pax.exam.options.MavenArtifactProvisionOption in project motech by motech.

the class BasePaxIT method dependencies.

/**
 * Returns the Pax Exam options describing the dependencies for the test (modules other than the tested one).
 * This method will take all dependencies of the tested module (using Maven) and remove dependencies outside of scopes not
 * being used during the test and dependencies that are marked as ignored. More specific methods than this one should be
 * easier to override in order to control the dependency management for the test. Only the osgi-platform module will be marked for being
 * started by this method, since it is responsible for starting other bundles.
 * @return the Pax Exam options describing the dependencies to use during the test.
 * @see #getAdditionalTestDependencies()
 * @see #getIgnoredDependencies()
 * @see #getRequiredDependencyScopes()
 */
protected Option dependencies() {
    List<MavenArtifact> mavenDependencies = getMavenArtifacts();
    List<MavenArtifactProvisionOption> options = new ArrayList<>();
    Set<String> ignoredDependencies = getIgnoredDependencies();
    Set<String> testDependencies = getTestDependencies();
    Set<String> includedScopes = getRequiredDependencyScopes();
    for (MavenArtifact artifact : mavenDependencies) {
        String groupId = artifact.getGroupId();
        String artifactId = artifact.getArtifactId();
        String version = artifact.getVersion();
        MavenArtifactProvisionOption mavenOption = mavenBundle(groupId, artifactId, version);
        String artifactStr = artifact.toGroupArtifactString();
        boolean shouldInclude = includedScopes.contains(artifact.getScope()) || testDependencies.contains(artifactStr);
        if (shouldInclude && !ignoredDependencies.contains(artifactStr)) {
            // we only start the platform bundle
            if (!MOTECH_PLATFORM_BUNDLE.equals(artifactStr)) {
                mavenOption = mavenOption.noStart();
            }
            options.add(mavenOption);
        }
    }
    return composite(options.toArray(new Option[options.size()]));
}
Also used : ArrayList(java.util.ArrayList) MavenArtifactProvisionOption(org.ops4j.pax.exam.options.MavenArtifactProvisionOption) Option(org.ops4j.pax.exam.Option) MavenArtifactProvisionOption(org.ops4j.pax.exam.options.MavenArtifactProvisionOption) MavenArtifact(org.motechproject.testing.osgi.mvn.MavenArtifact)

Example 2 with MavenArtifactProvisionOption

use of org.ops4j.pax.exam.options.MavenArtifactProvisionOption in project java-driver by datastax.

the class MailboxServiceGuava21IT method guava21Config.

@Configuration
public Option[] guava21Config() {
    MavenArtifactProvisionOption guavaBundle = guavaBundle();
    String javaVersion = System.getProperty("java.version");
    // will fail to load for < 1.8 and we plan on skipping the test anyways.
    if (javaVersion.compareTo("1.8") >= 0) {
        guavaBundle = guavaBundle.version("21.0");
    }
    return options(defaultOptions(), nettyBundles(), guavaBundle, driverBundle(), extrasBundle(), mappingBundle(), mailboxBundle());
}
Also used : MavenArtifactProvisionOption(org.ops4j.pax.exam.options.MavenArtifactProvisionOption) Configuration(org.ops4j.pax.exam.Configuration)

Example 3 with MavenArtifactProvisionOption

use of org.ops4j.pax.exam.options.MavenArtifactProvisionOption in project aries by apache.

the class IsolatedCfgAdminRuntimeTest method constructApplications.

/**
 * Creates two applications, as follows:
 * <p/>
 * - helloworld-bp.eba ------
 * |
 * | This application contains a helloworld bundle which contains an interface and impl for HelloWorld. Upon being started
 * | blueprint will create a new container for this bundle and register the HelloWorld service. The service will be injected
 * | with a message coming from the ConfigurationAdmin service using the PID: helloworld-bp. As a CM property placeholder is
 * | used, a ManagedService will also be registered on the bundles behalf so that further updates can be captured. Note that
 * | the blueprint configuration is wired to reload the container on a configuration update (to allow easier tracking of when
 * | to test service contents etc).
 * |
 * | The application also contains a configuration admin bundle (pulled from Maven).
 * ---------------------------
 * <p/>
 * - helloworld-mn.eba -------
 * |
 * | This application contains a helloworld bundle containing an activator that will register itself as a ManagedService for the
 * | PID: helloworld-mn. The activator will also expose out a HelloWorld service. Upon recieving an update from the packaged
 * | Configuration Admin service, the HelloWorld service will be re-registered using the latest configuration, namely the "message".
 * |
 * | The application also contains a configuration admin bundle (pulled from Maven).
 * ---------------------------
 *
 * @throws Exception
 */
@Before
public void constructApplications() throws Exception {
    Assert.assertNotNull("Could not find Maven URL handler", (new RichBundleContext(context())).getService(URLStreamHandlerService.class, "url.handler.protocol=mvn", 300000));
    MavenArtifactProvisionOption configAdminProvisionOption = mavenBundleInTest(getClass().getClassLoader(), "org.apache.felix", "org.apache.felix.configadmin");
    Assert.assertNotNull("Unable to lookup config admin maven bundle", configAdminProvisionOption);
    URL configAdminUrl = new URL(configAdminProvisionOption.getURL());
    ZipFixture helloWorldBluePrintEba = ArchiveFixture.newZip().binary("META-INF/APPLICATION.MF", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("isolated/config/APPLICATION-BP.MF")).binary("org.apache.felix.configadmin.jar", configAdminUrl.openStream()).jar("helloworld-bundle.jar").manifest().symbolicName("org.apache.aries.isolated.helloworldbp").attribute("Bundle-Version", "1.0.0").attribute("Import-Package", "org.osgi.service.cm").end().binary("org/apache/aries/isolated/sample/HelloWorld.class", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorld.class")).binary("org/apache/aries/isolated/sample/HelloWorldImpl.class", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorldImpl.class")).binary("OSGI-INF/blueprint/blueprint.xml", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("isolated/config/blueprint.xml")).end();
    ZipFixture helloWorldManualEba = ArchiveFixture.newZip().binary("META-INF/APPLICATION.MF", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("isolated/config/APPLICATION-MN.MF")).binary("org.apache.felix.configadmin.jar", configAdminUrl.openStream()).jar("helloworld-bundle.jar").manifest().symbolicName("org.apache.aries.isolated.helloworldmn").attribute("Bundle-Version", "1.0.0").attribute("Bundle-Activator", "org.apache.aries.isolated.config.HelloWorldManagedServiceImpl").attribute("Import-Package", "org.osgi.framework,org.osgi.service.cm").end().binary("org/apache/aries/isolated/sample/HelloWorld.class", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorld.class")).binary("org/apache/aries/isolated/sample/HelloWorldImpl.class", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorldImpl.class")).binary("org/apache/aries/isolated/config/HelloWorldManagedServiceImpl.class", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/config/HelloWorldManagedServiceImpl.class")).end();
    FileOutputStream fout = new FileOutputStream(APP_HWBP);
    helloWorldBluePrintEba.writeOut(fout);
    fout.close();
    fout = new FileOutputStream(APP_HWMN);
    helloWorldManualEba.writeOut(fout);
    fout.close();
}
Also used : ZipFixture(org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture) RichBundleContext(org.apache.aries.itest.RichBundleContext) URLStreamHandlerService(org.osgi.service.url.URLStreamHandlerService) MavenArtifactProvisionOption(org.ops4j.pax.exam.options.MavenArtifactProvisionOption) URL(java.net.URL) Before(org.junit.Before)

Aggregations

MavenArtifactProvisionOption (org.ops4j.pax.exam.options.MavenArtifactProvisionOption)3 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 RichBundleContext (org.apache.aries.itest.RichBundleContext)1 ZipFixture (org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture)1 Before (org.junit.Before)1 MavenArtifact (org.motechproject.testing.osgi.mvn.MavenArtifact)1 Configuration (org.ops4j.pax.exam.Configuration)1 Option (org.ops4j.pax.exam.Option)1 URLStreamHandlerService (org.osgi.service.url.URLStreamHandlerService)1