Search in sources :

Example 36 with Subsystem

use of org.osgi.service.subsystem.Subsystem in project aries by apache.

the class Aries1416Test method testSystemRepositoryBundlePreferredProvider.

@Test
public void testSystemRepositoryBundlePreferredProvider() throws Exception {
    Subsystem root = getRootSubsystem();
    // Install bundle B providing capability b into the root subsystem's
    // region.
    Bundle bundleB = installBundleFromFile(BUNDLE_B, root);
    try {
        // Install application A containing content bundle A requiring 
        // capability b and dependency bundle B providing capability b.
        // Bundle B is not content but will become part of the local 
        // repository. The preferred provider is bundle B. Bundle B from the
        // system repository should be used. Bundle B from the local
        // repository should not be provisioned.
        Subsystem applicationA = installSubsystemFromFile(APPLICATION_A);
        uninstallSubsystemSilently(applicationA);
    } catch (SubsystemException e) {
        e.printStackTrace();
        fail("Subsystem should have installed");
    } finally {
        uninstallSilently(bundleB);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) Test(org.junit.Test) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest)

Example 37 with Subsystem

use of org.osgi.service.subsystem.Subsystem in project aries by apache.

the class Aries1383Test method test16c.

/*
	 * (16) Unscoped subsystem with a value of apache-aries-provision-dependencies 
	 * that is the same as the scoped parent installs successfully.
	 */
@Test
public void test16c() throws Exception {
    Subsystem root = getRootSubsystem();
    try {
        Subsystem subsystem = installSubsystem(root, "application", new SubsystemArchiveBuilder().symbolicName("application").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).subsystem("feature", new SubsystemArchiveBuilder().symbolicName("feature").type(SubsystemConstants.SUBSYSTEM_TYPE_FEATURE + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).build()).build(), false);
        uninstallSubsystemSilently(subsystem);
    } catch (SubsystemException e) {
        e.printStackTrace();
        fail("Subsystem should have installed");
    }
}
Also used : SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest) Test(org.junit.Test)

Example 38 with Subsystem

use of org.osgi.service.subsystem.Subsystem in project aries by apache.

the class Aries1383Test method test13.

/*
	 * (13) The root subsystem has apache-aries-provision-dependencies:=install.
	 */
@Test
public void test13() throws Exception {
    Subsystem root = getRootSubsystem();
    Map<String, String> headers = root.getSubsystemHeaders(null);
    String headerStr = headers.get(SubsystemConstants.SUBSYSTEM_TYPE);
    SubsystemTypeHeader header = new SubsystemTypeHeader(headerStr);
    AriesProvisionDependenciesDirective directive = header.getAriesProvisionDependenciesDirective();
    assertEquals("Wrong directive", AriesProvisionDependenciesDirective.INSTALL, directive);
}
Also used : AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) AriesProvisionDependenciesDirective(org.apache.aries.subsystem.core.archive.AriesProvisionDependenciesDirective) SubsystemTypeHeader(org.apache.aries.subsystem.core.archive.SubsystemTypeHeader) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest) Test(org.junit.Test)

Example 39 with Subsystem

use of org.osgi.service.subsystem.Subsystem in project aries by apache.

the class Aries1383Test method testComApiComImplAppClient.

@Test
public void testComApiComImplAppClient() throws Exception {
    Subsystem root = getRootSubsystem();
    final Subsystem shared = installSubsystem(root, "shared", new SubsystemArchiveBuilder().symbolicName("shared").type(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString() + ';' + SubsystemConstants.PROVISION_POLICY_DIRECTIVE + ":=" + SubsystemConstants.PROVISION_POLICY_ACCEPT_DEPENDENCIES).importPackage("org.osgi.framework").build(), false);
    uninstallableSubsystems.add(shared);
    shared.start();
    stoppableSubsystems.add(shared);
    @SuppressWarnings("unchecked") Callable<Subsystem>[] installCallables = new Callable[] { new Callable<Subsystem>() {

        @Override
        public Subsystem call() throws Exception {
            Subsystem result = installSubsystem(shared, "client", new SubsystemArchiveBuilder().symbolicName("client").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION).bundle("client", new BundleArchiveBuilder().symbolicName("client").importPackage("org.apache.aries.subsystem.itests.defect").requireCapability("osgi.service;filter:=\"(objectClass=" + TestService.class.getName() + ")\";effective:=active").build()).build(), false);
            uninstallableSubsystems.add(result);
            return result;
        }
    }, new Callable<Subsystem>() {

        @Override
        public Subsystem call() throws Exception {
            Subsystem result = installSubsystem(shared, "impl", new SubsystemArchiveBuilder().symbolicName("impl").type(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE).content("impl;version=\"[0,0]\"").provideCapability("osgi.service;objectClass:List<String>=\"" + TestService.class.getName() + "\"").importPackage("org.osgi.framework").requireBundle("api").bundle("impl", new BundleArchiveBuilder().symbolicName("impl").provideCapability("osgi.service;objectClass:List<String>=\"" + TestService.class.getName() + "\"").importPackage("org.osgi.framework").requireBundle("api").clazz(TestServiceImpl.class).activator(TestServiceImplActivator.class).build()).build(), false);
            uninstallableSubsystems.add(result);
            return result;
        }
    }, new Callable<Subsystem>() {

        @Override
        public Subsystem call() throws Exception {
            Subsystem result = installSubsystem(shared, "api", new SubsystemArchiveBuilder().symbolicName("api").type(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE).content("api;version=\"[0,0]\"").exportPackage("org.apache.aries.subsystem.itests.defect").provideCapability("osgi.wiring.bundle;osgi.wiring.bundle=api;bundle-version=0").bundle("api", new BundleArchiveBuilder().symbolicName("api").exportPackage("org.apache.aries.subsystem.itests.defect").clazz(TestService.class).build()).build(), false);
            uninstallableSubsystems.add(result);
            return result;
        }
    } };
    ExecutorService executor = Executors.newFixedThreadPool(3);
    List<Future<Subsystem>> installFutures = executor.invokeAll(Arrays.asList(installCallables));
    final Subsystem a1 = installFutures.get(0).get();
    final Subsystem c1 = installFutures.get(1).get();
    final Subsystem c2 = installFutures.get(2).get();
    @SuppressWarnings("unchecked") Callable<Void>[] startCallables = new Callable[] { new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            a1.start();
            stoppableSubsystems.add(a1);
            assertEvent(a1, State.INSTALLED, subsystemEvents.poll(a1.getSubsystemId(), 5000));
            assertEvent(a1, State.RESOLVING, subsystemEvents.poll(a1.getSubsystemId(), 5000));
            assertEvent(a1, State.RESOLVED, subsystemEvents.poll(a1.getSubsystemId(), 5000));
            assertEvent(a1, State.STARTING, subsystemEvents.poll(a1.getSubsystemId(), 5000));
            assertEvent(a1, State.ACTIVE, subsystemEvents.poll(a1.getSubsystemId(), 5000));
            return null;
        }
    }, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            c1.start();
            stoppableSubsystems.add(c1);
            assertEvent(c1, State.INSTALLED, subsystemEvents.poll(c1.getSubsystemId(), 5000));
            assertEvent(c1, State.RESOLVING, subsystemEvents.poll(c1.getSubsystemId(), 5000));
            assertEvent(c1, State.RESOLVED, subsystemEvents.poll(c1.getSubsystemId(), 5000));
            assertEvent(c1, State.STARTING, subsystemEvents.poll(c1.getSubsystemId(), 5000));
            assertEvent(c1, State.ACTIVE, subsystemEvents.poll(c1.getSubsystemId(), 5000));
            return null;
        }
    }, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            c2.start();
            stoppableSubsystems.add(c2);
            assertEvent(c2, State.INSTALLED, subsystemEvents.poll(c2.getSubsystemId(), 5000));
            assertEvent(c2, State.RESOLVING, subsystemEvents.poll(c2.getSubsystemId(), 5000));
            assertEvent(c2, State.RESOLVED, subsystemEvents.poll(c2.getSubsystemId(), 5000));
            assertEvent(c2, State.STARTING, subsystemEvents.poll(c2.getSubsystemId(), 5000));
            assertEvent(c2, State.ACTIVE, subsystemEvents.poll(c2.getSubsystemId(), 5000));
            return null;
        }
    } };
    List<Future<Void>> startFutures = executor.invokeAll(Arrays.asList(startCallables));
    startFutures.get(0).get();
    startFutures.get(1).get();
    startFutures.get(2).get();
}
Also used : BundleArchiveBuilder(org.apache.aries.subsystem.itests.util.BundleArchiveBuilder) Callable(java.util.concurrent.Callable) SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest) Test(org.junit.Test)

Example 40 with Subsystem

use of org.osgi.service.subsystem.Subsystem in project aries by apache.

the class Aries1419Test method testProvideCapability.

@Test
public void testProvideCapability() throws Exception {
    Bundle bundleB = installBundleFromFile(BUNDLE_B);
    try {
        Subsystem applicationB = installSubsystemFromFile(APPLICATION_B);
        uninstallSubsystemSilently(applicationB);
    } catch (SubsystemException e) {
        e.printStackTrace();
        fail("Subsystem should have installed");
    } finally {
        uninstallSilently(bundleB);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) Test(org.junit.Test) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest)

Aggregations

Subsystem (org.osgi.service.subsystem.Subsystem)187 Test (org.junit.Test)151 SubsystemTest (org.apache.aries.subsystem.itests.SubsystemTest)78 AriesSubsystem (org.apache.aries.subsystem.AriesSubsystem)52 SubsystemException (org.osgi.service.subsystem.SubsystemException)50 Bundle (org.osgi.framework.Bundle)48 SubsystemArchiveBuilder (org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder)31 BundleArchiveBuilder (org.apache.aries.subsystem.itests.util.BundleArchiveBuilder)22 BasicSubsystem (org.apache.aries.subsystem.core.internal.BasicSubsystem)19 IOException (java.io.IOException)11 Hashtable (java.util.Hashtable)8 BundleContext (org.osgi.framework.BundleContext)7 File (java.io.File)6 ArrayList (java.util.ArrayList)6 TestCapability (org.apache.aries.subsystem.itests.util.TestCapability)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Callable (java.util.concurrent.Callable)5 BundleException (org.osgi.framework.BundleException)5 FileInputStream (java.io.FileInputStream)4 Future (java.util.concurrent.Future)4