コード例 #1
0
 @Test(expected = ConnectionServiceException.class)
 public void testIsConnectionExist_Error() throws Exception {
   doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
   doThrow(mock(DatasourceMgmtServiceException.class))
       .when(connectionServiceImpl.datasourceMgmtSvc)
       .getDatasourceByName(CONN_NAME);
   assertTrue(connectionServiceImpl.isConnectionExist(CONN_NAME));
 }
コード例 #2
0
 @Test
 public void testIsConnectionExist_true() throws Exception {
   doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
   doReturn(mockDBConnection)
       .when(connectionServiceImpl.datasourceMgmtSvc)
       .getDatasourceByName(CONN_NAME);
   assertTrue(connectionServiceImpl.isConnectionExist(CONN_NAME));
 }
コード例 #3
0
  @Test
  public void testDeleteConnectionConn() throws Exception {
    doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
    doNothing().when(connectionServiceImpl.datasourceMgmtSvc).deleteDatasourceByName(CONN_NAME);

    assertTrue(connectionServiceImpl.deleteConnection(mockDBConnection));
    verify(datasourceService).clearDataSource(CONN_NAME);
  }
コード例 #4
0
 @Test
 public void testGetConnections() throws Exception {
   doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
   List<IDatabaseConnection> mockConnectionList = Collections.emptyList();
   doReturn(mockConnectionList).when(connectionServiceImpl.datasourceMgmtSvc).getDatasources();
   List<IDatabaseConnection> connectionList = connectionServiceImpl.getConnections();
   verify(connectionServiceImpl).getConnections();
   assertEquals(connectionList, mockConnectionList);
 }
コード例 #5
0
  @Test
  public void testUpdateConnection() throws Exception {
    doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
    doReturn("").when(connectionServiceImpl).getConnectionPassword(anyString(), anyString());

    assertTrue(connectionServiceImpl.updateConnection(mockDBConnection));

    verify(connectionServiceImpl).updateConnection(mockDBConnection);
    verify(datasourceService).clearDataSource(CONN_NAME);
  }
コード例 #6
0
 private void testAddConnectionError(Exception ex) throws Exception {
   doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
   doThrow(ex).when(connectionServiceImpl.datasourceMgmtSvc).createDatasource(mockDBConnection);
   try {
     connectionServiceImpl.addConnection(mockDBConnection);
     fail(); // This line should never be reached
   } catch (ConnectionServiceException e) {
     // Expected exception
   }
 }
コード例 #7
0
 @Test
 public void testGetConnectionByName() throws Exception {
   doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
   doReturn(mockDBConnection)
       .when(connectionServiceImpl.datasourceMgmtSvc)
       .getDatasourceByName(CONN_NAME);
   IDatabaseConnection connection = connectionServiceImpl.getConnectionByName(CONN_NAME);
   verify(connectionServiceImpl).getConnectionByName(CONN_NAME);
   assertEquals(mockDBConnection, connection);
 }
コード例 #8
0
 private void testDeleteConnectionErrorString(Exception ex) throws Exception {
   doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
   doThrow(ex).when(connectionServiceImpl.datasourceMgmtSvc).deleteDatasourceByName(CONN_NAME);
   try {
     connectionServiceImpl.deleteConnection(CONN_NAME);
     fail(); // This line should never be reached
   } catch (ConnectionServiceException e) {
     // Expected exception
   }
 }
コード例 #9
0
 @Test
 public void testGetConnectionByNameError_NullDataSource() throws Exception {
   doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
   doReturn(null).when(connectionServiceImpl.datasourceMgmtSvc).getDatasourceByName(CONN_NAME);
   try {
     connectionServiceImpl.getConnectionByName(CONN_NAME);
     fail(); // This line should never be reached
   } catch (ConnectionServiceException e) {
     // Expected exception
   }
 }
コード例 #10
0
 @Test
 public void testGetConnectionByIdError() throws Exception {
   doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
   DatasourceMgmtServiceException dmsException = mock(DatasourceMgmtServiceException.class);
   doThrow(dmsException).when(connectionServiceImpl.datasourceMgmtSvc).getDatasourceById(CONN_ID);
   try {
     connectionServiceImpl.getConnectionById(CONN_ID);
     fail(); // This line should never be reached
   } catch (ConnectionServiceException e) {
     // Expected exception
   }
 }
コード例 #11
0
  @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;
  }
コード例 #12
0
 private void testUpdateConnectionError(Exception ex) throws Exception {
   doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
   doReturn("").when(connectionServiceImpl).getConnectionPassword(anyString(), anyString());
   doThrow(ex)
       .when(connectionServiceImpl.datasourceMgmtSvc)
       .updateDatasourceByName(CONN_NAME, mockDBConnection);
   try {
     connectionServiceImpl.updateConnection(mockDBConnection);
     fail(); // This line should never be reached
   } catch (ConnectionServiceException e) {
     // Expected exception
   }
   verify(connectionServiceImpl).updateConnection(mockDBConnection);
 }
コード例 #13
0
  private void testTestConnection(
      DatabaseAccessType accessType,
      IDatabaseConnection connection,
      String database,
      boolean isPool)
      throws Exception {
    doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
    doReturn("connectionPassword")
        .when(connectionServiceImpl)
        .getConnectionPassword(anyString(), anyString());

    IDatabaseDialect dialect = mock(IDatabaseDialect.class);
    doReturn("NativeDriver").when(dialect).getNativeDriver();
    doReturn(dialect)
        .when(connectionServiceImpl.dialectService)
        .getDialect(any(IDatabaseConnection.class));
    doReturn(database).when(databaseType).getShortName();
    doReturn(accessType).when(mockDBConnection).getAccessType();
    doReturn("DATABASENAME").when(mockDBConnection).getDatabaseName();
    doReturn(isPool).when(mockDBConnection).isUsingConnectionPool();
    assertTrue(connectionServiceImpl.testConnection(connection));
    verify(sqlConnection).close();
  }
コード例 #14
0
 @Test
 public void testIsConnectionExist_false() throws Exception {
   doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
   assertFalse(connectionServiceImpl.isConnectionExist(CONN_NAME));
 }
コード例 #15
0
 @Test
 public void testAddConnection() throws Exception {
   doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
   assertTrue(connectionServiceImpl.addConnection(mockDBConnection));
 }