use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class DeploymentAdminEventTest method testSuccessfulUninstallationCausesCompletionEventOk.
/**
* FELIX-4466 - test that an event is fired when a DP is uninstalled.
*/
@Test
public void testSuccessfulUninstallationCausesCompletionEventOk() throws Exception {
DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl1", "bundleimpl1", "1.0.0")));
final AtomicReference<Event> completionEventRef = new AtomicReference<Event>();
final AtomicReference<Event> uninstallEventRef = new AtomicReference<Event>();
final CountDownLatch cdl = new CountDownLatch(2);
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_UNINSTALL.equals(event.getTopic())) {
assertTrue("Multiple events received?!", uninstallEventRef.compareAndSet(null, event));
cdl.countDown();
}
}
};
DeploymentPackage dp = installDeploymentPackage(dpBuilder);
assertNotNull(dp);
awaitRefreshPackagesEvent();
Dictionary props = new Properties();
props.put(EventConstants.EVENT_TOPIC, new String[] { Constants.EVENTTOPIC_COMPLETE, Constants.EVENTTOPIC_UNINSTALL });
ServiceRegistration sreg = m_context.registerService(EventHandler.class, eventHandler, props);
try {
dp.uninstall();
assertTrue("Not all events were received in time?!", cdl.await(5, TimeUnit.SECONDS));
Event event;
// Verify we've got the expected events...
event = uninstallEventRef.get();
assertNotNull("No uninstall event received?!", event);
event = completionEventRef.get();
assertNotNull("No completion event received?!", event);
assertTrue("Completion property set to false?!", Boolean.TRUE.equals(event.getProperty(Constants.EVENTPROPERTY_SUCCESSFUL)));
} finally {
sreg.unregister();
}
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class DeploymentAdminEventTest method testFailedUninstallationCausesCompletionEventOk.
/**
* FELIX-4466 - test that an event is fired when a DP is uninstalled, but fails.
*/
@Test
public void testFailedUninstallationCausesCompletionEventOk() 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")));
final AtomicReference<Event> completionEventRef = new AtomicReference<Event>();
final AtomicReference<Event> uninstallEventRef = new AtomicReference<Event>();
final CountDownLatch cdl = new CountDownLatch(2);
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_UNINSTALL.equals(event.getTopic())) {
assertTrue("Multiple events received?!", uninstallEventRef.compareAndSet(null, event));
cdl.countDown();
}
}
};
DeploymentPackage dp = installDeploymentPackage(dpBuilder);
assertNotNull("No deployment package returned?!", dp);
awaitRefreshPackagesEvent();
// Should cause the uninstall of the DP to fail...
dp.getBundle(getSymbolicName("rp1")).uninstall();
Dictionary props = new Properties();
props.put(EventConstants.EVENT_TOPIC, new String[] { Constants.EVENTTOPIC_COMPLETE, Constants.EVENTTOPIC_UNINSTALL });
ServiceRegistration sreg = m_context.registerService(EventHandler.class, eventHandler, props);
try {
dp.uninstall();
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 = uninstallEventRef.get();
assertNotNull("No uninstall 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();
}
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class DeploymentAdminTest method testUpdateConfigurationOk.
/**
* Tests that we can update the configuration of {@link DeploymentAdmin} at runtime. Based on the test case for FELIX-4184, see
* {@link org.apache.felix.deploymentadmin.itest.InstallFixPackageTest#testInstallAndUpdateImplementationBundleWithSeparateAPIBundle_FELIX4184()}
*/
@Test
public void testUpdateConfigurationOk() throws Exception {
System.setProperty("org.apache.felix.deploymentadmin.stopUnaffectedBundles", "false");
System.setProperty("org.apache.felix.deploymentadmin.allowForeignCustomizers", "false");
// This test case will only work if stopUnaffectedBundle is set to 'false'...
try {
// first, install a deployment package with implementation and api bundles in version 1.0.0
DeploymentPackageBuilder dpBuilder = createDeploymentPackageBuilder("a", "1.0.0");
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl1", "bundleimpl1", "1.0.0")));
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0")));
DeploymentPackage dp1 = installDeploymentPackage(dpBuilder);
assertNotNull("No deployment package returned?!", dp1);
assertEquals("Expected a single deployment package?!", 1, countDeploymentPackages());
// then, install a fix package with implementation and api bundles in version 2.0.0
dpBuilder = createDeploymentPackageBuilder("a", "2.0.0").setFixPackage("[1.0.0,2.0.0]");
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl2", "bundleimpl2", "2.0.0")));
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi2", "bundleapi2", "2.0.0")));
DeploymentPackage dp2 = installDeploymentPackage(dpBuilder);
assertNotNull("No deployment package returned?!", dp2);
awaitRefreshPackagesEvent();
assertBundleExists(getSymbolicName("bundleimpl"), "2.0.0");
assertBundleExists(getSymbolicName("bundleapi"), "2.0.0");
assertBundleNotExists(getSymbolicName("bundleimpl"), "1.0.0");
assertBundleNotExists(getSymbolicName("bundleapi"), "1.0.0");
} finally {
System.clearProperty("org.apache.felix.deploymentadmin.stopUnaffectedBundles");
System.clearProperty("org.apache.felix.deploymentadmin.allowForeignCustomizers");
}
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class DeploymentAdminTest method testBundleSymbolicNameMustMatchManifestEntry.
@Test
public void testBundleSymbolicNameMustMatchManifestEntry() throws Exception {
DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")).setFilter(new JarManifestManipulatingFilter("Bundle-SymbolicName", "foo")));
try {
installDeploymentPackage(dpBuilder);
fail("Succeeded into installing a bundle with a fake symbolic name?!");
} catch (DeploymentException exception) {
// Ok; expected...
assertDeploymentException(CODE_BUNDLE_NAME_ERROR, exception);
}
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class DeploymentAdminTest method testManifestEntryMustMatchBundleSymbolicName.
@Test
public void testManifestEntryMustMatchBundleSymbolicName() throws Exception {
DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setSymbolicName("foo").setUrl(getTestBundleURL("bundle2")));
try {
installDeploymentPackage(dpBuilder);
fail("Succeeded into installing a bundle with a fake symbolic name?!");
} catch (DeploymentException exception) {
// Ok; expected...
assertDeploymentException(CODE_BUNDLE_NAME_ERROR, exception);
}
}
Aggregations