use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.
the class ConnectionServiceImplTest method testGetConnectionsPasswords.
@Test
public void testGetConnectionsPasswords() throws Exception {
doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
List<IDatabaseConnection> mockConnectionList = new ArrayList<>();
IDatabaseConnection mockConnection = new DatabaseConnection();
mockConnectionList.add(mockConnection);
mockConnection.setPassword("testPassword");
doReturn(mockConnectionList).when(connectionServiceImpl.datasourceMgmtSvc).getDatasources();
List<IDatabaseConnection> connectionList = connectionServiceImpl.getConnections();
verify(connectionServiceImpl).getConnections();
// Default getConnections() method does not hide password
assertEquals("testPassword", mockConnectionList.get(0).getPassword());
// Hide passwords
connectionList = connectionServiceImpl.getConnections(true);
verify(connectionServiceImpl).getConnections();
assertEquals(null, mockConnectionList.get(0).getPassword());
}
use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.
the class DSWDatasourceServiceImplTest method testSqlQueries_AreNotSupported_PentahoDataServices.
@Test(expected = SqlQueriesNotSupportedException.class)
public void testSqlQueries_AreNotSupported_PentahoDataServices() throws Exception {
String connNameDataService = "connToDataService";
String dbTypeIdDataService = "Pentaho Data Services";
DatabaseType dbtype = new DatabaseType(dbTypeIdDataService, STRING_DEFAULT, null, 0, STRING_DEFAULT);
IDatabaseConnection connDataService = new DatabaseConnection();
connDataService.setDatabaseType(dbtype);
ConnectionServiceImpl connService = mock(ConnectionServiceImpl.class);
doReturn(connDataService).when(connService).getConnectionByName(eq(connNameDataService));
DSWDatasourceServiceImpl service = new DSWDatasourceServiceImpl(connService);
service.checkSqlQueriesSupported(connNameDataService);
}
use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.
the class DSWDatasourceServiceImplTest method testSqlQueries_Supported_PostgresDb.
@Test
public void testSqlQueries_Supported_PostgresDb() throws Exception {
String connNamePostgres = "connToPostgresDb";
String dbTypeIdPostgres = "PostgresDb";
IDatabaseConnection connDataService = new DatabaseConnection();
connDataService.setDatabaseType(new DatabaseType(dbTypeIdPostgres, STRING_DEFAULT, null, 0, STRING_DEFAULT));
ConnectionServiceImpl connService = mock(ConnectionServiceImpl.class);
doReturn(connDataService).when(connService).getConnectionByName(eq(connNamePostgres));
DSWDatasourceServiceImpl service = new DSWDatasourceServiceImpl(connService);
service.checkSqlQueriesSupported(connNamePostgres);
}
use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.
the class DSWDatasourceServiceImplTest method testGenerateQueryDomain.
private void testGenerateQueryDomain(String modelName, String query, List<String> roleList, List<String> userList) throws DatasourceServiceException {
ModelInfo modelInfo = mock(ModelInfo.class);
when(modelInfo.getFileInfo()).thenReturn(mock(CsvFileInfo.class));
DatasourceDTO datasourceDTO = new DatasourceDTO();
datasourceDTO.setConnectionName(CONNECTION_NAME);
datasourceDTO.setDatasourceName(CONNECTION_NAME);
datasourceDTO.setCsvModelInfo(modelInfo);
DatabaseConnection connectionSpy = spy(new DatabaseConnection());
connectionSpy.setName(CONNECTION_NAME);
connectionSpy.setDatabaseName("[database name 接続 <;>!@#$%^&*()_-=+.,]");
connectionSpy.setDatabasePort("123456");
connectionSpy.setHostname("[hostname 接続 <;>!@#$%^&*()_-=+.,]");
connectionSpy.setPassword("[password 接続 <;>!@#$%^&*()_-=+.,]");
connectionSpy.setUsername("[username 接続 <;>!@#$%^&*()_-=+.,]");
connectionSpy.setDatabaseType(mock(IDatabaseType.class));
doReturn(modelerService).when(dswService).createModelerService();
doReturn(true).when(dswService).hasDataAccessPermission();
doReturn(roleList).when(dswService).getPermittedRoleList();
doReturn(userList).when(dswService).getPermittedUserList();
doReturn(null).when(dswService).getGeoContext();
doReturn(1).when(dswService).getDefaultAcls();
QueryDatasourceSummary summary = dswService.generateQueryDomain(modelName, query, connectionSpy, datasourceDTO);
try {
verify(dswService).executeQuery("[connection 接続 <;>!@#$%^&*()_-=+.,]", query, "1");
} catch (Exception e) {
e.printStackTrace();
}
verify(connectionSpy).setName("[connection 接続 <;>!@#$%^&*()_-=+.,]");
verify(connectionSpy).setDatabaseName("[database name 接続 <;>!@#$%^&*()_-=+.,]");
verify(connectionSpy, times(2)).setDatabasePort("123456");
verify(connectionSpy).setHostname("[hostname 接続 <;>!@#$%^&*()_-=+.,]");
verify(connectionSpy).setPassword("[password 接続 <;>!@#$%^&*()_-=+.,]");
verify(connectionSpy).setUsername("[username 接続 <;>!@#$%^&*()_-=+.,]");
assertNotNull(summary);
assertNotNull(summary.getDomain());
assertEquals(CONNECTION_NAME, summary.getDomain().getId());
}
use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.
the class ConnectionServiceConcrete method getConnections.
public List<DatabaseConnection> getConnections() throws ConnectionServiceException {
List<IDatabaseConnection> iConnections = service.getConnections();
List<DatabaseConnection> connections = new ArrayList<DatabaseConnection>();
for (IDatabaseConnection iConnection : iConnections) {
hidePassword(iConnection);
connections.add((DatabaseConnection) iConnection);
}
return connections;
}
Aggregations