use of org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException in project data-access by pentaho.
the class ConnectionServiceImplTest method testGetConnectionsError.
@Test
public void testGetConnectionsError() throws Exception {
doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
DatasourceMgmtServiceException mockDatasourceMgmtServiceException = mock(DatasourceMgmtServiceException.class);
doThrow(mockDatasourceMgmtServiceException).when(connectionServiceImpl.datasourceMgmtSvc).getDatasources();
try {
connectionServiceImpl.getConnections();
// This line should never be reached
fail();
} catch (ConnectionServiceException e) {
// Expected exception
}
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException in project data-access by pentaho.
the class ConnectionServiceImpl method getConnections.
public List<IDatabaseConnection> getConnections(boolean hidePassword) throws ConnectionServiceException {
ensureDataAccessPermission();
List<IDatabaseConnection> connectionList = null;
try {
connectionList = datasourceMgmtSvc.getDatasources();
for (IDatabaseConnection conn : connectionList) {
sanitizer.unsanitizeConnectionParameters(conn);
if (hidePassword) {
conn.setPassword(null);
}
}
} catch (DatasourceMgmtServiceException dme) {
String message = Messages.getErrorString(// $NON-NLS-1$
"ConnectionServiceImpl.ERROR_0002_UNABLE_TO_GET_CONNECTION_LIST", dme.getLocalizedMessage());
logger.error(message);
throw new ConnectionServiceException(message, dme);
}
return connectionList;
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException in project data-access by pentaho.
the class ConnectionServiceImpl method deleteConnection.
public boolean deleteConnection(IDatabaseConnection connection) throws ConnectionServiceException {
ensureDataAccessPermission();
sanitizer.sanitizeConnectionParameters(connection);
try {
datasourceMgmtSvc.deleteDatasourceByName(connection.getName());
clearDatasource(connection.getName());
return true;
} catch (NonExistingDatasourceException nonExistingDatasourceException) {
String message = // $NON-NLS-1$
Messages.getErrorString(// $NON-NLS-1$
"ConnectionServiceImpl.ERROR_0006_UNABLE_TO_DELETE_CONNECTION", connection.getName(), nonExistingDatasourceException.getLocalizedMessage());
throw new ConnectionServiceException(Response.SC_NOT_FOUND, message, nonExistingDatasourceException);
} catch (Exception e) {
String message = // $NON-NLS-1$
Messages.getErrorString(// $NON-NLS-1$
"ConnectionServiceImpl.ERROR_0006_UNABLE_TO_DELETE_CONNECTION", connection.getName(), e.getLocalizedMessage());
logger.error(message);
throw new ConnectionServiceException(message, e);
}
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException in project data-access by pentaho.
the class ConnectionServiceImpl method testConnection.
public boolean testConnection(IDatabaseConnection connection) throws ConnectionServiceException {
ensureDataAccessPermission();
if (connection != null) {
sanitizer.sanitizeConnectionParameters(connection);
if (connection.getPassword() == null) {
// Can have an empty password but not a null one
// $NON-NLS-1$
connection.setPassword("");
}
IDatabaseDialect dialect = dialectService.getDialect(connection);
String driverClass = null;
if (connection.getDatabaseType().getShortName().equals("GENERIC")) {
driverClass = connection.getAttributes().get(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS);
} else {
driverClass = dialect.getNativeDriver();
}
IPentahoConnection pentahoConnection = null;
try {
if (connection.getAccessType().equals(DatabaseAccessType.JNDI)) {
pentahoConnection = PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, connection.getDatabaseName(), null, this);
} else {
if (connection.isUsingConnectionPool()) {
Properties props = new Properties();
props.put(IPentahoConnection.CONNECTION_NAME, connection.getName());
props.put(IPentahoConnection.CONNECTION, connection);
pentahoConnection = PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, props, null, this);
} else {
pentahoConnection = PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, driverClass, dialect.getURLWithExtraOptions(connection), connection.getUsername(), getConnectionPassword(connection.getName(), connection.getPassword()), null, this);
}
}
} catch (DatabaseDialectException e) {
throw new ConnectionServiceException(e);
}
if (pentahoConnection != null) {
// make sure we have a native connection behind the SQLConnection object
// if the native connection is null, the test of the connection failed
boolean testedOk = ((SQLConnection) pentahoConnection).getNativeConnection() != null;
pentahoConnection.close();
return testedOk;
} else {
return false;
}
} else {
// $NON-NLS-1$
String message = Messages.getErrorString("ConnectionServiceImpl.ERROR_0008_UNABLE_TO_TEST_NULL_CONNECTION");
logger.error(message);
// $NON-NLS-1$
throw new ConnectionServiceException(Response.SC_BAD_REQUEST, message);
}
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException in project data-access by pentaho.
the class JdbcDatasourceResourceTest method testGetConnectionError.
@Test
public void testGetConnectionError() throws Exception {
ConnectionServiceException mockConnectionServiceException = mock(ConnectionServiceException.class);
doThrow(mockConnectionServiceException).when(jdbcDatasourceResource.service).getConnectionByName("Name");
Response mockResponse = mock(Response.class);
doReturn(mockResponse).when(jdbcDatasourceResource).buildServerErrorResponse();
Response response = jdbcDatasourceResource.getConnection("Name");
verify(jdbcDatasourceResource, times(1)).getConnection("Name");
assertEquals(response, mockResponse);
}
Aggregations