Search in sources :

Example 61 with DeploymentPackageBuilder

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

the class InstallFixPackageTest method testUpdateWithDuplicateBundleFail.

/**
 * Tests that if we try to update with a DP containing a duplicate bundle (of which one is already installed in
 * an earlier DP) that this will fail the installation. See FELIX-4463.
 */
@Test
public void testUpdateWithDuplicateBundleFail() throws Exception {
    DeploymentPackageBuilder dpBuilder = createDeploymentPackageBuilder("c", "1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl1", "bundleimpl1", "1.0.0")));
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0")));
    // Should succeed, as the DP is correct...
    DeploymentPackage dp1 = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp1);
    // then, install a fix package with implementation and api bundles in version 2.0.0, but *also* containing the original implementation
    // bundle, which is incorrect (no bundles with the same BSN may exist in a DP)...
    dpBuilder = createDeploymentPackageBuilder("c", "2.0.0").setFixPackage("[1.0.0,2.0.0]");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0")));
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl2", "bundleimpl2", "2.0.0")));
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl1", "bundleimpl1", "1.0.0")));
    try {
        installDeploymentPackage(dpBuilder);
        fail("DeploymentException expected!");
    } catch (DeploymentException e) {
        // Ok; expected...
        assertEquals(DeploymentException.CODE_OTHER_ERROR, e.getCode());
    }
    awaitRefreshPackagesEvent();
    // Nothing should be updated...
    assertBundleExists(getSymbolicName("bundleimpl"), "1.0.0");
    assertBundleExists(getSymbolicName("bundleapi"), "1.0.0");
}
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 62 with DeploymentPackageBuilder

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

the class InstallFixPackageTest method testInstallAndUpdateImplementationBundleWithSeparateAPIBundle_FELIX4184.

@Test
public void testInstallAndUpdateImplementationBundleWithSeparateAPIBundle_FELIX4184() throws Exception {
    String value = System.getProperty("org.apache.felix.deploymentadmin.stopunaffectedbundle");
    System.setProperty("org.apache.felix.deploymentadmin.stopunaffectedbundle", "false");
    // first, install a deployment package with implementation and api bundles in version 1.0.0
    DeploymentPackageBuilder dpBuilder = createDeploymentPackageBuilder("a", "1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl1", "bundleimpl1", "1.0.0")));
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0")));
    DeploymentPackage dp1 = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp1);
    assertEquals("Expected a single deployment package?!", 1, countDeploymentPackages());
    // then, install a fix package with implementation and api bundles in version 2.0.0
    dpBuilder = createDeploymentPackageBuilder("a", "2.0.0").setFixPackage("[1.0.0,2.0.0]");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl2", "bundleimpl2", "2.0.0")));
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi2", "bundleapi2", "2.0.0")));
    DeploymentPackage dp2 = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp2);
    awaitRefreshPackagesEvent();
    assertBundleExists(getSymbolicName("bundleimpl"), "2.0.0");
    assertBundleExists(getSymbolicName("bundleapi"), "2.0.0");
    assertBundleNotExists(getSymbolicName("bundleimpl"), "1.0.0");
    assertBundleNotExists(getSymbolicName("bundleapi"), "1.0.0");
    if (value != null) {
        System.setProperty("org.apache.felix.deploymentadmin.stopunaffectedbundle", value);
    }
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) Test(org.junit.Test)

Example 63 with DeploymentPackageBuilder

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

the class InstallFixPackageTest method testInstallFixPackageReplacesOriginalTargetPackageOk.

/**
 * Tests that installing a fix-package causes the original target package to be replaced.
 */
@Test
public void testInstallFixPackageReplacesOriginalTargetPackageOk() 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);
    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.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")).setMissing());
    DeploymentPackage dp2 = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp2);
    awaitRefreshPackagesEvent();
    assertEquals("Expected only 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 64 with DeploymentPackageBuilder

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

the class InstallFixPackageTest method testInstallBundleWithDependencyInFixPackageUpdateOk.

/**
 * Tests that we can install a new bundle through a fix-package.
 */
@Test
public void testInstallBundleWithDependencyInFixPackageUpdateOk() 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");
    dpBuilder.setFixPackage("[1.0,2.0)").add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")).setMissing());
    DeploymentPackage dp2 = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp2);
    awaitRefreshPackagesEvent();
    bundle = dp2.getBundle(getSymbolicName("bundle2"));
    assertNotNull("Failed to obtain bundle from bundle context?!", bundle);
    assertBundleExists(getSymbolicName("bundle1"), "1.0.0");
    assertBundleExists(getSymbolicName("bundle2"), "1.0.0");
    assertTrue(isBundleActive(bundle));
}
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 65 with DeploymentPackageBuilder

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

the class ResourceSharingTest method testForeignBundleCanCoexistWithPackagedBundleIfVersionsDiffer.

@Test
public void testForeignBundleCanCoexistWithPackagedBundleIfVersionsDiffer() throws Exception {
    // Manually install a bundle...
    Bundle result = m_context.installBundle(getTestBundleURL("bundle1").toExternalForm());
    assertNotNull(result);
    long bundleId = result.getBundleId();
    assertBundleExists(getSymbolicName("bundle1"), "1.0.0");
    assertTrue(isBundleInstalled(result));
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setVersion("1.1.0").setUrl(getTestBundleURL("bundle1")).setFilter(new JarManifestManipulatingFilter("Bundle-Version", "1.1.0"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")));
    // should succeed: valid-bundle1 is installed, but has a different version than the one in our DP...
    DeploymentPackage dp = installDeploymentPackage(dpBuilder);
    awaitRefreshPackagesEvent();
    assertBundleExists(getSymbolicName("bundle1"), "1.0.0");
    assertBundleExists(getSymbolicName("bundle1"), "1.1.0");
    // The manually installed bundle should still be in the installed or resolved state...
    assertTrue(isBundleInstalled(m_context.getBundle(bundleId)) || isBundleResolved(m_context.getBundle(bundleId)));
    assertTrue(isBundleActive(dp.getBundle(getSymbolicName("bundle1"))));
}
Also used : Bundle(org.osgi.framework.Bundle) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) JarManifestManipulatingFilter(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder.JarManifestManipulatingFilter) 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