changeset 1041:2359df39aa5a

Fix killvm-client-swing ActivatorTest The current ActivatorTest for killvm-client-swing is ignored. This commit replaces the test with one similar to activator tests used in other bundles. Reviewed-by: omajid, jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-March/006114.html
author Elliott Baron <ebaron@redhat.com>
date Wed, 20 Mar 2013 15:37:33 -0400
parents fd4f84176be8
children 40414c3e4f02
files killvm/client-swing/pom.xml killvm/client-swing/src/test/java/com/redhat/thermostat/killvm/client/internal/ActivatorTest.java
diffstat 2 files changed, 47 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/killvm/client-swing/pom.xml	Wed Mar 20 13:31:06 2013 -0400
+++ b/killvm/client-swing/pom.xml	Wed Mar 20 15:37:33 2013 -0400
@@ -100,5 +100,11 @@
     	<artifactId>thermostat-osgi-process-handler</artifactId>
     	<version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>com.redhat.thermostat</groupId>
+      <artifactId>thermostat-common-test</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>
--- a/killvm/client-swing/src/test/java/com/redhat/thermostat/killvm/client/internal/ActivatorTest.java	Wed Mar 20 13:31:06 2013 -0400
+++ b/killvm/client-swing/src/test/java/com/redhat/thermostat/killvm/client/internal/ActivatorTest.java	Wed Mar 20 15:37:33 2013 -0400
@@ -36,38 +36,56 @@
 
 package com.redhat.thermostat.killvm.client.internal;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.isA;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
 
-import java.util.Dictionary;
+import org.junit.Test;
 
-import org.junit.Ignore;
-import org.junit.Test;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-
+import com.redhat.thermostat.client.command.RequestQueue;
 import com.redhat.thermostat.client.ui.VMContextAction;
-import com.redhat.thermostat.killvm.client.internal.Activator;
-import com.redhat.thermostat.killvm.client.internal.KillVMAction;
+import com.redhat.thermostat.storage.dao.AgentInfoDAO;
+import com.redhat.thermostat.storage.dao.VmInfoDAO;
+import com.redhat.thermostat.testutils.StubBundleContext;
 
 public class ActivatorTest {
+    
+    @Test
+    public void verifyActivatorDoesNotRegisterServiceOnMissingDeps() throws Exception {
+        StubBundleContext context = new StubBundleContext();
 
-    @Ignore(value="testing activator is slightly more complex")
+        Activator activator = new Activator();
+
+        activator.start(context);
+
+        assertEquals(0, context.getAllServices().size());
+        assertNotSame(1, context.getServiceListeners().size());
+
+        activator.stop(context);
+    }
+
     @Test
-    public void startRegistersKillVMAction() throws Exception {
-        BundleContext ctx = mock(BundleContext.class);
-        ServiceRegistration serviceReg = mock(ServiceRegistration.class);
-        when(ctx.registerService(anyString(), any(), any(Dictionary.class)))
-                .thenReturn(serviceReg);
+    public void verifyActivatorRegistersServices() throws Exception {
+        StubBundleContext context = new StubBundleContext();
+        AgentInfoDAO agentInfoDAO = mock(AgentInfoDAO.class);
+        VmInfoDAO vmInfoDAO = mock(VmInfoDAO.class);
+        RequestQueue queue = mock(RequestQueue.class);
+
+        context.registerService(AgentInfoDAO.class, agentInfoDAO, null);
+        context.registerService(VmInfoDAO.class, vmInfoDAO, null);
+        context.registerService(RequestQueue.class, queue, null);
+
         Activator activator = new Activator();
-        activator.start(ctx);
-        verify(ctx).registerService(eq(VMContextAction.class.getName()),
-                isA(KillVMAction.class), any(Dictionary.class));
+
+        activator.start(context);
+
+        assertTrue(context.isServiceRegistered(VMContextAction.class.getName(), KillVMAction.class));
+
+        activator.stop(context);
+
+        assertEquals(0, context.getServiceListeners().size());
+        assertEquals(3, context.getAllServices().size());
     }
 
 }