use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class InstallDeploymentPackageTest method testInstallBundleWithDependencyInPackageUpdateOk.
/**
* Tests that adding the dependency for a bundle in an update package causes the depending bundle to be resolved and
* started.
*/
@Test
public void testInstallBundleWithDependencyInPackageUpdateOk() throws Exception {
DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
// missing bundle1 as dependency...
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);
assertTrue(isBundleInstalled(dp1.getBundle(getSymbolicName("bundle2"))));
dpBuilder = createDeploymentPackageBuilder(dpBuilder.getSymbolicName(), "1.0.1");
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")));
DeploymentPackage dp2 = installDeploymentPackage(dpBuilder);
assertNotNull("No deployment package returned?!", dp2);
awaitRefreshPackagesEvent();
assertTrue(isBundleActive(dp2.getBundle(getSymbolicName("bundle1"))));
assertTrue(isBundleActive(dp2.getBundle(getSymbolicName("bundle2"))));
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class InstallDeploymentPackageTest method testRollbackUninstallBundleWithPopulatedDataAreaOk.
/**
* Tests that we can correctly install a deployment package with bundles that have their data area populated.
*/
@Test
public void testRollbackUninstallBundleWithPopulatedDataAreaOk() 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());
// This will cause the new bundle to fail in its stop method...
System.setProperty("rp1", "process");
dpBuilder = createDeploymentPackageBuilder(dpBuilder.getSymbolicName(), "1.0.1");
dpBuilder.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());
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder 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());
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class InstallDeploymentPackageTest method testUninstallBundleWithPopulatedDataAreaOk.
/**
* Tests that we can correctly install a deployment package with bundles that have their data area populated.
*/
@Test
public void testUninstallBundleWithPopulatedDataAreaOk() 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.createResourceProcessorResource().setUrl(getTestBundleURL("rp1"))).add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
// should succeed!
dp = installDeploymentPackage(dpBuilder);
// We should no longer have this bundle..
bundle1 = getBundle("testbundles.bundle1");
assertNull("Unable to get installed test bundle?!", bundle1);
// Data area should be restored exactly as-is...
assertFalse("Data area not purged?!", dataArea.exists());
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class InstallDeploymentPackageTest method testInstallSingleValidBundleOk.
/**
* Tests that installing a new bundle works as expected.
*/
@Test
public void testInstallSingleValidBundleOk() throws Exception {
DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")));
DeploymentPackage dp = installDeploymentPackage(dpBuilder);
assertNotNull("No deployment package returned?!", dp);
awaitRefreshPackagesEvent();
assertNotNull("Failed to obtain test service?!", awaitService(TEST_SERVICE_NAME));
assertBundleExists(getSymbolicName("bundle1"), "1.0.0");
assertTrue(isBundleActive(dp.getBundle(getSymbolicName("bundle1"))));
}
Aggregations