Search in sources :

Example 51 with DeploymentPackageBuilder

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

the class InstallDeploymentPackageTest method testInstallInvalidDeploymentPackageFail.

/**
 * FELIX-4409/4410/4463 - test the installation of an invalid deployment package.
 */
@Test
public void testInstallInvalidDeploymentPackageFail() 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")));
    try {
        installDeploymentPackage(dpBuilder);
        fail("DeploymentException expected!");
    } catch (DeploymentException e) {
    // Ok; expected...
    }
    // Verify that none of the bundles are installed...
    assertBundleNotExists("testbundles.bundleapi", "1.0.0");
    assertBundleNotExists("testbundles.bundleapi", "2.0.0");
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Test(org.junit.Test)

Example 52 with DeploymentPackageBuilder

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

the class InstallDeploymentPackageTest method testInstallBundlesWithPathsOk.

/**
 * FELIX-1835 - test whether we can install bundles with a non-root path inside the DP.
 */
@Test
public void testInstallBundlesWithPathsOk() 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")).setFilename("bundles/bundleapi1.jar")).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl1", "bundleimpl1", "1.0.0")).setFilename("bundles/bundleimpl1.jar"));
    DeploymentPackage dp = installDeploymentPackage(dpBuilder);
    assertNotNull(dp);
    BundleInfo[] bundleInfos = dp.getBundleInfos();
    assertEquals(2, bundleInfos.length);
    // Verify that none of the bundles are installed...
    assertBundleExists("testbundles.bundleapi", "1.0.0");
    assertBundleExists("testbundles.bundleimpl", "1.0.0");
}
Also used : BundleInfo(org.osgi.service.deploymentadmin.BundleInfo) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) Test(org.junit.Test)

Example 53 with DeploymentPackageBuilder

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

the class InstallDeploymentPackageTest method testInstallDeploymentPackageWithLocalizationAndSignatureFilesOk.

/**
 * FELIX-518 - Test that DP with localization and signature files are properly deployed.
 */
@Test
public void testInstallDeploymentPackageWithLocalizationAndSignatureFilesOk() throws Exception {
    URL dpProps = getClass().getResource("/dp.properties");
    assertNotNull(dpProps);
    SignerInfo signer = createSelfSignedCert("CN=dpTest", KeyType.EC);
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.signOutput(signer.getPrivate(), signer.getCert()).add(dpBuilder.createLocalizationResource().setUrl(dpProps).setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setFilename("dp.properties")).add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")));
    // should succeed.
    installDeploymentPackage(dpBuilder);
    assertBundleExists("testbundles.bundle1", "1.0.0");
    assertBundleExists("testbundles.bundle2", "1.0.0");
    assertBundleExists("testbundles.rp1", "1.0.0");
}
Also used : SignerInfo(org.apache.felix.deploymentadmin.itest.util.CertificateUtil.SignerInfo) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) URL(java.net.URL) Test(org.junit.Test)

Example 54 with DeploymentPackageBuilder

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

the class InstallDeploymentPackageTest method testInstallBundleWithExceptionThrownInStartCausesNoRollbackOk.

/**
 * Tests that if an exception is thrown in the start method of a bundle, the installation is not rolled back.
 */
@Test
public void testInstallBundleWithExceptionThrownInStartCausesNoRollbackOk() throws Exception {
    System.setProperty("bundle3", "start");
    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("bundle1"), "1.0.0");
    assertBundleExists(getSymbolicName("bundle3"), "1.0.0");
    assertTrue(isBundleActive(dp.getBundle(getSymbolicName("bundle1"))));
    // the bundle threw an exception during start, so it is not active...
    assertFalse(isBundleActive(dp.getBundle(getSymbolicName("bundle3"))));
    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 55 with DeploymentPackageBuilder

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

the class InstallFixPackageTest method testInstallFixPackageOutsideLowerTargetRangeFail.

/**
 * Tests that it is not possible to install a fix package if it specifies a fix-version range that falls outside the installed target deployment package.
 */
@Test
public void testInstallFixPackageOutsideLowerTargetRangeFail() throws Exception {
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")));
    DeploymentPackage dp1 = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp1);
    awaitRefreshPackagesEvent();
    Bundle bundle = dp1.getBundle(getSymbolicName("bundle2"));
    assertNotNull("Failed to obtain bundle from deployment package?!", bundle);
    assertEquals(Bundle.INSTALLED, bundle.getState());
    dpBuilder = createDeploymentPackageBuilder(dpBuilder.getSymbolicName(), "1.0.1");
    // should not include version 1.0.0!
    dpBuilder.setFixPackage("(1.0,2.0)").add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")).setMissing());
    try {
        installDeploymentPackage(dpBuilder);
        fail("Succeeded into installing fix package for undefined target package?!");
    } catch (DeploymentException exception) {
        // Ok; expected
        assertDeploymentException(CODE_MISSING_FIXPACK_TARGET, exception);
    }
}
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)

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