Search in sources :

Example 31 with IDatabaseConnection

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

Example 32 with IDatabaseConnection

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

Example 33 with IDatabaseConnection

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();
    }
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) Test(org.junit.Test)

Example 34 with IDatabaseConnection

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();
    }
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) Test(org.junit.Test)

Example 35 with IDatabaseConnection

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();
    }
}
Also used : ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) Test(org.junit.Test)

Aggregations

IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)102 Test (org.junit.Test)32 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)29 ArrayList (java.util.ArrayList)18 Bindable (org.pentaho.ui.xul.stereotype.Bindable)15 RequestException (com.google.gwt.http.client.RequestException)14 Request (com.google.gwt.http.client.Request)13 RequestBuilder (com.google.gwt.http.client.RequestBuilder)13 RequestCallback (com.google.gwt.http.client.RequestCallback)13 Response (com.google.gwt.http.client.Response)13 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)13 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)11 DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)9 List (java.util.List)8 Response (javax.ws.rs.core.Response)8 Path (javax.ws.rs.Path)7 GET (javax.ws.rs.GET)6 Produces (javax.ws.rs.Produces)6 Facet (org.codehaus.enunciate.Facet)5 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)5