Search in sources :

Example 36 with DeploymentPackageBuilder

use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.

the class DeploymentAdminEventTest method testSuccessfulUninstallationCausesCompletionEventOk.

/**
 * FELIX-4466 - test that an event is fired when a DP is uninstalled.
 */
@Test
public void testSuccessfulUninstallationCausesCompletionEventOk() throws Exception {
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl1", "bundleimpl1", "1.0.0")));
    final AtomicReference<Event> completionEventRef = new AtomicReference<Event>();
    final AtomicReference<Event> uninstallEventRef = new AtomicReference<Event>();
    final CountDownLatch cdl = new CountDownLatch(2);
    EventHandler eventHandler = new EventHandler() {

        @Override
        public void handleEvent(Event event) {
            if (Constants.EVENTTOPIC_COMPLETE.equals(event.getTopic())) {
                assertTrue("Multiple events received?!", completionEventRef.compareAndSet(null, event));
                cdl.countDown();
            } else if (Constants.EVENTTOPIC_UNINSTALL.equals(event.getTopic())) {
                assertTrue("Multiple events received?!", uninstallEventRef.compareAndSet(null, event));
                cdl.countDown();
            }
        }
    };
    DeploymentPackage dp = installDeploymentPackage(dpBuilder);
    assertNotNull(dp);
    awaitRefreshPackagesEvent();
    Dictionary props = new Properties();
    props.put(EventConstants.EVENT_TOPIC, new String[] { Constants.EVENTTOPIC_COMPLETE, Constants.EVENTTOPIC_UNINSTALL });
    ServiceRegistration sreg = m_context.registerService(EventHandler.class, eventHandler, props);
    try {
        dp.uninstall();
        assertTrue("Not all events were received in time?!", cdl.await(5, TimeUnit.SECONDS));
        Event event;
        // Verify we've got the expected events...
        event = uninstallEventRef.get();
        assertNotNull("No uninstall event received?!", event);
        event = completionEventRef.get();
        assertNotNull("No completion event received?!", event);
        assertTrue("Completion property set to false?!", Boolean.TRUE.equals(event.getProperty(Constants.EVENTPROPERTY_SUCCESSFUL)));
    } finally {
        sreg.unregister();
    }
}
Also used : Dictionary(java.util.Dictionary) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) Event(org.osgi.service.event.Event) EventHandler(org.osgi.service.event.EventHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Properties(java.util.Properties) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Example 37 with DeploymentPackageBuilder

use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.

the class DeploymentAdminEventTest method testFailedUninstallationCausesCompletionEventOk.

/**
 * FELIX-4466 - test that an event is fired when a DP is uninstalled, but fails.
 */
@Test
public void testFailedUninstallationCausesCompletionEventOk() throws Exception {
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1"))).add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
    final AtomicReference<Event> completionEventRef = new AtomicReference<Event>();
    final AtomicReference<Event> uninstallEventRef = new AtomicReference<Event>();
    final CountDownLatch cdl = new CountDownLatch(2);
    EventHandler eventHandler = new EventHandler() {

        @Override
        public void handleEvent(Event event) {
            if (Constants.EVENTTOPIC_COMPLETE.equals(event.getTopic())) {
                assertTrue("Multiple events received?!", completionEventRef.compareAndSet(null, event));
                cdl.countDown();
            } else if (Constants.EVENTTOPIC_UNINSTALL.equals(event.getTopic())) {
                assertTrue("Multiple events received?!", uninstallEventRef.compareAndSet(null, event));
                cdl.countDown();
            }
        }
    };
    DeploymentPackage dp = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp);
    awaitRefreshPackagesEvent();
    // Should cause the uninstall of the DP to fail...
    dp.getBundle(getSymbolicName("rp1")).uninstall();
    Dictionary props = new Properties();
    props.put(EventConstants.EVENT_TOPIC, new String[] { Constants.EVENTTOPIC_COMPLETE, Constants.EVENTTOPIC_UNINSTALL });
    ServiceRegistration sreg = m_context.registerService(EventHandler.class, eventHandler, props);
    try {
        dp.uninstall();
        fail("DeploymentException expected!");
    } catch (DeploymentException e) {
        // Ok, expected...
        assertTrue("Not all events were received in time?!", cdl.await(5, TimeUnit.SECONDS));
        Event event;
        // Verify we've got the expected events...
        event = uninstallEventRef.get();
        assertNotNull("No uninstall event received?!", event);
        event = completionEventRef.get();
        assertNotNull("No completion event received?!", event);
        assertTrue("Completion property set to true?!", Boolean.FALSE.equals(event.getProperty(Constants.EVENTPROPERTY_SUCCESSFUL)));
    } finally {
        sreg.unregister();
    }
}
Also used : Dictionary(java.util.Dictionary) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) Event(org.osgi.service.event.Event) EventHandler(org.osgi.service.event.EventHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) CountDownLatch(java.util.concurrent.CountDownLatch) Properties(java.util.Properties) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Example 38 with DeploymentPackageBuilder

use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.

the class DeploymentAdminTest method testUpdateConfigurationOk.

/**
 * Tests that we can update the configuration of {@link DeploymentAdmin} at runtime. Based on the test case for FELIX-4184, see
 * {@link org.apache.felix.deploymentadmin.itest.InstallFixPackageTest#testInstallAndUpdateImplementationBundleWithSeparateAPIBundle_FELIX4184()}
 */
@Test
public void testUpdateConfigurationOk() throws Exception {
    System.setProperty("org.apache.felix.deploymentadmin.stopUnaffectedBundles", "false");
    System.setProperty("org.apache.felix.deploymentadmin.allowForeignCustomizers", "false");
    // This test case will only work if stopUnaffectedBundle is set to 'false'...
    try {
        // first, install a deployment package with implementation and api bundles in version 1.0.0
        DeploymentPackageBuilder dpBuilder = createDeploymentPackageBuilder("a", "1.0.0");
        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl1", "bundleimpl1", "1.0.0")));
        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0")));
        DeploymentPackage dp1 = installDeploymentPackage(dpBuilder);
        assertNotNull("No deployment package returned?!", dp1);
        assertEquals("Expected a single deployment package?!", 1, countDeploymentPackages());
        // then, install a fix package with implementation and api bundles in version 2.0.0
        dpBuilder = createDeploymentPackageBuilder("a", "2.0.0").setFixPackage("[1.0.0,2.0.0]");
        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl2", "bundleimpl2", "2.0.0")));
        dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi2", "bundleapi2", "2.0.0")));
        DeploymentPackage dp2 = installDeploymentPackage(dpBuilder);
        assertNotNull("No deployment package returned?!", dp2);
        awaitRefreshPackagesEvent();
        assertBundleExists(getSymbolicName("bundleimpl"), "2.0.0");
        assertBundleExists(getSymbolicName("bundleapi"), "2.0.0");
        assertBundleNotExists(getSymbolicName("bundleimpl"), "1.0.0");
        assertBundleNotExists(getSymbolicName("bundleapi"), "1.0.0");
    } finally {
        System.clearProperty("org.apache.felix.deploymentadmin.stopUnaffectedBundles");
        System.clearProperty("org.apache.felix.deploymentadmin.allowForeignCustomizers");
    }
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) Test(org.junit.Test)

Example 39 with DeploymentPackageBuilder

use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.

the class DeploymentAdminTest method testBundleSymbolicNameMustMatchManifestEntry.

@Test
public void testBundleSymbolicNameMustMatchManifestEntry() throws Exception {
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")).setFilter(new JarManifestManipulatingFilter("Bundle-SymbolicName", "foo")));
    try {
        installDeploymentPackage(dpBuilder);
        fail("Succeeded into installing a bundle with a fake symbolic name?!");
    } catch (DeploymentException exception) {
        // Ok; expected...
        assertDeploymentException(CODE_BUNDLE_NAME_ERROR, exception);
    }
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) JarManifestManipulatingFilter(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder.JarManifestManipulatingFilter) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Test(org.junit.Test)

Example 40 with DeploymentPackageBuilder

use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.

the class DeploymentAdminTest method testManifestEntryMustMatchBundleSymbolicName.

@Test
public void testManifestEntryMustMatchBundleSymbolicName() throws Exception {
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setSymbolicName("foo").setUrl(getTestBundleURL("bundle2")));
    try {
        installDeploymentPackage(dpBuilder);
        fail("Succeeded into installing a bundle with a fake symbolic name?!");
    } catch (DeploymentException exception) {
        // Ok; expected...
        assertDeploymentException(CODE_BUNDLE_NAME_ERROR, exception);
    }
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Test(org.junit.Test)

Aggregations

DeploymentPackageBuilder (org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder)67 Test (org.junit.Test)67 DeploymentPackage (org.osgi.service.deploymentadmin.DeploymentPackage)46 DeploymentException (org.osgi.service.deploymentadmin.DeploymentException)28 Bundle (org.osgi.framework.Bundle)15 JarInputStream (java.util.jar.JarInputStream)6 JarManifestManipulatingFilter (org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder.JarManifestManipulatingFilter)6 Manifest (java.util.jar.Manifest)5 File (java.io.File)4 Dictionary (java.util.Dictionary)4 Properties (java.util.Properties)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 ServiceRegistration (org.osgi.framework.ServiceRegistration)4 Event (org.osgi.service.event.Event)4 EventHandler (org.osgi.service.event.EventHandler)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URL (java.net.URL)2 JarEntry (java.util.jar.JarEntry)2 SignerInfo (org.apache.felix.deploymentadmin.itest.util.CertificateUtil.SignerInfo)2