Search in sources :

Example 41 with DatabaseConnection

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());
}
Also used : ArrayList(java.util.ArrayList) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Test(org.junit.Test)

Example 42 with DatabaseConnection

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);
}
Also used : DatabaseType(org.pentaho.database.model.DatabaseType) IDatabaseType(org.pentaho.database.model.IDatabaseType) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Mockito.anyString(org.mockito.Mockito.anyString) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Test(org.junit.Test)

Example 43 with DatabaseConnection

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);
}
Also used : DatabaseType(org.pentaho.database.model.DatabaseType) IDatabaseType(org.pentaho.database.model.IDatabaseType) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Mockito.anyString(org.mockito.Mockito.anyString) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Test(org.junit.Test)

Example 44 with DatabaseConnection

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 &#25509;&#32154; &lt;;&gt;!@#$%^&amp;*()_-=+.,]", query, "1");
    } catch (Exception e) {
        e.printStackTrace();
    }
    verify(connectionSpy).setName("[connection &#25509;&#32154; &lt;;&gt;!@#$%^&amp;*()_-=+.,]");
    verify(connectionSpy).setDatabaseName("[database name &#25509;&#32154; &lt;;&gt;!@#$%^&amp;*()_-=+.,]");
    verify(connectionSpy, times(2)).setDatabasePort("123456");
    verify(connectionSpy).setHostname("[hostname &#25509;&#32154; &lt;;&gt;!@#$%^&amp;*()_-=+.,]");
    verify(connectionSpy).setPassword("[password &#25509;&#32154; &lt;;&gt;!@#$%^&amp;*()_-=+.,]");
    verify(connectionSpy).setUsername("[username &#25509;&#32154; &lt;;&gt;!@#$%^&amp;*()_-=+.,]");
    assertNotNull(summary);
    assertNotNull(summary.getDomain());
    assertEquals(CONNECTION_NAME, summary.getDomain().getId());
}
Also used : IDatabaseType(org.pentaho.database.model.IDatabaseType) CsvFileInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvFileInfo) QueryDatasourceSummary(org.pentaho.platform.dataaccess.datasource.wizard.sources.query.QueryDatasourceSummary) ModelInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatasourceDTO(org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceDTO) ModelerException(org.pentaho.agilebi.modeler.ModelerException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) SQLException(java.sql.SQLException) SqlQueriesNotSupportedException(org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException)

Example 45 with DatabaseConnection

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;
}
Also used : ArrayList(java.util.ArrayList) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Aggregations

DatabaseConnection (org.pentaho.database.model.DatabaseConnection)56 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)48 Test (org.junit.Test)36 HashMap (java.util.HashMap)10 IDatabaseDialectService (org.pentaho.database.service.IDatabaseDialectService)7 DatabaseType (org.pentaho.database.model.DatabaseType)6 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)6 DatabaseTypeHelper (org.pentaho.database.util.DatabaseTypeHelper)6 ArrayList (java.util.ArrayList)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 IDatabaseType (org.pentaho.database.model.IDatabaseType)5 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)5 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)5 Response (javax.ws.rs.core.Response)4 List (java.util.List)3 LinkedList (java.util.LinkedList)2 Mockito.anyString (org.mockito.Mockito.anyString)2 DatabaseAccessType (org.pentaho.database.model.DatabaseAccessType)2 PartitionDatabaseMeta (org.pentaho.database.model.PartitionDatabaseMeta)2 Category (org.pentaho.metadata.model.Category)2