use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class InstallFixPackageTest method testRemoveBundleInFixPackageUpdateOk.
/**
* Tests the removal of a bundle through a fix package.
*/
@Test
public void testRemoveBundleInFixPackageUpdateOk() throws Exception {
DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).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.ACTIVE, bundle.getState());
// valid-bundle2 is to be removed by this fix package...
dpBuilder = createDeploymentPackageBuilder(dpBuilder.getSymbolicName(), "1.0.1");
dpBuilder.setFixPackage("[1.0,2.0)").add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")).setMissing());
DeploymentPackage dp2 = installDeploymentPackage(dpBuilder);
assertNotNull("No deployment package returned?!", dp2);
awaitRefreshPackagesEvent();
assertBundleExists(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 testInstallFixPackageWithMissingTargetResourceFail.
/**
* Tests that installing a fix-package that mentions a resource that is not in the target package fails.
*/
@Test
public void testInstallFixPackageWithMissingTargetResourceFail() 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);
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.createResourceProcessorResource().setUrl(getTestBundleURL("rp1"))).add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")).setMissing());
try {
installDeploymentPackage(dpBuilder);
fail("Succeeded into installing a fix-package with a missing bundle on target?!");
} catch (DeploymentException exception) {
assertDeploymentException(CODE_MISSING_RESOURCE, exception);
}
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class ResourceSharingTest method testBundleCanBelongToOneDeploymentPackageOnly.
@Test
public void testBundleCanBelongToOneDeploymentPackageOnly() throws Exception {
DeploymentPackageBuilder dpBuilder1 = createNewDeploymentPackageBuilder("1.0.0");
dpBuilder1.add(dpBuilder1.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder1.createBundleResource().setUrl(getTestBundleURL("bundle2")));
DeploymentPackageBuilder dpBuilder2 = createNewDeploymentPackageBuilder("0.8.0");
dpBuilder2.add(dpBuilder2.createBundleResource().setUrl(getTestBundleURL("bundle1")));
DeploymentPackage dp1 = installDeploymentPackage(dpBuilder1);
assertNotNull("No deployment package returned?!", dp1);
awaitRefreshPackagesEvent();
try {
// should fail: valid-bundle1 belongs to another DP...
installDeploymentPackage(dpBuilder2);
fail("Expected a DeploymentException with code " + DeploymentException.CODE_BUNDLE_SHARING_VIOLATION);
} catch (DeploymentException exception) {
// Ok; expected...
assertEquals(DeploymentException.CODE_BUNDLE_SHARING_VIOLATION, exception.getCode());
}
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class ResourceSharingTest method testBundleCannotBeSharedWithNonDeploymentPackagedBundle.
@Test
public void testBundleCannotBeSharedWithNonDeploymentPackagedBundle() throws Exception {
// Manually install a bundle...
Bundle result = m_context.installBundle(getTestBundleURL("bundle1").toExternalForm());
assertNotNull(result);
assertBundleExists(getSymbolicName("bundle1"), "1.0.0");
DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")));
try {
// should fail: valid-bundle1 is installed, but does not belong to any DP...
installDeploymentPackage(dpBuilder);
fail("Expected a DeploymentException with code " + DeploymentException.CODE_BUNDLE_SHARING_VIOLATION);
} catch (DeploymentException exception) {
// Ok; expected...
assertEquals(DeploymentException.CODE_BUNDLE_SHARING_VIOLATION, exception.getCode());
}
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class UninstallDeploymentPackageTest method testUninstallDeploymentPackageWithExceptionThrowingInPrepareCausesRollbackOk.
/**
* Tests that if an exception is thrown during the prepare-phase, the installation is rolled back.
*/
@Test
public void testUninstallDeploymentPackageWithExceptionThrowingInPrepareCausesRollbackOk() throws Exception {
DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1"))).add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
DeploymentPackage dp = installDeploymentPackage(dpBuilder);
assertNotNull("No deployment package returned?!", dp);
awaitRefreshPackagesEvent();
assertTrue("Two bundles should be started!", getCurrentBundles().size() == 2);
assertEquals("Expected no deployment package?!", 1, countDeploymentPackages());
System.setProperty("rp1", "prepare");
try {
dp.uninstall();
fail("Expected uninstall to fail and rollback!");
} catch (DeploymentException exception) {
// Ok; expected
assertDeploymentException(CODE_COMMIT_ERROR, exception);
}
assertTrue("Two bundles should be started!", getCurrentBundles().size() == 2);
assertEquals("Expected no deployment package?!", 1, countDeploymentPackages());
}
Aggregations