use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class CustomizerTest method testInstallBundleWithExceptionThrowingInCommitCauseNoRollbackOk.
/**
* Tests that if an exception is thrown during the commit-phase, the installation proceeds and succeeds.
*/
@Test
public void testInstallBundleWithExceptionThrowingInCommitCauseNoRollbackOk() throws Exception {
System.setProperty("rp1", "commit");
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());
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class CustomizerTest method testInstallResourceWithNonAvailableCustomizerFail.
/**
* Tests that if a resource is installed which mentions a RP that does not exist a rollback takes place.
*/
@Test
public void testInstallResourceWithNonAvailableCustomizerFail() throws Exception {
DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
dpBuilder.disableVerification().add(dpBuilder.createResource().setResourceProcessorPID("my.unknown.rp").setUrl(getTestResource("test-config1.xml")));
try {
installDeploymentPackage(dpBuilder);
fail("Succeeded into installing a resource with an non-existing RP?!");
} catch (DeploymentException exception) {
// Ok; expected...
assertDeploymentException(CODE_PROCESSOR_NOT_FOUND, exception);
}
assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
assertTrue("Expected no artifacts to be installed?!", getCurrentBundles().isEmpty());
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class CustomizerTest method testInstallBundleWithExceptionThrowingInPrepareCausesRollbackOk.
/**
* Tests that if an exception is thrown during the prepare-phase, the installation is cancelled and rolled back.
*/
@Test
public void testInstallBundleWithExceptionThrowingInPrepareCausesRollbackOk() throws Exception {
System.setProperty("rp1", "prepare");
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")));
try {
installDeploymentPackage(dpBuilder);
fail("Succeeded into installing a failing deployment package?!");
} catch (DeploymentException exception) {
// Ok; expected
assertDeploymentException(DeploymentException.CODE_COMMIT_ERROR, exception);
}
assertTrue("No bundles should be started!", getCurrentBundles().isEmpty());
assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class CustomizerTest method testInstallResourceProcessorWithExceptionThrowingInStartCausesRollbackOk.
/**
* Tests that if an exception is thrown during the commit-phase, the installation proceeds and succeeds.
*/
@Test
public void testInstallResourceProcessorWithExceptionThrowingInStartCausesRollbackOk() throws Exception {
System.setProperty("rp1", "start");
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")));
try {
installDeploymentPackage(dpBuilder);
fail("Succeeded into installing a failing RP?!");
} catch (DeploymentException exception) {
// Ok; expected...
assertDeploymentException(CODE_OTHER_ERROR, exception);
}
assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
assertTrue("Expected no artifacts to be installed?!", getCurrentBundles().isEmpty());
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class DPSignerTest method testSignArtifactsOk.
@Test
public void testSignArtifactsOk() throws Exception {
URL dpProps = getClass().getResource("/dp.properties");
assertNotNull(dpProps);
DeploymentPackageBuilder builder = DeploymentPackageBuilder.create("dpSignerTest1", "1.0.0");
builder.add(builder.createLocalizationResource().setUrl(dpProps).setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setFilename("dp.properties"));
SignerInfo signerInfo = CertificateUtil.createSelfSignedCert("CN=testCert", KeyType.RSA);
DPSigner signer = new DPSigner();
byte[] rawData;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
signer.sign(builder, signerInfo.getPrivate(), signerInfo.getCert(), baos);
rawData = baos.toByteArray();
}
try (ByteArrayInputStream bais = new ByteArrayInputStream(rawData);
JarInputStream jis = new JarInputStream(bais, true)) {
JarEntry entry;
while ((entry = jis.getNextJarEntry()) != null) {
assertNotNull(entry);
jis.closeEntry();
}
assertNotNull(jis.getManifest());
}
}
Aggregations