# HG changeset patch # User Elliott Baron # Date 1363808253 14400 # Node ID 2359df39aa5a275d5ed8c00541d6fb2bcde523dd # Parent fd4f84176be80ee04d1ba6e5cf1148fb6405ea16 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 diff -r fd4f84176be8 -r 2359df39aa5a killvm/client-swing/pom.xml --- 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 @@ thermostat-osgi-process-handler ${project.version} + + com.redhat.thermostat + thermostat-common-test + ${project.version} + test + diff -r fd4f84176be8 -r 2359df39aa5a killvm/client-swing/src/test/java/com/redhat/thermostat/killvm/client/internal/ActivatorTest.java --- 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()); } }