Search in sources :

Example 1 with JarManifestManipulatingFilter

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

the class DeploymentAdminTest method testBundleVersionMustMatchManifestEntry.

@Test
public void testBundleVersionMustMatchManifestEntry() throws Exception {
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")).setFilter(new JarManifestManipulatingFilter("Bundle-Version", "1.1.0")));
    try {
        installDeploymentPackage(dpBuilder);
        fail("Succeeded into installing a bundle with a fake version?!");
    } catch (DeploymentException exception) {
        // Ok; expected...
        assertDeploymentException(CODE_OTHER_ERROR, exception);
    }
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) JarManifestManipulatingFilter(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder.JarManifestManipulatingFilter) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Test(org.junit.Test)

Example 2 with JarManifestManipulatingFilter

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

the class DeploymentPackageBuilderTest method testResourceFilterOk.

/**
 * Tests that we can filter a resource.
 */
@Test
public void testResourceFilterOk() throws Exception {
    DeploymentPackageBuilder dpBuilder = DeploymentPackageBuilder.create("dp-test", "1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle2"))).add(dpBuilder.createBundleResource().setVersion("1.1.0").setFilter(new JarManifestManipulatingFilter("Bundle-Version", "1.1.0", "Foo", "bar")).setUrl(getTestBundle("bundle1")));
    JarInputStream jis = new JarInputStream(dpBuilder.generate());
    assertNotNull(jis);
    Manifest manifest = jis.getManifest();
    assertManifestHeader(manifest, "DeploymentPackage-SymbolicName", "dp-test");
    assertManifestHeader(manifest, "DeploymentPackage-Version", "1.0.0");
    String filename = getBundleName("bundle1");
    assertManifestEntry(manifest, filename, "Name", filename);
    assertManifestEntry(manifest, filename, "Bundle-SymbolicName", "testbundles.bundle1");
    assertManifestEntry(manifest, filename, "Bundle-Version", "1.1.0");
    filename = getBundleName("bundle2");
    assertManifestEntry(manifest, filename, "Name", filename);
    assertManifestEntry(manifest, filename, "Bundle-SymbolicName", "testbundles.bundle2");
    assertManifestEntry(manifest, filename, "Bundle-Version", "1.0.0");
    try {
        byte[] buf = new byte[32 * 1024];
        JarEntry entry;
        while ((entry = jis.getNextJarEntry()) != null) {
            if (entry.getName().endsWith("valid-bundle1.jar")) {
                int read = jis.read(buf);
                JarInputStream jis2 = new JarInputStream(new ByteArrayInputStream(Arrays.copyOf(buf, read)));
                Manifest manifest2 = jis2.getManifest();
                Attributes mainAttributes = manifest2.getMainAttributes();
                assertEquals("1.1.0", mainAttributes.getValue("Bundle-Version"));
                assertEquals("bar", mainAttributes.getValue("Foo"));
                jis2.close();
            }
            jis.closeEntry();
        }
    } finally {
        jis.close();
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) Attributes(java.util.jar.Attributes) JarManifestManipulatingFilter(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder.JarManifestManipulatingFilter) Manifest(java.util.jar.Manifest) JarEntry(java.util.jar.JarEntry) Test(org.junit.Test)

Example 3 with JarManifestManipulatingFilter

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

the class InstallDeploymentPackageTest method testUpgradeWithPopulatedDataAreaOk.

/**
 * Tests that we can correctly install a deployment package with bundles that have their data area populated.
 */
@Test
public void testUpgradeWithPopulatedDataAreaOk() throws Exception {
    // Install a first version, in which we're going to change the data area of a bundle...
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setVersion("1.0.0").setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")));
    DeploymentPackage dp = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp);
    awaitRefreshPackagesEvent();
    Bundle bundle1 = getBundle("testbundles.bundle1");
    assertNotNull("Unable to get installed test bundle?!", bundle1);
    File dataArea = bundle1.getDataFile("");
    assertNotNull("No data area obtained for test bundle?!", dataArea);
    // Populate the data area...
    assertTrue("No file created?!", new File(dataArea, "file1").createNewFile());
    assertTrue("No file created?!", new File(dataArea, "file2").createNewFile());
    assertTrue("No file created?!", new File(dataArea, "file3").createNewFile());
    dpBuilder = createDeploymentPackageBuilder(dpBuilder.getSymbolicName(), "1.0.1");
    dpBuilder.add(dpBuilder.createBundleResource().setVersion("1.1.0").setUrl(getTestBundleURL("bundle1")).setFilter(new JarManifestManipulatingFilter("Bundle-Version", "1.1.0"))).add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1"))).add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
    // should succeed!
    dp = installDeploymentPackage(dpBuilder);
    // We should still have this bundle..
    bundle1 = getBundle("testbundles.bundle1");
    assertNotNull("Unable to get installed test bundle?!", bundle1);
    dataArea = bundle1.getDataFile("");
    assertNotNull("No data area obtained for test bundle?!", dataArea);
    // Data area should be restored exactly as-is...
    assertTrue("File not restored?!", new File(dataArea, "file1").exists());
    assertTrue("File not restored?!", new File(dataArea, "file2").exists());
    assertTrue("File not restored?!", new File(dataArea, "file3").exists());
}
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) File(java.io.File) Test(org.junit.Test)

Example 4 with JarManifestManipulatingFilter

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

the class DeploymentAdminTest method testBundleSymbolicNameMustMatchManifestEntry.

@Test
public void testBundleSymbolicNameMustMatchManifestEntry() throws Exception {
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")).setFilter(new JarManifestManipulatingFilter("Bundle-SymbolicName", "foo")));
    try {
        installDeploymentPackage(dpBuilder);
        fail("Succeeded into installing a bundle with a fake symbolic name?!");
    } catch (DeploymentException exception) {
        // Ok; expected...
        assertDeploymentException(CODE_BUNDLE_NAME_ERROR, exception);
    }
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) JarManifestManipulatingFilter(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder.JarManifestManipulatingFilter) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Test(org.junit.Test)

Example 5 with JarManifestManipulatingFilter

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

the class InstallDeploymentPackageTest method testRollbackWithPopulatedDataAreaOk.

/**
 * Tests that we can correctly rollback the installation of a deployment package for bundles that have their data
 * area populated.
 */
@Test
public void testRollbackWithPopulatedDataAreaOk() throws Exception {
    // Install a first version, in which we're going to change the data area of a bundle...
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")));
    DeploymentPackage dp = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp);
    awaitRefreshPackagesEvent();
    Bundle bundle1 = getBundle("testbundles.bundle1");
    assertNotNull("Unable to get installed test bundle?!", bundle1);
    File dataArea = bundle1.getDataFile("");
    assertNotNull("No data area obtained for test bundle?!", dataArea);
    // Populate the data area...
    assertTrue("No file created?!", new File(dataArea, "file1").createNewFile());
    assertTrue("No file created?!", new File(dataArea, "file2").createNewFile());
    assertTrue("No file created?!", new File(dataArea, "file3").createNewFile());
    // This will cause the new bundle to fail in its stop method...
    System.setProperty("rp1", "process");
    // Simulate an upgrade for our bundle, which should cause its data area to be retained...
    dpBuilder = createDeploymentPackageBuilder(dpBuilder.getSymbolicName(), "1.0.1");
    dpBuilder.add(dpBuilder.createBundleResource().setVersion("1.1.0").setUrl(getTestBundleURL("bundle1")).setFilter(new JarManifestManipulatingFilter("Bundle-Version", "1.1.0"))).add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1"))).add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
    try {
        // should fail!
        dp = installDeploymentPackage(dpBuilder);
        fail("Deployment of upgrade package should have failed?!");
    } catch (DeploymentException e) {
    // Ok; expected...
    }
    // We should still have this bundle..
    bundle1 = getBundle("testbundles.bundle1");
    assertNotNull("Unable to get installed test bundle?!", bundle1);
    dataArea = bundle1.getDataFile("");
    assertNotNull("No data area obtained for test bundle?!", dataArea);
    // Data area should be restored exactly as-is...
    assertTrue("File not restored?!", new File(dataArea, "file1").exists());
    assertTrue("File not restored?!", new File(dataArea, "file2").exists());
    assertTrue("File not restored?!", new File(dataArea, "file3").exists());
}
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) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) File(java.io.File) Test(org.junit.Test)

Aggregations

DeploymentPackageBuilder (org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder)6 JarManifestManipulatingFilter (org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder.JarManifestManipulatingFilter)6 Test (org.junit.Test)6 Bundle (org.osgi.framework.Bundle)3 DeploymentException (org.osgi.service.deploymentadmin.DeploymentException)3 DeploymentPackage (org.osgi.service.deploymentadmin.DeploymentPackage)3 File (java.io.File)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Attributes (java.util.jar.Attributes)1 JarEntry (java.util.jar.JarEntry)1 JarInputStream (java.util.jar.JarInputStream)1 Manifest (java.util.jar.Manifest)1