use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class CustomizerTest method testDropResourceWithExceptionThrowingInDroppedCausesRollbackOk.
/**
* Tests that if an exception is thrown during the dropping of a resource, the installation is continued and finishes normally.
*/
@Test
public void testDropResourceWithExceptionThrowingInDroppedCausesRollbackOk() throws Exception {
System.setProperty("rp1", "dropped");
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")));
DeploymentPackage dp = installDeploymentPackage(dpBuilder);
assertNotNull("No deployment package returned?!", dp);
awaitRefreshPackagesEvent();
assertTrue("One bundle should be started!", getCurrentBundles().size() == 1);
assertEquals("Expected no deployment package?!", 1, countDeploymentPackages());
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class CustomizerTest method testInstallResourceWithForeignCustomizerFail.
/**
* Tests that if a resource is installed which mentions a RP that does not belong to the same package, a rollback takes place.
*/
@Test
public void testInstallResourceWithForeignCustomizerFail() throws Exception {
DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
dpBuilder.add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")));
installDeploymentPackage(dpBuilder);
awaitRefreshPackagesEvent();
assertEquals("Expected no deployment package?!", 1, countDeploymentPackages());
assertBundleExists(getSymbolicName("rp1"), "1.0.0");
dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
dpBuilder.disableVerification().add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).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_FOREIGN_CUSTOMIZER, exception);
}
assertEquals("Expected no deployment package?!", 1, countDeploymentPackages());
assertTrue("Expected no additional artifacts to be installed?!", getCurrentBundles().size() == 1);
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class CustomizerTest method testInstallBundleWithNonProcessedResourcesOk.
/**
* FELIX-4491 - Only resources with a resource processor defined should be processed.
*/
@Test
public void testInstallBundleWithNonProcessedResourcesOk() throws Exception {
DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
dpBuilder.add(dpBuilder.createResource().setNeedResourceProcessor(false).setUrl(getTestResource("LICENSE"))).add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1"))).add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")));
DeploymentPackage dp = installDeploymentPackage(dpBuilder);
assertNotNull("No deployment package returned?!", dp);
assertEquals("Expected a single deployment package?!", 1, countDeploymentPackages());
awaitRefreshPackagesEvent();
assertBundleExists(getSymbolicName("bundle1"), "1.0.0");
// Check that only the processed resources are dropped...
dp.uninstall();
assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
awaitRefreshPackagesEvent();
assertBundleNotExists(getSymbolicName("bundle1"), "1.0.0");
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class CustomizerTest method testInstallResourceWithExceptionThrowingInProcessCausesRollbackOk.
/**
* Tests that if an exception is thrown during the processing of a resource, the installation is cancelled and rolled back.
*/
@Test
public void testInstallResourceWithExceptionThrowingInProcessCausesRollbackOk() throws Exception {
System.setProperty("rp1", "process");
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_RESOURCE_SHARING_VIOLATION, 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 DeploymentAdminEventTest method testFailedInstallationCausesCompletionEventOk.
/**
* FELIX-4466 - test that an event is fired when an installation of a DP fails.
*/
@Test
public void testFailedInstallationCausesCompletionEventOk() throws Exception {
DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
// incluse two different versions of the same bundle (with the same BSN), this is *not* allowed per the DA spec...
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi2", "bundleapi2", "2.0.0")));
final AtomicReference<Event> completionEventRef = new AtomicReference<Event>();
final AtomicReference<Event> installEventRef = new AtomicReference<Event>();
final CountDownLatch cdl = new CountDownLatch(1);
EventHandler eventHandler = new EventHandler() {
@Override
public void handleEvent(Event event) {
if (Constants.EVENTTOPIC_COMPLETE.equals(event.getTopic())) {
assertTrue("Multiple events received?!", completionEventRef.compareAndSet(null, event));
cdl.countDown();
} else if (Constants.EVENTTOPIC_INSTALL.equals(event.getTopic())) {
assertTrue("Multiple events received?!", installEventRef.compareAndSet(null, event));
}
}
};
Dictionary props = new Properties();
props.put(EventConstants.EVENT_TOPIC, new String[] { Constants.EVENTTOPIC_COMPLETE, Constants.EVENTTOPIC_INSTALL });
ServiceRegistration sreg = m_context.registerService(EventHandler.class, eventHandler, props);
try {
installDeploymentPackage(dpBuilder);
fail("DeploymentException expected!");
} catch (DeploymentException e) {
// Ok; expected...
assertTrue("Not all events were received in time?!", cdl.await(5, TimeUnit.SECONDS));
Event event;
// Verify we've got the expected events...
event = installEventRef.get();
// The install event is send *after* the DP have been created, which fails in this test...
assertNull("No install event received?!", event);
event = completionEventRef.get();
assertNotNull("No completion event received?!", event);
assertTrue("Completion property set to true?!", Boolean.FALSE.equals(event.getProperty(Constants.EVENTPROPERTY_SUCCESSFUL)));
} finally {
sreg.unregister();
}
}
Aggregations