Search in sources :

Example 31 with DeploymentPackageBuilder

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

the class CustomizerTest method testDropResourceWithExceptionThrowingInDroppedCausesRollbackOk.

/**
 * Tests that if an exception is thrown during the dropping of a resource, the installation is continued and finishes normally.
 */
@Test
public void testDropResourceWithExceptionThrowingInDroppedCausesRollbackOk() throws Exception {
    System.setProperty("rp1", "dropped");
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1"))).add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
    DeploymentPackage dp = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp);
    awaitRefreshPackagesEvent();
    assertTrue("One bundle should be started!", getCurrentBundles().size() == 1);
    assertEquals("Expected no deployment package?!", 1, countDeploymentPackages());
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) Test(org.junit.Test)

Example 32 with DeploymentPackageBuilder

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

the class CustomizerTest method testInstallResourceWithForeignCustomizerFail.

/**
 * Tests that if a resource is installed which mentions a RP that does not belong to the same package, a rollback takes place.
 */
@Test
public void testInstallResourceWithForeignCustomizerFail() throws Exception {
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")));
    installDeploymentPackage(dpBuilder);
    awaitRefreshPackagesEvent();
    assertEquals("Expected no deployment package?!", 1, countDeploymentPackages());
    assertBundleExists(getSymbolicName("rp1"), "1.0.0");
    dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.disableVerification().add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
    try {
        installDeploymentPackage(dpBuilder);
        fail("Succeeded into installing a resource with an non-existing RP?!");
    } catch (DeploymentException exception) {
        // Ok; expected...
        assertDeploymentException(CODE_FOREIGN_CUSTOMIZER, exception);
    }
    assertEquals("Expected no deployment package?!", 1, countDeploymentPackages());
    assertTrue("Expected no additional artifacts to be installed?!", getCurrentBundles().size() == 1);
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Test(org.junit.Test)

Example 33 with DeploymentPackageBuilder

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

the class CustomizerTest method testInstallBundleWithNonProcessedResourcesOk.

/**
 * FELIX-4491 - Only resources with a resource processor defined should be processed.
 */
@Test
public void testInstallBundleWithNonProcessedResourcesOk() throws Exception {
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createResource().setNeedResourceProcessor(false).setUrl(getTestResource("LICENSE"))).add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1"))).add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")));
    DeploymentPackage dp = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp);
    assertEquals("Expected a single deployment package?!", 1, countDeploymentPackages());
    awaitRefreshPackagesEvent();
    assertBundleExists(getSymbolicName("bundle1"), "1.0.0");
    // Check that only the processed resources are dropped...
    dp.uninstall();
    assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
    awaitRefreshPackagesEvent();
    assertBundleNotExists(getSymbolicName("bundle1"), "1.0.0");
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) Test(org.junit.Test)

Example 34 with DeploymentPackageBuilder

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

the class CustomizerTest method testInstallResourceWithExceptionThrowingInProcessCausesRollbackOk.

/**
 * Tests that if an exception is thrown during the processing of a resource, the installation is cancelled and rolled back.
 */
@Test
public void testInstallResourceWithExceptionThrowingInProcessCausesRollbackOk() throws Exception {
    System.setProperty("rp1", "process");
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1"))).add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
    try {
        installDeploymentPackage(dpBuilder);
        fail("Succeeded into installing a failing deployment package?!");
    } catch (DeploymentException exception) {
        // Ok; expected
        assertDeploymentException(DeploymentException.CODE_RESOURCE_SHARING_VIOLATION, exception);
    }
    assertTrue("No bundles should be started!", getCurrentBundles().isEmpty());
    assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Test(org.junit.Test)

Example 35 with DeploymentPackageBuilder

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

the class DeploymentAdminEventTest method testFailedInstallationCausesCompletionEventOk.

/**
 * FELIX-4466 - test that an event is fired when an installation of a DP fails.
 */
@Test
public void testFailedInstallationCausesCompletionEventOk() throws Exception {
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    // incluse two different versions of the same bundle (with the same BSN), this is *not* allowed per the DA spec...
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi2", "bundleapi2", "2.0.0")));
    final AtomicReference<Event> completionEventRef = new AtomicReference<Event>();
    final AtomicReference<Event> installEventRef = new AtomicReference<Event>();
    final CountDownLatch cdl = new CountDownLatch(1);
    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_INSTALL.equals(event.getTopic())) {
                assertTrue("Multiple events received?!", installEventRef.compareAndSet(null, event));
            }
        }
    };
    Dictionary props = new Properties();
    props.put(EventConstants.EVENT_TOPIC, new String[] { Constants.EVENTTOPIC_COMPLETE, Constants.EVENTTOPIC_INSTALL });
    ServiceRegistration sreg = m_context.registerService(EventHandler.class, eventHandler, props);
    try {
        installDeploymentPackage(dpBuilder);
        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 = installEventRef.get();
        // The install event is send *after* the DP have been created, which fails in this test...
        assertNull("No install 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) 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)

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