changeset 700:1dd0ea9aa8b4

Merge
author Roman Kennke <rkennke@redhat.com>
date Thu, 18 Oct 2012 00:25:04 +0200
parents 0daa5cf25aec (current diff) a31b9467af11 (diff)
children cf01b2bc4f4a 77998c10737b
files
diffstat 18 files changed, 59 insertions(+), 115 deletions(-) [+]
line wrap: on
line diff
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/AgentApplication.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/AgentApplication.java	Thu Oct 18 00:25:04 2012 +0200
@@ -102,7 +102,6 @@
 
         StorageProvider connProv = new MongoStorageProvider(configuration);
         final DAOFactory daoFactory = new MongoDAOFactory(connProv);
-        ApplicationContext.getInstance().setDAOFactory(daoFactory);
         TimerFactory timerFactory = new ThreadPoolTimerFactory(1);
         ApplicationContext.getInstance().setTimerFactory(timerFactory);
 
@@ -139,13 +138,13 @@
 
         BackendRegistry backendRegistry = null;
         try {
-            backendRegistry = new BackendRegistry(configuration);
+            backendRegistry = new BackendRegistry(configuration, daoFactory);
         } catch (BackendLoadException ble) {
             logger.log(Level.SEVERE, "Could not get BackendRegistry instance.", ble);
             System.exit(Constants.EXIT_BACKEND_LOAD_ERROR);
         }
 
-        final Agent agent = new Agent(backendRegistry, configuration, daoFactory, daoFactory.getAgentInfoDAO(), daoFactory.getBackendInfoDAO());
+        final Agent agent = new Agent(backendRegistry, configuration, daoFactory.getStorage(), daoFactory.getAgentInfoDAO(), daoFactory.getBackendInfoDAO());
         try {
             logger.fine("Starting agent.");
             agent.start();
--- a/agent/core/src/main/java/com/redhat/thermostat/agent/Agent.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/agent/core/src/main/java/com/redhat/thermostat/agent/Agent.java	Thu Oct 18 00:25:04 2012 +0200
@@ -47,7 +47,6 @@
 import com.redhat.thermostat.common.LaunchException;
 import com.redhat.thermostat.common.dao.AgentInfoDAO;
 import com.redhat.thermostat.common.dao.BackendInfoDAO;
-import com.redhat.thermostat.common.dao.DAOFactory;
 import com.redhat.thermostat.common.model.AgentInformation;
 import com.redhat.thermostat.common.model.BackendInformation;
 import com.redhat.thermostat.common.storage.Storage;
@@ -73,15 +72,15 @@
     private BackendInfoDAO backendDao;
     private boolean started = false;
 
-    public Agent(BackendRegistry backendRegistry, AgentStartupConfiguration config, DAOFactory daos, AgentInfoDAO agentDao, BackendInfoDAO backendDao) {
-        this(backendRegistry, UUID.randomUUID(), config, daos, agentDao, backendDao);
+    public Agent(BackendRegistry backendRegistry, AgentStartupConfiguration config, Storage storage, AgentInfoDAO agentDao, BackendInfoDAO backendDao) {
+        this(backendRegistry, UUID.randomUUID(), config, storage, agentDao, backendDao);
     }
 
-    public Agent(BackendRegistry registry, UUID agentId, AgentStartupConfiguration config, DAOFactory daos, AgentInfoDAO agentDao, BackendInfoDAO backendDao) {
+    public Agent(BackendRegistry registry, UUID agentId, AgentStartupConfiguration config, Storage storage, AgentInfoDAO agentDao, BackendInfoDAO backendDao) {
         this.id = agentId;
         this.backendRegistry = registry;
         this.config = config;
-        this.storage = daos.getStorage();
+        this.storage = storage;
         this.storage.setAgentId(agentId);
         this.agentDao = agentDao;
         this.backendDao = backendDao;
--- a/agent/core/src/main/java/com/redhat/thermostat/backend/BackendRegistry.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/agent/core/src/main/java/com/redhat/thermostat/backend/BackendRegistry.java	Thu Oct 18 00:25:04 2012 +0200
@@ -45,7 +45,6 @@
 import java.util.logging.Logger;
 
 import com.redhat.thermostat.agent.config.AgentStartupConfiguration;
-import com.redhat.thermostat.common.appctx.ApplicationContext;
 import com.redhat.thermostat.common.dao.DAOFactory;
 import com.redhat.thermostat.common.utils.LoggingUtils;
 
@@ -59,18 +58,16 @@
 
     private final Map<String, Backend> registeredBackends;
 
-    public BackendRegistry(AgentStartupConfiguration config) throws BackendLoadException {
-        this(config, new BackendConfigurationLoader());
+    public BackendRegistry(AgentStartupConfiguration config, DAOFactory daoFactory) throws BackendLoadException {
+        this(config, new BackendConfigurationLoader(), daoFactory);
     }
 
-    public BackendRegistry(AgentStartupConfiguration config, BackendConfigurationLoader backendConfigLoader) throws BackendLoadException {
+    public BackendRegistry(AgentStartupConfiguration config, BackendConfigurationLoader backendConfigLoader, DAOFactory daoFactory) throws BackendLoadException {
 
         registeredBackends = new HashMap<String, Backend>();
         
         List<BackendID> backends = config.getBackends();
 
-        DAOFactory df = ApplicationContext.getInstance().getDAOFactory();
-        
         /*
          * Configure the dynamic/custom backends
          */
@@ -83,7 +80,7 @@
                 Constructor<? extends Backend> backendConstructor = narrowed.getConstructor();
                 backend = backendConstructor.newInstance();
 
-                backend.setDAOFactory(df);
+                backend.setDAOFactory(daoFactory);
                 backend.setID(backendID);
                 
                 backend.setInitialConfiguration(backendConfigLoader.retrieveBackendConfigs(backend.getName()));
--- a/agent/core/src/main/java/com/redhat/thermostat/backend/system/JvmStatVmClassListener.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/agent/core/src/main/java/com/redhat/thermostat/backend/system/JvmStatVmClassListener.java	Thu Oct 18 00:25:04 2012 +0200
@@ -45,7 +45,6 @@
 import sun.jvmstat.monitor.event.VmEvent;
 import sun.jvmstat.monitor.event.VmListener;
 
-import com.redhat.thermostat.common.dao.DAOFactory;
 import com.redhat.thermostat.common.dao.VmClassStatDAO;
 import com.redhat.thermostat.common.model.VmClassStat;
 import com.redhat.thermostat.common.utils.LoggingUtils;
--- a/agent/core/src/test/java/com/redhat/thermostat/agent/AgentTest.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/agent/core/src/test/java/com/redhat/thermostat/agent/AgentTest.java	Thu Oct 18 00:25:04 2012 +0200
@@ -58,7 +58,6 @@
 import com.redhat.thermostat.backend.BackendRegistry;
 import com.redhat.thermostat.common.dao.AgentInfoDAO;
 import com.redhat.thermostat.common.dao.BackendInfoDAO;
-import com.redhat.thermostat.common.dao.DAOFactory;
 import com.redhat.thermostat.common.model.AgentInformation;
 import com.redhat.thermostat.common.model.BackendInformation;
 import com.redhat.thermostat.common.storage.Storage;
@@ -70,7 +69,6 @@
     private Backend backend;
 
     private Storage storage;
-    private DAOFactory daos;
     private AgentInfoDAO agentInfoDao;
     private BackendInfoDAO backendInfoDao;
     
@@ -83,8 +81,6 @@
         storage = mock(Storage.class);
         agentInfoDao = mock(AgentInfoDAO.class);
         backendInfoDao = mock(BackendInfoDAO.class);
-        daos = mock(DAOFactory.class);
-        when(daos.getStorage()).thenReturn(storage);
         
         backend = mock(Backend.class);
         when(backend.getName()).thenReturn("testname");
@@ -102,7 +98,7 @@
     public void testStartAgent() throws Exception {
         
         // Start agent.
-        Agent agent = new Agent(backendRegistry, config, daos, agentInfoDao, backendInfoDao);
+        Agent agent = new Agent(backendRegistry, config, storage, agentInfoDao, backendInfoDao);
         agent.start();
 
         // Verify that backend has been activated and storage received the agent information.
@@ -128,7 +124,7 @@
     
     @Test
     public void testStopAgentWithPurging() throws Exception {
-        Agent agent = new Agent(backendRegistry, config, daos, agentInfoDao, backendInfoDao);
+        Agent agent = new Agent(backendRegistry, config, storage, agentInfoDao, backendInfoDao);
         agent.start();
         
         // stop agent
@@ -148,7 +144,7 @@
         when(config.getStartTime()).thenReturn(123L);
         when(config.purge()).thenReturn(false);
         
-        Agent agent = new Agent(backendRegistry, config, daos, agentInfoDao, backendInfoDao);
+        Agent agent = new Agent(backendRegistry, config, storage, agentInfoDao, backendInfoDao);
         agent.start();
         
         // stop agent
--- a/agent/core/src/test/java/com/redhat/thermostat/backend/BackendRegistryTest.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/agent/core/src/test/java/com/redhat/thermostat/backend/BackendRegistryTest.java	Thu Oct 18 00:25:04 2012 +0200
@@ -51,7 +51,6 @@
 import org.junit.Test;
 
 import com.redhat.thermostat.agent.config.AgentStartupConfiguration;
-import com.redhat.thermostat.common.appctx.ApplicationContext;
 import com.redhat.thermostat.common.config.InvalidConfigurationException;
 import com.redhat.thermostat.common.dao.DAOFactory;
 import com.redhat.thermostat.common.storage.Storage;
@@ -90,6 +89,7 @@
         }
     }
 
+    private DAOFactory daoFactory;
     private List<BackendID> backends;
     private AgentStartupConfiguration config;
     private BackendConfigurationLoader configLoader;
@@ -105,9 +105,8 @@
         when(configLoader.retrieveBackendConfigs(any(String.class))).thenReturn(new HashMap<String,String>());
 
         Storage storage = mock(Storage.class);
-        DAOFactory df = mock(DAOFactory.class);
-        when(df.getStorage()).thenReturn(storage);
-        ApplicationContext.getInstance().setDAOFactory(df);
+        daoFactory = mock(DAOFactory.class);
+        when(daoFactory.getStorage()).thenReturn(storage);
     }
 
     @After
@@ -122,14 +121,14 @@
         /* setup fake backend */
         backends.add(new BackendID("mock", MockBackend.class.getName()));
 
-        BackendRegistry registry = new BackendRegistry(config, configLoader);
+        BackendRegistry registry = new BackendRegistry(config, configLoader, daoFactory);
         assertEquals(1, registry.getAll().size());
         assertNotNull(registry.getByName("mock"));
     }
 
     @Test
     public void testNoBackendsRegistered() throws InvalidConfigurationException, BackendLoadException {
-        BackendRegistry registry = new BackendRegistry(config, configLoader);
+        BackendRegistry registry = new BackendRegistry(config, configLoader, daoFactory);
         assertEquals(0, registry.getAll().size());
         assertEquals(null, registry.getByName("system"));
         assertEquals(null, registry.getByName("mock"));
@@ -143,7 +142,7 @@
         backends.add(new BackendID("mock", MockBackend.class.getClass().getName()));
 
         /* load the backends */
-        new BackendRegistry(config, configLoader);
+        new BackendRegistry(config, configLoader, daoFactory);
     }
 
 }
--- a/agent/core/src/test/java/com/redhat/thermostat/backend/system/JvmStatVmClassListenerTest.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/agent/core/src/test/java/com/redhat/thermostat/backend/system/JvmStatVmClassListenerTest.java	Thu Oct 18 00:25:04 2012 +0200
@@ -48,7 +48,6 @@
 import sun.jvmstat.monitor.MonitoredVm;
 import sun.jvmstat.monitor.event.VmEvent;
 
-import com.redhat.thermostat.common.dao.DAOFactory;
 import com.redhat.thermostat.common.dao.VmClassStatDAO;
 import com.redhat.thermostat.common.model.VmClassStat;
 
--- a/client/core/src/main/java/com/redhat/thermostat/client/internal/Main.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/client/core/src/main/java/com/redhat/thermostat/client/internal/Main.java	Thu Oct 18 00:25:04 2012 +0200
@@ -85,6 +85,7 @@
     private static final Logger logger = LoggingUtils.getLogger(Main.class);
 
     private UiFacadeFactory uiFacadeFactory;
+    private DAOFactory daoFactory;
     
     public Main(Keyring keyring, UiFacadeFactory uiFacadeFactory, String[] args) {
         this.uiFacadeFactory = uiFacadeFactory;
@@ -131,8 +132,7 @@
         StartupConfiguration config = new ConnectionConfiguration(prefs);
 
         StorageProvider connProv = new MongoStorageProvider(config);
-        DAOFactory daoFactory = new MongoDAOFactory(connProv);
-        ApplicationContext.getInstance().setDAOFactory(daoFactory);
+        daoFactory = new MongoDAOFactory(connProv);
         TimerFactory timerFactory = new ThreadPoolTimerFactory(1);
         ApplicationContext.getInstance().setTimerFactory(timerFactory);
     }
@@ -155,7 +155,7 @@
         @Override
         public void run() {
             
-            Connection connection = ApplicationContext.getInstance().getDAOFactory().getConnection();
+            Connection connection = daoFactory.getConnection();
             connection.setType(ConnectionType.LOCAL);
             ConnectionListener connectionListener = new ConnectionHandler(connection, service);
             connection.addListener(connectionListener);
@@ -280,8 +280,6 @@
             if (newStatus == ConnectionStatus.CONNECTED) {
                 
                 // register the storage, so other services can request it
-                DAOFactory daoFactory = ApplicationContext.getInstance().getDAOFactory();
-
                 daoFactory.registerDAOsAndStorageAsOSGiServices();
                 uiFacadeFactory.setHostInfoDao(daoFactory.getHostInfoDAO());
                 uiFacadeFactory.setCpuStatDao(daoFactory.getCpuStatDAO());
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/HostCpuController.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/HostCpuController.java	Thu Oct 18 00:25:04 2012 +0200
@@ -52,7 +52,6 @@
 import com.redhat.thermostat.common.Timer.SchedulingType;
 import com.redhat.thermostat.common.appctx.ApplicationContext;
 import com.redhat.thermostat.common.dao.CpuStatDAO;
-import com.redhat.thermostat.common.dao.DAOFactory;
 import com.redhat.thermostat.common.dao.HostInfoDAO;
 import com.redhat.thermostat.common.dao.HostRef;
 import com.redhat.thermostat.common.locale.Translate;
@@ -78,7 +77,6 @@
         this.ref = ref;
         view = provider.createView();
         view.clearCpuUsageData();
-        DAOFactory daos = ApplicationContext.getInstance().getDAOFactory();
         this.hostInfoDAO = hostInfoDao;
         this.cpuStatDAO = cpuStatDAO;
 
--- a/client/core/src/test/java/com/redhat/thermostat/client/ui/AgentInformationDisplayModelTest.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/client/core/src/test/java/com/redhat/thermostat/client/ui/AgentInformationDisplayModelTest.java	Thu Oct 18 00:25:04 2012 +0200
@@ -42,15 +42,11 @@
 
 import java.util.Arrays;
 
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.redhat.thermostat.common.appctx.ApplicationContext;
-import com.redhat.thermostat.common.appctx.ApplicationContextUtil;
 import com.redhat.thermostat.common.dao.AgentInfoDAO;
 import com.redhat.thermostat.common.dao.BackendInfoDAO;
-import com.redhat.thermostat.common.dao.DAOFactory;
 import com.redhat.thermostat.common.model.AgentInformation;
 
 public class AgentInformationDisplayModelTest {
--- a/client/core/src/test/java/com/redhat/thermostat/client/ui/HostCpuControllerTest.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/client/core/src/test/java/com/redhat/thermostat/client/ui/HostCpuControllerTest.java	Thu Oct 18 00:25:04 2012 +0200
@@ -66,7 +66,6 @@
 import com.redhat.thermostat.common.appctx.ApplicationContext;
 import com.redhat.thermostat.common.appctx.ApplicationContextUtil;
 import com.redhat.thermostat.common.dao.CpuStatDAO;
-import com.redhat.thermostat.common.dao.DAOFactory;
 import com.redhat.thermostat.common.dao.HostInfoDAO;
 import com.redhat.thermostat.common.dao.HostRef;
 import com.redhat.thermostat.common.model.CpuStat;
--- a/client/core/src/test/java/com/redhat/thermostat/client/ui/VmCpuControllerTest.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/client/core/src/test/java/com/redhat/thermostat/client/ui/VmCpuControllerTest.java	Thu Oct 18 00:25:04 2012 +0200
@@ -58,8 +58,6 @@
 import com.redhat.thermostat.common.TimerFactory;
 import com.redhat.thermostat.common.appctx.ApplicationContext;
 import com.redhat.thermostat.common.appctx.ApplicationContextUtil;
-import com.redhat.thermostat.common.dao.DAOFactory;
-import com.redhat.thermostat.common.dao.MongoDAOFactory;
 import com.redhat.thermostat.common.dao.VmCpuStatDAO;
 import com.redhat.thermostat.common.dao.VmRef;
 import com.redhat.thermostat.common.model.VmCpuStat;
--- a/client/heapdumper/src/test/java/com/redhat/thermostat/client/heap/cli/ListHeapDumpsCommandTest.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/client/heapdumper/src/test/java/com/redhat/thermostat/client/heap/cli/ListHeapDumpsCommandTest.java	Thu Oct 18 00:25:04 2012 +0200
@@ -54,12 +54,10 @@
 import org.junit.Ignore;
 import org.junit.Test;
 
-import com.redhat.thermostat.common.appctx.ApplicationContext;
 import com.redhat.thermostat.common.appctx.ApplicationContextUtil;
 import com.redhat.thermostat.common.cli.Command;
 import com.redhat.thermostat.common.cli.CommandException;
 import com.redhat.thermostat.common.cli.SimpleArguments;
-import com.redhat.thermostat.common.dao.DAOFactory;
 import com.redhat.thermostat.common.dao.HeapDAO;
 import com.redhat.thermostat.common.dao.HostInfoDAO;
 import com.redhat.thermostat.common.dao.HostRef;
--- a/common/core/src/main/java/com/redhat/thermostat/common/appctx/ApplicationContext.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/common/core/src/main/java/com/redhat/thermostat/common/appctx/ApplicationContext.java	Thu Oct 18 00:25:04 2012 +0200
@@ -37,14 +37,11 @@
 package com.redhat.thermostat.common.appctx;
 
 import com.redhat.thermostat.common.TimerFactory;
-import com.redhat.thermostat.common.dao.DAOFactory;
 
 public class ApplicationContext {
 
     private static ApplicationContext instance = new ApplicationContext();
 
-    private DAOFactory daoFactory;
-
     private TimerFactory timerFactory;
 
     public static ApplicationContext getInstance() {
@@ -60,14 +57,6 @@
         // the factory method.
     }
 
-    public void setDAOFactory(DAOFactory daoFactory) {
-        this.daoFactory = daoFactory;
-    }
-
-    public DAOFactory getDAOFactory() {
-        return daoFactory;
-    }
-
     public void setTimerFactory(TimerFactory timerFactory) {
         this.timerFactory = timerFactory;
     }
--- a/common/core/src/test/java/com/redhat/thermostat/common/appctx/ApplicationContextTest.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/common/core/src/test/java/com/redhat/thermostat/common/appctx/ApplicationContextTest.java	Thu Oct 18 00:25:04 2012 +0200
@@ -45,7 +45,6 @@
 
 import com.redhat.thermostat.common.TimerFactory;
 import com.redhat.thermostat.common.appctx.ApplicationContext;
-import com.redhat.thermostat.common.dao.DAOFactory;
 
 public class ApplicationContextTest {
 
@@ -66,35 +65,6 @@
     }
 
     @Test
-    public void  testDAOFactorySetGet() {
-        DAOFactory daoFactory = mock(DAOFactory.class);
-        ApplicationContext ctx = ApplicationContext.getInstance();
-        ctx.setDAOFactory(daoFactory);
-
-        DAOFactory actual1 = ctx.getDAOFactory();
-        assertSame(daoFactory, actual1);
-    }
-
-    @Test
-    public void  verifyDAOFactoryIsNullWhenNotInitialized() {
-        ApplicationContext ctx = ApplicationContext.getInstance();
-
-        DAOFactory actual = ctx.getDAOFactory();
-        assertNull(actual);
-    }
-
-    @Test
-    public void  verifyDAOFactoryStaysSame() {
-        DAOFactory daoFactory = mock(DAOFactory.class);
-        ApplicationContext ctx = ApplicationContext.getInstance();
-        ctx.setDAOFactory(daoFactory);
-
-        ApplicationContext ctx2 = ApplicationContext.getInstance();
-        DAOFactory actual2 = ctx2.getDAOFactory();
-        assertSame(daoFactory, actual2);
-    }
-
-    @Test
     public void  testTimerFactorySetGet() {
         TimerFactory timerFactory = mock(TimerFactory.class);
         ApplicationContext ctx = ApplicationContext.getInstance();
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/DbServiceImpl.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/DbServiceImpl.java	Thu Oct 18 00:25:04 2012 +0200
@@ -40,48 +40,34 @@
 
 import org.osgi.framework.ServiceRegistration;
 
-import com.redhat.thermostat.common.appctx.ApplicationContext;
-import com.redhat.thermostat.common.config.StartupConfiguration;
 import com.redhat.thermostat.common.dao.DAOFactory;
 import com.redhat.thermostat.common.dao.MongoDAOFactory;
-import com.redhat.thermostat.common.storage.Connection;
 import com.redhat.thermostat.common.storage.ConnectionException;
 import com.redhat.thermostat.common.storage.MongoStorageProvider;
-import com.redhat.thermostat.common.storage.StorageProvider;
 import com.redhat.thermostat.launcher.DbService;
 
 public class DbServiceImpl implements DbService {
     
-    private String username;
-    private String password;
-    private String dbUrl;
     @SuppressWarnings("rawtypes")
     private ServiceRegistration registration;
     
+    private DAOFactory daoFactory;
     
     DbServiceImpl(String username, String password, String dbUrl) {
-        this.username = username;
-        this.password = password;
-        this.dbUrl = dbUrl;
+        this(new MongoDAOFactory(new MongoStorageProvider(new ConnectionConfiguration(dbUrl, username, password))));
+    }
+
+    DbServiceImpl(DAOFactory daoFactory) {
+        this.daoFactory = daoFactory;
     }
 
     public void connect() throws ConnectionException {
-        StartupConfiguration config = new ConnectionConfiguration(dbUrl, username, password);
-        
-        StorageProvider connProv = new MongoStorageProvider(config);
-        DAOFactory daoFactory = new MongoDAOFactory(connProv);
-        Connection connection = daoFactory.getConnection();
-        connection.connect();
-        ApplicationContext.getInstance().setDAOFactory(daoFactory);
-
+        daoFactory.getConnection().connect();
         daoFactory.registerDAOsAndStorageAsOSGiServices();
     }
     
     public void disconnect() throws ConnectionException {
-        DAOFactory factory = ApplicationContext.getInstance().getDAOFactory();
-        Connection connection = factory.getConnection();
-        connection.disconnect();
-        ApplicationContext.getInstance().setDAOFactory(null);
+        daoFactory.getConnection().disconnect();
     }
     
     /**
--- a/launcher/src/test/java/com/redhat/thermostat/launcher/internal/DbServiceTest.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/launcher/src/test/java/com/redhat/thermostat/launcher/internal/DbServiceTest.java	Thu Oct 18 00:25:04 2012 +0200
@@ -37,21 +37,32 @@
 package com.redhat.thermostat.launcher.internal;
 
 import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.redhat.thermostat.common.dao.DAOFactory;
+import com.redhat.thermostat.common.storage.Connection;
 import com.redhat.thermostat.launcher.DbService;
 
 public class DbServiceTest {
     
+    private Connection connection;
+    private DAOFactory daoFactory;
     private DbService dbService;
     
     @Before
     public void setup() {
-        String dbUrl = "mongodb://testhost.example.com:19223";
-        dbService = new DbServiceImpl("tester", "testerpassword", dbUrl);
+        connection = mock(Connection.class);
+
+        daoFactory = mock(DAOFactory.class);
+        when(daoFactory.getConnection()).thenReturn(connection);
+
+        dbService = new DbServiceImpl(daoFactory);
     }
     
     @After
@@ -64,9 +75,24 @@
         try {
             dbService.setServiceRegistration(null);
             fail("Null registrations not allowed");
-        } catch (Exception e) {
+        } catch (NullPointerException e) {
             // pass
         }
     }
 
+    @Test
+    public void testConnect() {
+        dbService.connect();
+
+        verify(connection).connect();
+        verify(daoFactory).registerDAOsAndStorageAsOSGiServices();
+    }
+
+    @Test
+    public void testDisconnect() {
+        dbService.disconnect();
+
+        verify(connection).disconnect();
+    }
+
 }
--- a/tools/src/test/java/com/redhat/thermostat/tools/cli/VMInfoCommandTest.java	Thu Oct 18 00:23:54 2012 +0200
+++ b/tools/src/test/java/com/redhat/thermostat/tools/cli/VMInfoCommandTest.java	Thu Oct 18 00:25:04 2012 +0200
@@ -57,12 +57,10 @@
 import org.junit.Ignore;
 import org.junit.Test;
 
-import com.redhat.thermostat.common.appctx.ApplicationContext;
 import com.redhat.thermostat.common.appctx.ApplicationContextUtil;
 import com.redhat.thermostat.common.cli.CommandException;
 import com.redhat.thermostat.common.cli.SimpleArguments;
 import com.redhat.thermostat.common.dao.DAOException;
-import com.redhat.thermostat.common.dao.DAOFactory;
 import com.redhat.thermostat.common.dao.HostRef;
 import com.redhat.thermostat.common.dao.VmInfoDAO;
 import com.redhat.thermostat.common.dao.VmRef;