use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class ConnectionServiceImplTest method testTestConnection.
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();
if (DatabaseAccessType.JNDI == accessType) {
// Default is times(1), will get called 2x due to testConnection() change
verify(connection, atLeastOnce()).getDatabaseName();
} else {
verify(connection, atLeastOnce()).getName();
}
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class ConnectionServiceImplTest method testGetConnectionByName.
@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);
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class InMemoryConnectionServiceImplTest method testGetConnectionByName.
@Test
public void testGetConnectionByName() {
try {
InMemoryConnectionServiceImpl serv = new InMemoryConnectionServiceImpl();
List<IDatabaseConnection> conns = serv.getConnections();
assertTrue(conns != null && conns.size() == 0);
IDatabaseConnection connection = new DatabaseConnection();
connection.setName("Connection 1");
serv.addConnection(connection);
connection = new DatabaseConnection();
connection.setName("Connection 2");
serv.addConnection(connection);
connection = serv.getConnectionByName("Connection 2");
assertTrue(connection != null && connection.getName().equals("Connection 2"));
try {
connection = serv.getConnectionByName("Connection 5");
fail();
} catch (Exception ex) {
}
} catch (Exception ex) {
fail();
}
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class InMemoryConnectionServiceImplTest method testDeleteConnections.
@Test
public void testDeleteConnections() {
try {
InMemoryConnectionServiceImpl serv = new InMemoryConnectionServiceImpl();
List<IDatabaseConnection> conns = serv.getConnections();
assertTrue(conns != null && conns.size() == 0);
IDatabaseConnection connection = new DatabaseConnection();
connection.setName("Connection 1");
serv.addConnection(connection);
connection = new DatabaseConnection();
connection.setName("Connection 2");
serv.addConnection(connection);
conns = serv.getConnections();
assertTrue(conns != null && conns.size() == 2);
try {
serv.deleteConnection(connection);
connection = serv.getConnectionByName("Connection 2");
fail();
} catch (Exception ex) {
}
try {
serv.deleteConnection("Connection 1");
connection = serv.getConnectionByName("Connection 1");
fail();
} catch (Exception ex) {
}
} catch (Exception ex) {
fail();
}
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class InMemoryConnectionServiceImplTest method testAddConnections.
@Test
public void testAddConnections() {
try {
InMemoryConnectionServiceImpl serv = new InMemoryConnectionServiceImpl();
List<IDatabaseConnection> conns = serv.getConnections();
assertTrue(conns != null && conns.size() == 0);
IDatabaseConnection connection = new DatabaseConnection();
connection.setName("Connection 1");
serv.addConnection(connection);
connection = new DatabaseConnection();
connection.setName("Connection 1");
try {
// validate adding connection with existing name
serv.addConnection(connection);
fail();
} catch (ConnectionServiceException e) {
}
connection = new DatabaseConnection();
connection.setName("Connection 2");
serv.addConnection(connection);
conns = serv.getConnections();
assertTrue(conns != null && conns.size() > 0);
} catch (Exception ex) {
fail();
}
}
Aggregations