Search in sources :

Example 1 with SubsystemArchiveBuilder

use of org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder in project aries by apache.

the class Aries1608Test method test.

private void test(AriesProvisionDependenciesDirective provisionDependencies) throws Exception {
    boolean flag = AriesProvisionDependenciesDirective.INSTALL.equals(provisionDependencies);
    Subsystem root = getRootSubsystem();
    try {
        Subsystem subsystem = installSubsystem(root, "subsystem", new SubsystemArchiveBuilder().symbolicName("subsystem").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + provisionDependencies.toString()).content("org.apache.aries.subsystem.itests.aries1608provider,org.apache.aries.subsystem.itests.aries1608required").bundle("aries1608required", getClass().getClassLoader().getResourceAsStream("aries1608/aries1608required.jar")).build(), flag);
        try {
            startSubsystem(subsystem, flag);
            stopSubsystem(subsystem);
        } catch (SubsystemException e) {
            e.printStackTrace();
            fail("Subsystem should have started");
        } finally {
            uninstallSubsystemSilently(subsystem);
        }
    } catch (SubsystemException e) {
        e.printStackTrace();
        fail("Subsystem should have installed");
    }
}
Also used : SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException)

Example 2 with SubsystemArchiveBuilder

use of org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder in project aries by apache.

the class Aries1538Test method testEffectiveActive.

private void testEffectiveActive(AriesProvisionDependenciesDirective provisionDependencies) throws Exception {
    boolean flag = AriesProvisionDependenciesDirective.INSTALL.equals(provisionDependencies);
    BundleArchiveBuilder bab = new BundleArchiveBuilder();
    bab.symbolicName("bundle");
    bab.requireCapability("osgi.service;filter:=\"(&(objectClass=java.lang.Object)(foo=bar))\";effective:=active");
    bab.exportPackage("foo");
    Subsystem root = getRootSubsystem();
    Bundle a = root.getBundleContext().installBundle("a", bab.build());
    uninstallableBundles.add(a);
    startBundle(a);
    try {
        Subsystem subsystem = installSubsystem(root, "subsystem", new SubsystemArchiveBuilder().symbolicName("subsystem").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + provisionDependencies.toString()).bundle("b", new BundleArchiveBuilder().symbolicName("b").importPackage("foo").build()).build(), flag);
        uninstallableSubsystems.add(subsystem);
        startSubsystem(subsystem, flag);
        stoppableSubsystems.add(subsystem);
    } catch (SubsystemException e) {
        e.printStackTrace();
        fail("Subsystem should have installed and started");
    }
}
Also used : SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) BundleArchiveBuilder(org.apache.aries.subsystem.itests.util.BundleArchiveBuilder) Bundle(org.osgi.framework.Bundle) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException)

Example 3 with SubsystemArchiveBuilder

use of org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder in project aries by apache.

the class Aries1442Test method createFeature.

private Subsystem createFeature() throws Exception {
    Subsystem root = getRootSubsystem();
    Subsystem feature = installSubsystem(root, "feature", new SubsystemArchiveBuilder().symbolicName("feature").type(SubsystemConstants.SUBSYSTEM_TYPE_FEATURE).bundle("a", new BundleArchiveBuilder().symbolicName("a").exportPackage("a").build()).build(), true);
    uninstallableSubsystems.add(feature);
    startSubsystem(feature, true);
    stoppableSubsystems.add(feature);
    return feature;
}
Also used : SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) BundleArchiveBuilder(org.apache.aries.subsystem.itests.util.BundleArchiveBuilder) Subsystem(org.osgi.service.subsystem.Subsystem)

Example 4 with SubsystemArchiveBuilder

use of org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder in project aries by apache.

the class Aries1445Test method buildSubsystem.

private InputStream buildSubsystem(Subsystem parent, String symbolicName, String type) throws IOException {
    SubsystemArchiveBuilder builder = new SubsystemArchiveBuilder();
    builder.symbolicName(symbolicName);
    builder.type(type);
    if (SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE.equals(type)) {
        builder.importPackage("b.package");
    }
    builder.bundle("a", new BundleArchiveBuilder().symbolicName("a").importPackage("b.package").build());
    return builder.build();
}
Also used : SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) BundleArchiveBuilder(org.apache.aries.subsystem.itests.util.BundleArchiveBuilder)

Example 5 with SubsystemArchiveBuilder

use of org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder in project aries by apache.

the class Aries1383Test method testComApiComImplComClient.

@Test
public void testComApiComImplComClient() 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_COMPOSITE).content("client;version=\"[0,0]\"").importPackage("org.osgi.framework").requireCapability("osgi.service;filter:=\"(objectClass=" + TestService.class.getName() + ")\";effective:=active").importService(TestService.class.getName()).requireBundle("api,impl").bundle("client", new BundleArchiveBuilder().symbolicName("client").importPackage("org.osgi.framework").requireCapability("osgi.service;filter:=\"(objectClass=" + TestService.class.getName() + ")\";effective:=active").requireBundle("api,impl").activator(TestServiceClientActivator.class).build()).build(), false);
            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() + "\"").exportService(TestService.class.getName()).importPackage("org.osgi.framework").requireBundle("api").provideCapability("osgi.wiring.bundle;osgi.wiring.bundle=impl;bundle-version=0").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);
            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);
            return result;
        }
    } };
    ExecutorService executor = Executors.newFixedThreadPool(3);
    List<Future<Subsystem>> installFutures = executor.invokeAll(Arrays.asList(installCallables));
    final Subsystem client = installFutures.get(0).get();
    final Subsystem impl = installFutures.get(1).get();
    final Subsystem api = installFutures.get(2).get();
    @SuppressWarnings("unchecked") Callable<Void>[] startCallables = new Callable[] { new Callable<Void>() {

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

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

        @Override
        public Void call() throws Exception {
            api.start();
            assertEvent(api, State.INSTALLED, subsystemEvents.poll(api.getSubsystemId(), 5000));
            assertEvent(api, State.RESOLVING, subsystemEvents.poll(api.getSubsystemId(), 5000));
            assertEvent(api, State.RESOLVED, subsystemEvents.poll(api.getSubsystemId(), 5000));
            assertEvent(api, State.STARTING, subsystemEvents.poll(api.getSubsystemId(), 5000));
            assertEvent(api, State.ACTIVE, subsystemEvents.poll(api.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)

Aggregations

SubsystemArchiveBuilder (org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder)31 Subsystem (org.osgi.service.subsystem.Subsystem)30 BundleArchiveBuilder (org.apache.aries.subsystem.itests.util.BundleArchiveBuilder)22 AriesSubsystem (org.apache.aries.subsystem.AriesSubsystem)21 SubsystemTest (org.apache.aries.subsystem.itests.SubsystemTest)21 Test (org.junit.Test)21 SubsystemException (org.osgi.service.subsystem.SubsystemException)16 Bundle (org.osgi.framework.Bundle)5 Callable (java.util.concurrent.Callable)3 ExecutorService (java.util.concurrent.ExecutorService)3 Future (java.util.concurrent.Future)3 TestCapability (org.apache.aries.subsystem.itests.util.TestCapability)3 TestRepository (org.apache.aries.subsystem.itests.util.TestRepository)3 Repository (org.osgi.service.repository.Repository)3 TestRepositoryContent (org.apache.aries.subsystem.itests.util.TestRepositoryContent)2 TestRequirement (org.apache.aries.subsystem.itests.util.TestRequirement)1