Search in sources :

Example 21 with BundleArchiveBuilder

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

the class Aries1538Test method testSubstitutableExport.

private void testSubstitutableExport(AriesProvisionDependenciesDirective provisionDependencies) throws Exception {
    boolean flag = AriesProvisionDependenciesDirective.INSTALL.equals(provisionDependencies);
    BundleArchiveBuilder hostBuilder = new BundleArchiveBuilder();
    hostBuilder.symbolicName("host");
    BundleArchiveBuilder fragmentBuilder = new BundleArchiveBuilder();
    fragmentBuilder.symbolicName("fragment");
    fragmentBuilder.exportPackage("foo");
    fragmentBuilder.importPackage("foo");
    fragmentBuilder.header("Fragment-Host", "host");
    Subsystem root = getRootSubsystem();
    Bundle host = root.getBundleContext().installBundle("host", hostBuilder.build());
    uninstallableBundles.add(host);
    Bundle fragment = root.getBundleContext().installBundle("fragment", fragmentBuilder.build());
    uninstallableBundles.add(fragment);
    startBundle(host);
    try {
        Subsystem subsystem = installSubsystem(root, "subsystem", new SubsystemArchiveBuilder().symbolicName("subsystem").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + provisionDependencies.toString()).bundle("a", new BundleArchiveBuilder().symbolicName("a").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 22 with BundleArchiveBuilder

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

the class Aries1441Test method test.

private void test(String type) throws Exception {
    SubsystemArchiveBuilder builder = new SubsystemArchiveBuilder().symbolicName("subsystem").type(type).content("a;version=\"[0,0]\"").bundle("a", new BundleArchiveBuilder().symbolicName("a").importPackage("org.osgi.framework").importPackage("b").build()).bundle("b", new BundleArchiveBuilder().symbolicName("b").exportPackage("b").build());
    if (SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE.equals(type)) {
        builder.importPackage("org.osgi.framework,b");
    }
    Subsystem root = getRootSubsystem();
    Subsystem subsystem = installSubsystem(root, "subsystem", builder.build());
    uninstallableSubsystems.add(subsystem);
    startSubsystem(subsystem);
    stoppableSubsystems.add(subsystem);
    Bundle core = getSubsystemCoreBundle();
    core.stop();
    stoppableSubsystems.remove(subsystem);
    uninstallableSubsystems.remove(subsystem);
    assertBundleState(getSystemBundle(), org.osgi.framework.Bundle.ACTIVE);
    core.start();
    root = getRootSubsystem();
    subsystem = getChild(root, "subsystem", null, type);
    stopSubsystem(subsystem);
    assertBundleState(Bundle.RESOLVED, "b", root);
    uninstallSubsystem(subsystem);
    assertNotConstituent(root, "b");
}
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)

Example 23 with BundleArchiveBuilder

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

the class Aries1445Test method test.

private void test(String type1, String type2) throws Exception {
    serviceRegistrations.add(bundleContext.registerService(Repository.class, new TestRepository.Builder().resource(new TestRepositoryContent.Builder().capability(new TestCapability.Builder().namespace(IdentityNamespace.IDENTITY_NAMESPACE).attribute(IdentityNamespace.IDENTITY_NAMESPACE, "b").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion).attribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_BUNDLE)).capability(new TestCapability.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).attribute(PackageNamespace.PACKAGE_NAMESPACE, "b.package").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion)).requirement(new TestRequirement.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).directive(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.wiring.package=c.package)")).requirement(new TestRequirement.Builder().namespace(ServiceNamespace.SERVICE_NAMESPACE).directive(ServiceNamespace.REQUIREMENT_FILTER_DIRECTIVE, "(objectClass=foo.Bar)").directive(ServiceNamespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, ServiceNamespace.EFFECTIVE_ACTIVE)).content(new BundleArchiveBuilder().symbolicName("b").exportPackage("b.package").importPackage("c.package").requireCapability("osgi.service;filter:=\"(objectClass=foo.Bar)\";effective:=active").buildAsBytes()).build()).resource(new TestRepositoryContent.Builder().capability(new TestCapability.Builder().namespace(IdentityNamespace.IDENTITY_NAMESPACE).attribute(IdentityNamespace.IDENTITY_NAMESPACE, "c").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion).attribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_BUNDLE)).capability(new TestCapability.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).attribute(PackageNamespace.PACKAGE_NAMESPACE, "c.package").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion)).content(new BundleArchiveBuilder().symbolicName("c").exportPackage("c.package").buildAsBytes()).build()).resource(new TestRepositoryContent.Builder().capability(new TestCapability.Builder().namespace(IdentityNamespace.IDENTITY_NAMESPACE).attribute(IdentityNamespace.IDENTITY_NAMESPACE, "d").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion).attribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_BUNDLE)).capability(new TestCapability.Builder().namespace(ServiceNamespace.SERVICE_NAMESPACE).attribute(Constants.OBJECTCLASS, "foo.Bar").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion).directive(ServiceNamespace.CAPABILITY_EFFECTIVE_DIRECTIVE, ServiceNamespace.EFFECTIVE_ACTIVE)).content(new BundleArchiveBuilder().symbolicName("d").provideCapability("osgi.service;objectClass=foo.Bar;effective:=active").buildAsBytes()).build()).build(), null));
    Subsystem root = getRootSubsystem();
    Subsystem s1 = installSubsystem(root, "s1", buildSubsystem(root, "s1", type1));
    uninstallableSubsystems.add(s1);
    startSubsystem(s1);
    stoppableSubsystems.add(s1);
    Subsystem s2 = installSubsystem(root, "s2", buildSubsystem(root, "s2", type2));
    uninstallableSubsystems.add(s2);
    stopSubsystem(s1);
    stoppableSubsystems.remove(s1);
    uninstallSubsystem(s1);
    uninstallableSubsystems.remove(s1);
    getSystemBundleAsFrameworkWiring().refreshBundles(null, (FrameworkListener) null);
    try {
        s2.start();
        stoppableSubsystems.add(s2);
    } catch (SubsystemException e) {
        e.printStackTrace();
        fail("Subsystem should have started");
    }
    // Test the effective:=active service capability and requirement. Bundle
    // D should have had a reference count of 2 and not uninstalled as part
    // of S1. Because effective:=active does not effect runtime resolution,
    // we must ensure it is still a constituent of root.
    assertConstituent(root, "d");
}
Also used : TestRepository(org.apache.aries.subsystem.itests.util.TestRepository) Repository(org.osgi.service.repository.Repository) BundleArchiveBuilder(org.apache.aries.subsystem.itests.util.BundleArchiveBuilder) BundleArchiveBuilder(org.apache.aries.subsystem.itests.util.BundleArchiveBuilder) SubsystemArchiveBuilder(org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) TestCapability(org.apache.aries.subsystem.itests.util.TestCapability) TestRepositoryContent(org.apache.aries.subsystem.itests.util.TestRepositoryContent)

Aggregations

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