Search in sources :

Example 31 with Subsystem

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

the class Aries1429Test method testMissingParentChildEdgeNotTolerated.

@Test
public void testMissingParentChildEdgeNotTolerated() throws Exception {
    Subsystem applicationA = installSubsystemFromFile(APPLICATION_A);
    try {
        removeConnectionWithParent(applicationA);
        try {
            ((AriesSubsystem) applicationA).addRequirements(Collections.singletonList((Requirement) new TestRequirement.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).attribute(PackageNamespace.PACKAGE_NAMESPACE, "org.osgi.framework").build()));
            fail("No exception received");
        } catch (SubsystemException e) {
            Throwable cause = e.getCause();
            assertNotNull("Wrong cause", cause);
            assertEquals("Wrong cause", IllegalStateException.class, cause.getClass());
        }
    } finally {
        uninstallSubsystemSilently(applicationA);
    }
}
Also used : Requirement(org.osgi.resource.Requirement) TestRequirement(org.apache.aries.subsystem.itests.util.TestRequirement) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest) Test(org.junit.Test)

Example 32 with Subsystem

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

the class Aries1429Test method testMissingParentChildEdgeTolerated.

@Test
public void testMissingParentChildEdgeTolerated() throws Exception {
    final AtomicBoolean weavingHookCalled = new AtomicBoolean();
    final AtomicReference<FrameworkEvent> frameworkEvent = new AtomicReference<FrameworkEvent>();
    bundleContext.registerService(WeavingHook.class, new WeavingHook() {

        @Override
        public void weave(WovenClass wovenClass) {
            Bundle bundle = wovenClass.getBundleWiring().getBundle();
            if (BUNDLE_A.equals(bundle.getSymbolicName())) {
                wovenClass.getDynamicImports().add("com.acme.tnt");
                weavingHookCalled.set(true);
            }
        }
    }, null);
    Subsystem applicationA = installSubsystemFromFile(APPLICATION_A);
    try {
        removeConnectionWithParent(applicationA);
        BundleContext context = applicationA.getBundleContext();
        Bundle bundleA = context.installBundle(BUNDLE_A, TinyBundles.bundle().add(getClass().getClassLoader().loadClass("a.A"), InnerClassStrategy.NONE).set(Constants.BUNDLE_SYMBOLICNAME, BUNDLE_A).build(TinyBundles.withBnd()));
        bundleContext.addFrameworkListener(new FrameworkListener() {

            @Override
            public void frameworkEvent(FrameworkEvent event) {
                if (FrameworkEvent.ERROR == event.getType() && getSubsystemCoreBundle().equals(event.getBundle())) {
                    frameworkEvent.set(event);
                    if (event.getThrowable() != null) {
                        event.getThrowable().printStackTrace();
                    }
                }
            }
        });
        bundleA.loadClass("a.A");
        assertTrue("Weaving hook not called", weavingHookCalled.get());
        Thread.sleep(1000);
        assertNull("An exception was thrown", frameworkEvent.get());
    } finally {
        uninstallSubsystemSilently(applicationA);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FrameworkEvent(org.osgi.framework.FrameworkEvent) Bundle(org.osgi.framework.Bundle) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) WovenClass(org.osgi.framework.hooks.weaving.WovenClass) AtomicReference(java.util.concurrent.atomic.AtomicReference) FrameworkListener(org.osgi.framework.FrameworkListener) WeavingHook(org.osgi.framework.hooks.weaving.WeavingHook) BundleContext(org.osgi.framework.BundleContext) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest) Test(org.junit.Test)

Example 33 with Subsystem

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

the class Aries1399Test method testBundleEventOrder.

@Test
public void testBundleEventOrder() throws Exception {
    Subsystem root = getRootSubsystem();
    BundleContext context = root.getBundleContext();
    final List<BundleEvent> events = Collections.synchronizedList(new ArrayList<BundleEvent>());
    context.addBundleListener(new SynchronousBundleListener() {

        @Override
        public void bundleChanged(BundleEvent event) {
            events.add(event);
        }
    });
    Bundle bundle = context.installBundle("bundle", TinyBundles.bundle().set(Constants.BUNDLE_SYMBOLICNAME, "bundle").build());
    try {
        bundle.start();
        // INSTALLED, RESOLVED, STARTING, STARTED
        assertEquals(4, events.size());
        assertEquals(BundleEvent.INSTALLED, events.get(0).getType());
        assertEquals(BundleEvent.RESOLVED, events.get(1).getType());
        assertEquals(BundleEvent.STARTING, events.get(2).getType());
        assertEquals(BundleEvent.STARTED, events.get(3).getType());
    } finally {
        uninstallSilently(bundle);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Subsystem(org.osgi.service.subsystem.Subsystem) BundleEvent(org.osgi.framework.BundleEvent) SynchronousBundleListener(org.osgi.framework.SynchronousBundleListener) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest)

Example 34 with Subsystem

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

the class Aries1408Test method testRequirementFromRemoteRepositoryConvertsToRequireCapability.

@Test
public void testRequirementFromRemoteRepositoryConvertsToRequireCapability() throws Exception {
    Bundle bundleB = installBundleFromFile(BUNDLE_B);
    try {
        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) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest) Test(org.junit.Test)

Example 35 with Subsystem

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

the class Aries1416Test method testSharedContentBundlePreferredProvider.

@Test
public void testSharedContentBundlePreferredProvider() throws Exception {
    // Install feature A containing bundle B and application A both in the
    // archive and as content into the root subsystem region. Bundle B 
    // provides capability b. Application A contains bundle A requiring 
    // capability b both in the archive and as content. Preferred provider 
    // bundle B is also included in the archive but not as content.
    Subsystem featureA = installSubsystemFromFile(FEATURE_A);
    try {
        // Install feature B having the same characteristics as feature A
        // described above into the root subsystem region. Bundle B will 
        // become shared content of features A and B. Shared content bundle
        // B from the system repository should be used as the preferred
        // provider. Bundle B from the local repository should not be
        // provisioned.
        Subsystem featureB = installSubsystemFromFile(FEATURE_B);
        uninstallSubsystemSilently(featureB);
    } catch (SubsystemException e) {
        e.printStackTrace();
        fail("Subsystem should have installed");
    } finally {
        uninstallSubsystemSilently(featureA);
    }
}
Also used : 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