/**
  * @return the {@link IBackingRepositoryLifecycleManager} that this instance will use. If none has
  *     been specified, it will default to getting the information from {@link PentahoSystem.get()}
  */
 public ITenantManager getTenantManager() {
   // Check ... if we haven't been injected with a lifecycle manager, get one from PentahoSystem
   try {
     IPentahoObjectFactory objectFactory = PentahoSystem.getObjectFactory();
     IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
     return (null != tenantManager
         ? tenantManager
         : objectFactory.get(ITenantManager.class, "tenantMgrProxy", pentahoSession));
   } catch (ObjectFactoryException e) {
     return null;
   }
 }
  @Before
  public void setUp()
      throws ConnectionServiceException, ObjectFactoryException, DBDatasourceServiceException {
    doReturn(nativeConnection).when(sqlConnection).getNativeConnection();
    doReturn(SimpleDataAccessPermissionHandler.class.getName())
        .when(loader)
        .getPluginSetting(this.anyClass(), anyString(), anyString());

    when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
    when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class)))
        .thenAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(InvocationOnMock invocation) throws Throwable {
                if (invocation.getArguments()[0].equals(IPluginResourceLoader.class)) {
                  return loader;
                }
                if (invocation.getArguments()[0].equals(IPentahoConnection.class)) {
                  return sqlConnection;
                }
                if (invocation.getArguments()[0].equals(IDBDatasourceService.class)) {
                  return datasourceService;
                }
                if (invocation.getArguments()[0].equals(PooledDatasourceHelper.class)) {
                  return pdh;
                }
                return null;
              }
            });
    PentahoSystem.registerObjectFactory(pentahoObjectFactory);

    doReturn(databaseType).when(mockDBConnection).getDatabaseType();
    doReturn(CONN_NAME).when(mockDBConnection).getName();
    doNothing().when(mockDBConnection).setPassword(anyString());

    connectionServiceImpl = spy(new ConnectionServiceImpl());
    connectionServiceImpl.datasourceMgmtSvc = mock(IDatasourceMgmtService.class);
    connectionServiceImpl.dialectService = mock(DatabaseDialectService.class);
    connectionServiceImpl.datasourceService = datasourceService;
  }