summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Waibel2011-09-13 18:26:49 (EDT)
committer Glyn Normington2011-09-13 18:26:49 (EDT)
commit28633df0f7973d13e74a2d02c250c0263962a6db (patch)
treebf83aa619a342913b0c7a98818380865aae0a235
parent35a8cb0ea0125de205d8b02a769817c14ea5191b (diff)
downloadorg.eclipse.virgo.kernel-28633df0f7973d13e74a2d02c250c0263962a6db.zip
org.eclipse.virgo.kernel-28633df0f7973d13e74a2d02c250c0263962a6db.tar.gz
org.eclipse.virgo.kernel-28633df0f7973d13e74a2d02c250c0263962a6db.tar.bz2
bug 357473: add tests
-rw-r--r--org.eclipse.virgo.kernel.model/.classpath6
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerArtifactTests.java94
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DefaultArtifactObjectNameCreatorTests.java29
3 files changed, 124 insertions, 5 deletions
diff --git a/org.eclipse.virgo.kernel.model/.classpath b/org.eclipse.virgo.kernel.model/.classpath
index fb0b20d..b9dadd6 100644
--- a/org.eclipse.virgo.kernel.model/.classpath
+++ b/org.eclipse.virgo.kernel.model/.classpath
@@ -38,7 +38,11 @@
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.virgo.kernel.osgi"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.virgo.kernel.artifact"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.virgo.kernel.deployer"/>
- <classpathentry kind="src" path="/org.eclipse.virgo.kernel.core"/>
+ <classpathentry kind="src" path="/org.eclipse.virgo.kernel.core">
+ <attributes>
+ <attribute name="org.eclipse.ajdt.aspectpath" value="org.eclipse.ajdt.aspectpath"/>
+ </attributes>
+ </classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.virgo.kernel.stubs"/>
<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.springframework/org.springframework.context/3.0.5.RELEASE/org.springframework.context-3.0.5.RELEASE.jar" sourcepath="/KERNEL_IVY_CACHE/org.springframework/org.springframework.context/3.0.5.RELEASE/org.springframework.context-sources-3.0.5.RELEASE.jar"/>
<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.region/1.0.0.v20110503/org.eclipse.equinox.region-1.0.0.v20110503.jar"/>
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerArtifactTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerArtifactTests.java
index c66cf52..ed1e978 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerArtifactTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerArtifactTests.java
@@ -12,14 +12,23 @@
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.expectLastCall;
+import static org.easymock.EasyMock.getCurrentArguments;
+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.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import org.junit.Test;
import org.osgi.framework.Version;
+import org.easymock.IAnswer;
import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
import org.eclipse.virgo.kernel.install.artifact.InstallArtifact.State;
import org.eclipse.virgo.kernel.model.ArtifactState;
@@ -28,6 +37,7 @@ import org.eclipse.virgo.kernel.model.internal.DependencyDeterminer;
import org.eclipse.virgo.kernel.model.internal.deployer.DeployerArtifact;
+import org.eclipse.virgo.kernel.core.AbortableSignal;
import org.eclipse.virgo.kernel.core.KernelException;
import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
import org.eclipse.virgo.kernel.serviceability.Assert.FatalAssertionException;
@@ -99,13 +109,63 @@ public class DeployerArtifactTests {
}
@Test
- public void start() throws KernelException {
- this.artifact.start();
+ public void startSuccessful() throws KernelException, DeploymentException {
+ InstallArtifact installArtifact = createMock(InstallArtifact.class);
+
+ expect(installArtifact.getType()).andReturn("bundle");
+ expect(installArtifact.getName()).andReturn("test-bundle");
+ expect(installArtifact.getVersion()).andReturn(new Version("1.0.0"));
+ installArtifact.start((AbortableSignal) notNull());
+ expectLastCall().andAnswer(new IAnswer<Object>() {
+ public Object answer() {
+ AbortableSignal signal = (AbortableSignal) getCurrentArguments()[0];
+ signal.signalSuccessfulCompletion();
+ return null;
+ }
+ });
+ replay(installArtifact);
+
+ DeployerArtifact artifact = new DeployerArtifact(bundleContext, installArtifact, region);
+ artifact.start();
+
+ verify(installArtifact);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void startAborted() throws KernelException, DeploymentException {
+ InstallArtifact installArtifact = createMock(InstallArtifact.class);
+
+ expect(installArtifact.getType()).andReturn("bundle");
+ expect(installArtifact.getName()).andReturn("test-bundle");
+ expect(installArtifact.getVersion()).andReturn(new Version("1.0.0"));
+ installArtifact.start((AbortableSignal) notNull());
+ expectLastCall().andAnswer(new IAnswer<Object>() {
+ public Object answer() {
+ AbortableSignal signal = (AbortableSignal) getCurrentArguments()[0];
+ signal.signalAborted();
+ return null;
+ }
+ });
+ replay(installArtifact);
+
+ DeployerArtifact artifact = new DeployerArtifact(bundleContext, installArtifact, region);
+ artifact.start();
}
@Test
public void stop() throws DeploymentException {
- this.artifact.stop();
+ InstallArtifact installArtifact = createMock(InstallArtifact.class);
+
+ expect(installArtifact.getType()).andReturn("bundle");
+ expect(installArtifact.getName()).andReturn("test-bundle");
+ expect(installArtifact.getVersion()).andReturn(new Version("1.0.0"));
+ installArtifact.stop();
+ replay(installArtifact);
+
+ DeployerArtifact artifact = new DeployerArtifact(bundleContext, installArtifact, region);
+ artifact.stop();
+
+ verify(installArtifact);
}
@Test
@@ -120,6 +180,32 @@ public class DeployerArtifactTests {
@Test
public void getProperties() throws DeploymentException {
- this.artifact.getProperties();
+ InstallArtifact installArtifact = createMock(InstallArtifact.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);
+
+ replay(installArtifact);
+
+ DeployerArtifact artifact = new DeployerArtifact(bundleContext, installArtifact, region);
+ Map<String, String> properties = artifact.getProperties();
+
+ assertEquals("null values should be omitted.", 2, properties.size());
+ assertEquals("FOO", properties.get("foo"));
+ assertEquals("BAR", properties.get("bar"));
+
+ verify(installArtifact);
}
+
}
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DefaultArtifactObjectNameCreatorTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DefaultArtifactObjectNameCreatorTests.java
index 19c974f..ccfadcf 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DefaultArtifactObjectNameCreatorTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DefaultArtifactObjectNameCreatorTests.java
@@ -49,4 +49,33 @@ public class DefaultArtifactObjectNameCreatorTests {
assertNotNull(objectName);
assertEquals("test-domain:artifact-type=test-type,name=test-name,region=test-region,type=ArtifactModel,version=0.0.0", objectName.getCanonicalName());
}
+
+ @Test
+ public void createArtifactsOfTypeQuery() throws Exception {
+ ObjectName artifactsOfTypeQuery = creator.createArtifactsOfTypeQuery("test-type");
+ assertNotNull(artifactsOfTypeQuery);
+ assertEquals("test-domain:artifact-type=test-type,type=Model,*", artifactsOfTypeQuery.getCanonicalName());
+ }
+
+ @Test
+ public void artifactsQuery() throws Exception {
+ ObjectName artifactsQuery = creator.createArtifactsQuery();
+ assertNotNull(artifactsQuery);
+ assertEquals("test-domain:type=Model,*", artifactsQuery.getCanonicalName());
+ }
+
+ @Test
+ public void artifactVersionQuery() throws Exception {
+ ObjectName artifactsVersionQuery = creator.createArtifactVersionsQuery("test-type", "test-name");
+ assertNotNull(artifactsVersionQuery);
+ assertEquals("test-domain:artifact-type=test-type,name=test-name,type=Model,*", artifactsVersionQuery.getCanonicalName());
+ }
+
+ @Test
+ public void allArtifactsQuery() throws Exception {
+ ObjectName artifactsQuery = creator.createAllArtifactsQuery();
+ assertNotNull(artifactsQuery);
+ assertEquals("test-domain:type=*Model,*", artifactsQuery.getCanonicalName());
+ }
+
}