use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder 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());
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class InstallFixPackageTest method testUninstallBundleAddedInFixPackageOk.
/**
* Tests that we can uninstall a fix-package.
*/
@Test
public void testUninstallBundleAddedInFixPackageOk() 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();
// Add valid-bundle1 through fix-package...
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 a single deployment package?!", 1, countDeploymentPackages());
assertBundleExists(getSymbolicName("bundle1"), "1.0.0");
assertBundleExists(getSymbolicName("bundle2"), "1.0.0");
// Uninstall the deployment package; should yield the original situation again...
dp2.uninstall();
awaitRefreshPackagesEvent();
assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
// None of our installed bundles should remain...
assertBundleNotExists(getSymbolicName("bundle1"), "1.0.0");
assertBundleNotExists(getSymbolicName("bundle2"), "1.0.0");
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class InstallFixPackageTest method testInstallFixPackageWithoutTargetFail.
/**
* Tests that a fix package can only be installed after at least one version of the denoted target package is installed.
*/
@Test
public void testInstallFixPackageWithoutTargetFail() throws Exception {
DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
dpBuilder.setFixPackage("[1.0,2.0)").add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")));
try {
installDeploymentPackage(dpBuilder);
fail("Should not be able to install fix package without target?!");
} catch (DeploymentException exception) {
// Ok; expected
assertDeploymentException(CODE_MISSING_FIXPACK_TARGET, exception);
}
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class InstallFixPackageTest method testMissingBundlesOnlyInFixPackageFail.
/**
* Tests that only in a fix-package bundle can be marked as missing.
*/
@Test
public void testMissingBundlesOnlyInFixPackageFail() 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.disableVerification().add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")).setMissing());
try {
installDeploymentPackage(dpBuilder);
fail("Failed to install missing bundle?!");
} catch (DeploymentException exception) {
// Ok; expected...
assertEquals("Invalid exception code?!", CODE_BAD_HEADER, exception.getCode());
}
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class InstallFixPackageTest method testInstallFixPackageWithMissingTargetBundleFromOtherPackageFail.
/**
* Tests that installing a fix-package that mentions a bundle that does exist (in another DP), but is not in the target package fails.
*/
@Test
public void testInstallFixPackageWithMissingTargetBundleFromOtherPackageFail() 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);
awaitRefreshPackagesEvent();
assertEquals("Expected only a single deployment package?!", 1, countDeploymentPackages());
dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")));
DeploymentPackage dp2 = installDeploymentPackage(dpBuilder);
assertNotNull("No deployment package returned?!", dp2);
awaitRefreshPackagesEvent();
assertEquals("Expected only a single deployment package?!", 2, countDeploymentPackages());
dpBuilder = createDeploymentPackageBuilder(dpBuilder.getSymbolicName(), "1.0.1");
dpBuilder.setFixPackage("[1.0,2.0)").add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")).setMissing()).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle3")));
try {
installDeploymentPackage(dpBuilder);
fail("Succeeded into installing a fix-package with a missing bundle on target?!");
} catch (DeploymentException exception) {
assertDeploymentException(CODE_BUNDLE_SHARING_VIOLATION, exception);
}
}
Aggregations