aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Waibel2011-09-13 17:41:35 (EDT)
committerGlyn Normington2011-09-13 17:41:35 (EDT)
commit35a8cb0ea0125de205d8b02a769817c14ea5191b (patch)
treedfb1447101306eb6350e112f044e60d0e2e1daf8
parent0ac10943a03fd983086872437f1b52e4f8e418d3 (diff)
downloadorg.eclipse.virgo.kernel-35a8cb0ea0125de205d8b02a769817c14ea5191b.zip
org.eclipse.virgo.kernel-35a8cb0ea0125de205d8b02a769817c14ea5191b.tar.gz
org.eclipse.virgo.kernel-35a8cb0ea0125de205d8b02a769817c14ea5191b.tar.bz2
bug 357473: add tests
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifactTests.java136
1 files changed, 136 insertions, 0 deletions
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifactTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifactTests.java
new file mode 100644
index 0000000..6840aa7
--- /dev/null
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifactTests.java
@@ -0,0 +1,136 @@
+package org.eclipse.virgo.kernel.model.internal.deployer;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.notNull;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.install.artifact.BundleInstallArtifact;
+import org.eclipse.virgo.kernel.model.StubRegion;
+import org.eclipse.virgo.kernel.model.StubSpringContextAccessor;
+import org.eclipse.virgo.kernel.model.internal.DependencyDeterminer;
+import org.eclipse.virgo.kernel.model.internal.SpringContextAccessor;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+
+import org.eclipse.virgo.kernel.serviceability.Assert.FatalAssertionException;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+import org.eclipse.virgo.teststubs.osgi.support.TrueFilter;
+
+public class DeployerBundleArtifactTests {
+
+ private final StubBundleContext bundleContext = new StubBundleContext();
+ {
+ String filterString = String.format("(&(objectClass=%s)(artifactType=bundle))", DependencyDeterminer.class.getCanonicalName());
+ bundleContext.addFilter(filterString, new TrueFilter(filterString));
+ }
+
+ private final StubRegion region = new StubRegion("test-region");
+
+ private SpringContextAccessor springContextAccessor = new StubSpringContextAccessor();
+
+ @Test(expected = FatalAssertionException.class)
+ public void testNullBundleContext() {
+ BundleInstallArtifact installArtifact = createMock(BundleInstallArtifact.class);
+ new DeployerBundleArtifact(null, installArtifact, region, springContextAccessor);
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void testNullInstallArtifact() {
+ new DeployerBundleArtifact(bundleContext, null, region, springContextAccessor);
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void testNullRegion() {
+ BundleInstallArtifact installArtifact = createMock(BundleInstallArtifact.class);
+ new DeployerBundleArtifact(bundleContext, installArtifact, null, springContextAccessor);
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void testNullSpringContextAccessor() {
+ BundleInstallArtifact installArtifact = createMock(BundleInstallArtifact.class);
+ new DeployerBundleArtifact(bundleContext, installArtifact, region, null);
+ }
+
+ @Test
+ public void deleteEntry() throws DeploymentException {
+ BundleInstallArtifact installArtifact = createMock(BundleInstallArtifact.class);
+
+ expect(installArtifact.getType()).andReturn("bundle");
+ expect(installArtifact.getName()).andReturn("test-bundle");
+ expect(installArtifact.getVersion()).andReturn(new Version("1.0.0"));
+ installArtifact.deleteEntry("foo");
+ replay(installArtifact);
+
+ DeployerBundleArtifact artifact = new DeployerBundleArtifact(bundleContext, installArtifact, region, springContextAccessor);
+ artifact.deleteEntry("foo");
+
+ verify(installArtifact);
+ }
+
+ @Test
+ public void updateEntry() throws DeploymentException {
+ BundleInstallArtifact installArtifact = createMock(BundleInstallArtifact.class);
+
+ expect(installArtifact.getType()).andReturn("bundle");
+ expect(installArtifact.getName()).andReturn("test-bundle");
+ expect(installArtifact.getVersion()).andReturn(new Version("1.0.0"));
+ installArtifact.updateEntry((URI) notNull(), eq("bar"));
+ replay(installArtifact);
+
+ DeployerBundleArtifact artifact = new DeployerBundleArtifact(bundleContext, installArtifact, region, springContextAccessor);
+ artifact.updateEntry("foo", "bar");
+
+ verify(installArtifact);
+ }
+
+ @Test
+ public void getProperties() throws DeploymentException {
+ BundleInstallArtifact installArtifact = createMock(BundleInstallArtifact.class);
+
+ expect(installArtifact.getType()).andReturn("bundle");
+ expect(installArtifact.getName()).andReturn("test-bundle");
+ expect(installArtifact.getVersion()).andReturn(new Version("1.0.0"));
+ @SuppressWarnings("serial")
+ Set<String> names = new HashSet<String>() {{
+ add("foo");
+ add("bar");
+ add("deleted");
+ }};
+ expect(installArtifact.getPropertyNames()).andReturn(names);
+ expect(installArtifact.getProperty(eq("foo"))).andReturn("FOO");
+ expect(installArtifact.getProperty(eq("bar"))).andReturn("BAR");
+ expect(installArtifact.getProperty(eq("deleted"))).andReturn(null);
+ Bundle bundle = new StubBundle();
+ expect(installArtifact.getBundle()).andReturn(bundle);
+
+ SpringContextAccessor springContextAccessor = createMock(SpringContextAccessor.class);
+ expect(springContextAccessor.isSpringPowered((Bundle) notNull())).andReturn(true);
+
+ replay(installArtifact, springContextAccessor);
+
+ DeployerBundleArtifact artifact = new DeployerBundleArtifact(bundleContext, installArtifact, region, springContextAccessor);
+ Map<String, String> properties = artifact.getProperties();
+
+ assertEquals("null values should be omitted.", 4, properties.size());
+ assertEquals("FOO", properties.get("foo"));
+ assertEquals("BAR", properties.get("bar"));
+
+ assertEquals("" + bundle.getBundleId(), properties.get("Bundle Id"));
+ assertEquals("true", properties.get("Spring"));
+
+ verify(installArtifact, springContextAccessor);
+ }
+
+}