changeset 683:3dd95a7bfa9f

Add test for heapdumper bundle. This is to ensure the action works and the vm info service is registered appropriately. Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-October/003629.html
author Severin Gehwolf <sgehwolf@redhat.com>
date Tue, 09 Oct 2012 17:10:16 +0200
parents ab7cd3768b61
children c2f3b3b23e0a
files client/heapdumper/src/test/java/com/redhat/thermostat/client/heap/ServicesAvailableActionTest.java
diffstat 1 files changed, 89 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/heapdumper/src/test/java/com/redhat/thermostat/client/heap/ServicesAvailableActionTest.java	Tue Oct 09 17:10:16 2012 +0200
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2012 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.client.heap;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+
+import com.redhat.thermostat.client.core.VmInformationService;
+import com.redhat.thermostat.client.heap.Activator.ServicesAvailableAction;
+import com.redhat.thermostat.client.osgi.service.ApplicationService;
+import com.redhat.thermostat.common.dao.AgentInfoDAO;
+import com.redhat.thermostat.common.dao.HeapDAO;
+import com.redhat.thermostat.common.dao.VmMemoryStatDAO;
+import com.redhat.thermostat.test.StubBundleContext;
+
+public class ServicesAvailableActionTest {
+
+    @Test
+    public void verifyDepsAvailableRegistersVmInformationService() throws Exception {
+        StubBundleContext ctx = new StubBundleContext();
+        Activator activator = new Activator();
+        
+        activator.start(ctx);
+        
+        
+        
+        ServicesAvailableAction action = activator.getServiceAvailableAction();
+        ApplicationService appService = mock(ApplicationService.class);
+        AgentInfoDAO dao = mock(AgentInfoDAO.class);
+        VmMemoryStatDAO vmMemoryDao = mock(VmMemoryStatDAO.class);
+        HeapDAO heapDao = mock(HeapDAO.class);
+        Map<String, Object> services = new HashMap<>();
+        services.put(AgentInfoDAO.class.getName(), dao);
+        services.put(ApplicationService.class.getName(), appService);
+        services.put(VmMemoryStatDAO.class.getName(), vmMemoryDao);
+        services.put(HeapDAO.class.getName(), heapDao);
+        
+        action.dependenciesAvailable(services);
+        
+        assertTrue(ctx.isServiceRegistered(VmInformationService.class.getName(), HeapDumperService.class));
+        
+        // Interesting enought this comes back with all services listed in
+        // 1.) this bundles commands: META-IN/services/com.redhat.thermostat.common.cli.Command (7 Commands)
+        // 2.) commands provided by tools (6 commands)
+        // 3.) 3 more services, namely applicationService, AgentInfoDAO and the VmInformationService registered
+        //     by this bundle.
+        assertEquals(16, ctx.getAllServices().size());
+    }
+}