Search in sources :

Example 1 with DeploymentPackageBuilder

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

the class CustomizerTest method testInstallBundleWithExceptionThrowingInCommitCauseNoRollbackOk.

/**
 * Tests that if an exception is thrown during the commit-phase, the installation proceeds and succeeds.
 */
@Test
public void testInstallBundleWithExceptionThrowingInCommitCauseNoRollbackOk() throws Exception {
    System.setProperty("rp1", "commit");
    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());
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) Test(org.junit.Test)

Example 2 with DeploymentPackageBuilder

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

the class CustomizerTest method testInstallResourceWithNonAvailableCustomizerFail.

/**
 * Tests that if a resource is installed which mentions a RP that does not exist a rollback takes place.
 */
@Test
public void testInstallResourceWithNonAvailableCustomizerFail() throws Exception {
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.disableVerification().add(dpBuilder.createResource().setResourceProcessorPID("my.unknown.rp").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_PROCESSOR_NOT_FOUND, exception);
    }
    assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
    assertTrue("Expected no artifacts to be installed?!", getCurrentBundles().isEmpty());
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Test(org.junit.Test)

Example 3 with DeploymentPackageBuilder

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

the class CustomizerTest method testInstallBundleWithExceptionThrowingInPrepareCausesRollbackOk.

/**
 * Tests that if an exception is thrown during the prepare-phase, the installation is cancelled and rolled back.
 */
@Test
public void testInstallBundleWithExceptionThrowingInPrepareCausesRollbackOk() throws Exception {
    System.setProperty("rp1", "prepare");
    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_COMMIT_ERROR, 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 4 with DeploymentPackageBuilder

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

the class CustomizerTest method testInstallResourceProcessorWithExceptionThrowingInStartCausesRollbackOk.

/**
 * Tests that if an exception is thrown during the commit-phase, the installation proceeds and succeeds.
 */
@Test
public void testInstallResourceProcessorWithExceptionThrowingInStartCausesRollbackOk() throws Exception {
    System.setProperty("rp1", "start");
    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")));
    try {
        installDeploymentPackage(dpBuilder);
        fail("Succeeded into installing a failing RP?!");
    } catch (DeploymentException exception) {
        // Ok; expected...
        assertDeploymentException(CODE_OTHER_ERROR, exception);
    }
    assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
    assertTrue("Expected no artifacts to be installed?!", getCurrentBundles().isEmpty());
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Test(org.junit.Test)

Example 5 with DeploymentPackageBuilder

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

the class DPSignerTest method testSignArtifactsOk.

@Test
public void testSignArtifactsOk() throws Exception {
    URL dpProps = getClass().getResource("/dp.properties");
    assertNotNull(dpProps);
    DeploymentPackageBuilder builder = DeploymentPackageBuilder.create("dpSignerTest1", "1.0.0");
    builder.add(builder.createLocalizationResource().setUrl(dpProps).setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setFilename("dp.properties"));
    SignerInfo signerInfo = CertificateUtil.createSelfSignedCert("CN=testCert", KeyType.RSA);
    DPSigner signer = new DPSigner();
    byte[] rawData;
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        signer.sign(builder, signerInfo.getPrivate(), signerInfo.getCert(), baos);
        rawData = baos.toByteArray();
    }
    try (ByteArrayInputStream bais = new ByteArrayInputStream(rawData);
        JarInputStream jis = new JarInputStream(bais, true)) {
        JarEntry entry;
        while ((entry = jis.getNextJarEntry()) != null) {
            assertNotNull(entry);
            jis.closeEntry();
        }
        assertNotNull(jis.getManifest());
    }
}
Also used : SignerInfo(org.apache.felix.deploymentadmin.itest.util.CertificateUtil.SignerInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) JarInputStream(java.util.jar.JarInputStream) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DPSigner(org.apache.felix.deploymentadmin.itest.util.DPSigner) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JarEntry(java.util.jar.JarEntry) URL(java.net.URL) 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