use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class DeploymentAdminEventTest method testSuccessfulInstallationCausesCompletionEventOk.
/**
* FELIX-4466 - test that an event is fired when an installation of a DP succeeds.
*/
@Test
public void testSuccessfulInstallationCausesCompletionEventOk() 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> installEventRef = 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_INSTALL.equals(event.getTopic())) {
assertTrue("Multiple events received?!", installEventRef.compareAndSet(null, event));
cdl.countDown();
}
}
};
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);
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();
assertNotNull("No install 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 DeploymentAdminTest method testBundleVersionMustMatchManifestEntry.
@Test
public void testBundleVersionMustMatchManifestEntry() 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-Version", "1.1.0")));
try {
installDeploymentPackage(dpBuilder);
fail("Succeeded into installing a bundle with a fake version?!");
} catch (DeploymentException exception) {
// Ok; expected...
assertDeploymentException(CODE_OTHER_ERROR, exception);
}
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class DeploymentAdminTest method testManifestEntryMustMatchBundleVersion.
@Test
public void testManifestEntryMustMatchBundleVersion() throws Exception {
DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setVersion("1.1.0").setUrl(getTestBundleURL("bundle2")));
try {
installDeploymentPackage(dpBuilder);
fail("Succeeded into installing a bundle with a fake version?!");
} catch (DeploymentException exception) {
// Ok; expected...
assertDeploymentException(CODE_OTHER_ERROR, exception);
}
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class DeploymentPackageBuilderTest method testCreateMissingBundleResourceOk.
/**
* Tests that we can build a deployment package with a bundle resource.
*/
@Test
public void testCreateMissingBundleResourceOk() throws Exception {
DeploymentPackageBuilder dpBuilder = DeploymentPackageBuilder.create("dp-test", "1.0.0");
dpBuilder.setFixPackage().add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle1")).setMissing());
JarInputStream jis = new JarInputStream(dpBuilder.generate());
assertNotNull(jis);
Manifest manifest = jis.getManifest();
assertManifestHeader(manifest, "DeploymentPackage-SymbolicName", "dp-test");
assertManifestHeader(manifest, "DeploymentPackage-Version", "1.0.0");
String filename = getBundleName("bundle1");
assertManifestEntry(manifest, filename, "Name", filename);
assertManifestEntry(manifest, filename, "Bundle-SymbolicName", "testbundles.bundle1");
assertManifestEntry(manifest, filename, "Bundle-Version", "1.0.0");
assertManifestEntry(manifest, filename, "DeploymentPackage-Missing", "true");
int count = countJarEntries(jis);
assertEquals("Expected two entries in the JAR!", 0, count);
}
use of org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder in project felix by apache.
the class DeploymentPackageBuilderTest method testResourceFilterOk.
/**
* Tests that we can filter a resource.
*/
@Test
public void testResourceFilterOk() throws Exception {
DeploymentPackageBuilder dpBuilder = DeploymentPackageBuilder.create("dp-test", "1.0.0");
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundle("bundle2"))).add(dpBuilder.createBundleResource().setVersion("1.1.0").setFilter(new JarManifestManipulatingFilter("Bundle-Version", "1.1.0", "Foo", "bar")).setUrl(getTestBundle("bundle1")));
JarInputStream jis = new JarInputStream(dpBuilder.generate());
assertNotNull(jis);
Manifest manifest = jis.getManifest();
assertManifestHeader(manifest, "DeploymentPackage-SymbolicName", "dp-test");
assertManifestHeader(manifest, "DeploymentPackage-Version", "1.0.0");
String filename = getBundleName("bundle1");
assertManifestEntry(manifest, filename, "Name", filename);
assertManifestEntry(manifest, filename, "Bundle-SymbolicName", "testbundles.bundle1");
assertManifestEntry(manifest, filename, "Bundle-Version", "1.1.0");
filename = getBundleName("bundle2");
assertManifestEntry(manifest, filename, "Name", filename);
assertManifestEntry(manifest, filename, "Bundle-SymbolicName", "testbundles.bundle2");
assertManifestEntry(manifest, filename, "Bundle-Version", "1.0.0");
try {
byte[] buf = new byte[32 * 1024];
JarEntry entry;
while ((entry = jis.getNextJarEntry()) != null) {
if (entry.getName().endsWith("valid-bundle1.jar")) {
int read = jis.read(buf);
JarInputStream jis2 = new JarInputStream(new ByteArrayInputStream(Arrays.copyOf(buf, read)));
Manifest manifest2 = jis2.getManifest();
Attributes mainAttributes = manifest2.getMainAttributes();
assertEquals("1.1.0", mainAttributes.getValue("Bundle-Version"));
assertEquals("bar", mainAttributes.getValue("Foo"));
jis2.close();
}
jis.closeEntry();
}
} finally {
jis.close();
}
}
Aggregations