Search in sources :

Example 26 with DeploymentPackageBuilder

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

the class UninstallDeploymentPackageTest method testUninstallBundleWithOtherArtifactsOk.

/**
 * Tests that uninstalling a DP with a bundle along with other (non-bundle) artifacts succeeds.
 */
@Test
public void testUninstallBundleWithOtherArtifactsOk() throws Exception {
    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"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle3")));
    DeploymentPackage dp = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp);
    awaitRefreshPackagesEvent();
    // Though the commit failed; the package should be installed...
    assertBundleExists(getSymbolicName("rp1"), "1.0.0");
    assertBundleExists(getSymbolicName("bundle3"), "1.0.0");
    assertEquals("Expected a single deployment package?!", 1, countDeploymentPackages());
    // Should succeed...
    dp.uninstall();
    assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
    assertBundleNotExists(getSymbolicName("rp1"), "1.0.0");
    assertBundleNotExists(getSymbolicName("bundle3"), "1.0.0");
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) Test(org.junit.Test)

Example 27 with DeploymentPackageBuilder

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

the class UninstallDeploymentPackageTest method testUninstallDeploymentPackageWithExceptionThrownInStopCauseNoRollbackOk.

/**
 * Tests that if an exception is thrown during the uninstall of a bundle, the installation/update continues and succeeds.
 */
@Test
public void testUninstallDeploymentPackageWithExceptionThrownInStopCauseNoRollbackOk() throws Exception {
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle3")));
    DeploymentPackage dp = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp);
    awaitRefreshPackagesEvent();
    assertBundleExists(getSymbolicName("bundle3"), "1.0.0");
    System.setProperty("bundle3", "stop");
    // should succeed.
    dp.uninstall();
    // FELIX-4484: only after a successful uninstall, the DP should be marked as stale...
    assertTrue(dp.isStale());
    awaitRefreshPackagesEvent();
    assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
    assertTrue("Expected no bundles to remain?!", getCurrentBundles().isEmpty());
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) Test(org.junit.Test)

Example 28 with DeploymentPackageBuilder

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

the class UninstallDeploymentPackageTest method testUninstallDeploymentPackageWithExceptionThrowingInDropAllResourcesCausesRollbackOk.

/**
 * Tests that if an exception is thrown during the dropping of a resource, the installation is rolled back.
 */
@Test
public void testUninstallDeploymentPackageWithExceptionThrowingInDropAllResourcesCausesRollbackOk() 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")));
    DeploymentPackage dp = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp);
    awaitRefreshPackagesEvent();
    assertTrue("Two bundles should be started!", getCurrentBundles().size() == 2);
    assertEquals("Expected no deployment package?!", 1, countDeploymentPackages());
    System.setProperty("rp1", "dropAllResources");
    try {
        dp.uninstall();
        fail("Expected uninstall to fail and rollback!");
    } catch (DeploymentException exception) {
        // Ok; expected
        assertDeploymentException(CODE_OTHER_ERROR, exception);
    }
    // FELIX-4484: only after a successful uninstall, the DP should be marked as stale...
    assertFalse(dp.isStale());
    assertTrue("Two bundles should be started!", getCurrentBundles().size() == 2);
    assertEquals("Expected no deployment package?!", 1, countDeploymentPackages());
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Test(org.junit.Test)

Example 29 with DeploymentPackageBuilder

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

the class UninstallDeploymentPackageTest method testUninstallDeploymentPackageWithMissingResourceProcessorCausesRollback.

/**
 * Tests that if a resource processor is missing (uninstalled) during the uninstallation of a deployment package, this is regarded an error and a rollback is performed.
 */
@Test
public void testUninstallDeploymentPackageWithMissingResourceProcessorCausesRollback() 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")));
    DeploymentPackage dp = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp);
    awaitRefreshPackagesEvent();
    assertTrue("Two bundles should be started!", getCurrentBundles().size() == 2);
    Bundle rpBundle = dp.getBundle(getSymbolicName("rp1"));
    rpBundle.uninstall();
    assertTrue("One bundle should be started!", getCurrentBundles().size() == 1);
    assertEquals("Expected no deployment package?!", 1, countDeploymentPackages());
    try {
        dp.uninstall();
        fail("Expected uninstall to fail and rollback!");
    } catch (DeploymentException exception) {
        // Ok; expected
        assertDeploymentException(CODE_PROCESSOR_NOT_FOUND, exception);
    }
    assertTrue("One bundle should be started!", getCurrentBundles().size() == 1);
    assertEquals("Expected one deployment package?!", 1, countDeploymentPackages());
}
Also used : Bundle(org.osgi.framework.Bundle) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Test(org.junit.Test)

Example 30 with DeploymentPackageBuilder

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

the class UninstallDeploymentPackageTest method testUninstallDeploymentPackageWithExceptionThrowingInCommitCausesNoRollbackOk.

/**
 * Tests that if an exception is thrown during the commit-phase, the installation is continued normally.
 */
@Test
public void testUninstallDeploymentPackageWithExceptionThrowingInCommitCausesNoRollbackOk() 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")));
    DeploymentPackage dp = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp);
    awaitRefreshPackagesEvent();
    assertTrue("Two bundles should be started!", getCurrentBundles().size() == 2);
    assertEquals("Expected no deployment package?!", 1, countDeploymentPackages());
    System.setProperty("rp1", "commit");
    dp.uninstall();
    assertTrue("No bundles should be started! " + getCurrentBundles(), getCurrentBundles().isEmpty());
    assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) 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