Search in sources :

Example 41 with DeploymentPackageBuilder

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

the class DeploymentPackageBuilderTest method testCreateMinimalTwoBundleResourcesOk.

/**
 * Tests that we can build a deployment package with two bundle resources.
 */
@Test
public void testCreateMinimalTwoBundleResourcesOk() throws Exception {
    DeploymentPackageBuilder dpBuilder = DeploymentPackageBuilder.create("dp-test", "1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle2")));
    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.0.0");
    filename = getBundleName("bundle2");
    assertManifestEntry(manifest, filename, "Name", filename);
    assertManifestEntry(manifest, filename, "Bundle-SymbolicName", "testbundles.bundle2");
    assertManifestEntry(manifest, filename, "Bundle-Version", "1.0.0");
    int count = countJarEntries(jis);
    assertEquals("Expected two entries in the JAR!", 2, count);
}
Also used : JarInputStream(java.util.jar.JarInputStream) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) Manifest(java.util.jar.Manifest) Test(org.junit.Test)

Example 42 with DeploymentPackageBuilder

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

the class DeploymentPackageBuilderTest method testCreateMinimalSingleBundleResourceOk.

/**
 * Tests that we can build a deployment package with a bundle resource.
 */
@Test
public void testCreateMinimalSingleBundleResourceOk() throws Exception {
    DeploymentPackageBuilder dpBuilder = DeploymentPackageBuilder.create("dp-test", "1.0.0");
    dpBuilder.add(dpBuilder.createBundleResource().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.0.0");
    int count = countJarEntries(jis);
    assertEquals("Expected two entries in the JAR!", 1, count);
}
Also used : JarInputStream(java.util.jar.JarInputStream) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) Manifest(java.util.jar.Manifest) Test(org.junit.Test)

Example 43 with DeploymentPackageBuilder

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

the class DeploymentPackageBuilderTest method testCreateMinimalSingleResourceAndProcessorOk.

/**
 * Tests that we can build a deployment package with a "plain" resource and resource processor.
 */
@Test
public void testCreateMinimalSingleResourceAndProcessorOk() throws Exception {
    DeploymentPackageBuilder dpBuilder = DeploymentPackageBuilder.create("dp-test", "1.0.0");
    dpBuilder.add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundle("rp1"))).add(dpBuilder.createResource().setResourceProcessorPID("org.apache.felix.deploymentadmin.test.rp1").setUrl(getTestResource("test-config1.xml")));
    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("rp1");
    assertManifestEntry(manifest, filename, "Name", filename);
    assertManifestEntry(manifest, filename, "Bundle-SymbolicName", "testbundles.rp1");
    assertManifestEntry(manifest, filename, "Bundle-Version", "1.0.0");
    filename = "test-config1.xml";
    assertManifestEntry(manifest, filename, "Name", filename);
    assertManifestEntry(manifest, filename, "Resource-Processor", "org.apache.felix.deploymentadmin.test.rp1");
    int count = countJarEntries(jis);
    assertEquals("Expected two entries in the JAR!", 2, count);
}
Also used : JarInputStream(java.util.jar.JarInputStream) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) Manifest(java.util.jar.Manifest) Test(org.junit.Test)

Example 44 with DeploymentPackageBuilder

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

the class InstallDeploymentPackageTest method testInstallBundleWithDependencyInSeparatePackageOk.

/**
 * Tests that installing a bundle with a dependency installed by another deployment package is not started, but is
 * resolved.
 */
@Test
public void testInstallBundleWithDependencyInSeparatePackageOk() 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();
    assertBundleExists(getSymbolicName("bundle2"), "1.0.0");
    // We shouldn't be able to resolve the deps for bundle2...
    assertFalse(resolveBundles(dp1.getBundle(getSymbolicName("bundle2"))));
    assertTrue(isBundleInstalled(dp1.getBundle(getSymbolicName("bundle2"))));
    dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    // as missing bundle1...
    dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")));
    DeploymentPackage dp2 = installDeploymentPackage(dpBuilder);
    assertNotNull("No deployment package returned?!", dp2);
    awaitRefreshPackagesEvent();
    assertBundleExists(getSymbolicName("bundle1"), "1.0.0");
    assertBundleExists(getSymbolicName("bundle2"), "1.0.0");
    // Now we should be able to resolve the dependencies for bundle2...
    assertTrue(resolveBundles(dp1.getBundle(getSymbolicName("bundle2"))));
    assertTrue(isBundleActive(dp2.getBundle(getSymbolicName("bundle1"))));
    assertTrue(isBundleResolved(dp1.getBundle(getSymbolicName("bundle2"))));
}
Also used : DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) Test(org.junit.Test)

Example 45 with DeploymentPackageBuilder

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

the class InstallDeploymentPackageTest method testInstallBundleWithOtherArtifactsOk.

/**
 * Tests that installing a bundle along with other (non-bundle) artifacts succeeds.
 */
@Test
public void testInstallBundleWithOtherArtifactsOk() throws Exception {
    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)

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