Search in sources :

Example 21 with DeploymentPackageBuilder

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

the class InstallFixPackageTest method testRemoveBundleInFixPackageUpdateOk.

/**
 * Tests the removal of a bundle through a fix package.
 */
@Test
public void testRemoveBundleInFixPackageUpdateOk() throws Exception {
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).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.ACTIVE, bundle.getState());
    // valid-bundle2 is to be removed by this fix package...
    dpBuilder = createDeploymentPackageBuilder(dpBuilder.getSymbolicName(), "1.0.1");
    dpBuilder.setFixPackage("[1.0,2.0)").add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")).setMissing());
    DeploymentPackage dp2 = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp2);
    awaitRefreshPackagesEvent();
    assertBundleExists(getSymbolicName("bundle1"), "1.0.0");
    assertBundleNotExists(getSymbolicName("bundle2"), "1.0.0");
}
Also used : Bundle(org.osgi.framework.Bundle) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) Test(org.junit.Test)

Example 22 with DeploymentPackageBuilder

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

the class InstallFixPackageTest method testInstallFixPackageWithMissingTargetResourceFail.

/**
 * Tests that installing a fix-package that mentions a resource that is not in the target package fails.
 */
@Test
public void testInstallFixPackageWithMissingTargetResourceFail() throws Exception {
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")));
    DeploymentPackage dp1 = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp1);
    assertEquals("Expected only a single deployment package?!", 1, countDeploymentPackages());
    awaitRefreshPackagesEvent();
    dpBuilder = createDeploymentPackageBuilder(dpBuilder.getSymbolicName(), "1.0.1");
    dpBuilder.setFixPackage("[1.0,2.0)").add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1"))).add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")).setMissing());
    try {
        installDeploymentPackage(dpBuilder);
        fail("Succeeded into installing a fix-package with a missing bundle on target?!");
    } catch (DeploymentException exception) {
        assertDeploymentException(CODE_MISSING_RESOURCE, exception);
    }
}
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 23 with DeploymentPackageBuilder

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

the class ResourceSharingTest method testBundleCanBelongToOneDeploymentPackageOnly.

@Test
public void testBundleCanBelongToOneDeploymentPackageOnly() throws Exception {
    DeploymentPackageBuilder dpBuilder1 = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder1.add(dpBuilder1.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder1.createBundleResource().setUrl(getTestBundleURL("bundle2")));
    DeploymentPackageBuilder dpBuilder2 = createNewDeploymentPackageBuilder("0.8.0");
    dpBuilder2.add(dpBuilder2.createBundleResource().setUrl(getTestBundleURL("bundle1")));
    DeploymentPackage dp1 = installDeploymentPackage(dpBuilder1);
    assertNotNull("No deployment package returned?!", dp1);
    awaitRefreshPackagesEvent();
    try {
        // should fail: valid-bundle1 belongs to another DP...
        installDeploymentPackage(dpBuilder2);
        fail("Expected a DeploymentException with code " + DeploymentException.CODE_BUNDLE_SHARING_VIOLATION);
    } catch (DeploymentException exception) {
        // Ok; expected...
        assertEquals(DeploymentException.CODE_BUNDLE_SHARING_VIOLATION, exception.getCode());
    }
}
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 24 with DeploymentPackageBuilder

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

the class ResourceSharingTest method testBundleCannotBeSharedWithNonDeploymentPackagedBundle.

@Test
public void testBundleCannotBeSharedWithNonDeploymentPackagedBundle() throws Exception {
    // Manually install a bundle...
    Bundle result = m_context.installBundle(getTestBundleURL("bundle1").toExternalForm());
    assertNotNull(result);
    assertBundleExists(getSymbolicName("bundle1"), "1.0.0");
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")));
    try {
        // should fail: valid-bundle1 is installed, but does not belong to any DP...
        installDeploymentPackage(dpBuilder);
        fail("Expected a DeploymentException with code " + DeploymentException.CODE_BUNDLE_SHARING_VIOLATION);
    } catch (DeploymentException exception) {
        // Ok; expected...
        assertEquals(DeploymentException.CODE_BUNDLE_SHARING_VIOLATION, exception.getCode());
    }
}
Also used : Bundle(org.osgi.framework.Bundle) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Test(org.junit.Test)

Example 25 with DeploymentPackageBuilder

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

the class UninstallDeploymentPackageTest method testUninstallDeploymentPackageWithExceptionThrowingInPrepareCausesRollbackOk.

/**
 * Tests that if an exception is thrown during the prepare-phase, the installation is rolled back.
 */
@Test
public void testUninstallDeploymentPackageWithExceptionThrowingInPrepareCausesRollbackOk() 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", "prepare");
    try {
        dp.uninstall();
        fail("Expected uninstall to fail and rollback!");
    } catch (DeploymentException exception) {
        // Ok; expected
        assertDeploymentException(CODE_COMMIT_ERROR, exception);
    }
    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)

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