Search in sources :

Example 46 with DatabaseConnection

use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.

the class DatabaseConnectionConverter method convertToObject.

public IDatabaseConnection convertToObject(String xml) {
    Document document = XMLParser.parse(xml);
    Element element = document.getDocumentElement();
    IDatabaseConnection databaseConnection = new DatabaseConnection();
    databaseConnection.setDatabaseName(getNodeValueByTagName(element, DATABASE_NAME));
    databaseConnection.setHostname(getNodeValueByTagName(element, HOSTNAME));
    databaseConnection.setIndexTablespace(getNodeValueByTagName(element, INDEX_TABLESPACE));
    databaseConnection.setDataTablespace(getNodeValueByTagName(element, DATA_TABLESPACE));
    databaseConnection.setName(getNodeValueByTagName(element, NAME));
    databaseConnection.setUsername(getNodeValueByTagName(element, USERNAME));
    databaseConnection.setPassword(getNodeValueByTagName(element, PASSWORD));
    databaseConnection.setDatabasePort(getNodeValueByTagName(element, DATABASE_PORT));
    databaseConnection.setAccessType(DatabaseAccessType.getAccessTypeByName(getNodeValueByTagName(element, ACCESS_TYPE)));
    databaseConnection.setDatabaseType((DatabaseType) databaseTypeHelper.getDatabaseTypeByShortName(getNodeValueByTagName(element, DATABASE_TYPE)));
    databaseConnection.setPassword(getNodeValueByTagName(element, PASSWORD));
    databaseConnection.setInformixServername(getNodeValueByTagName(element, SERVER_NAME));
    for (Node node : getNodesByTagName(element, ATTRIBUTES)) {
        databaseConnection.getAttributes().put(node.getNodeName(), node.getNodeValue());
    }
    return databaseConnection;
}
Also used : Element(com.google.gwt.xml.client.Element) Node(com.google.gwt.xml.client.Node) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Document(com.google.gwt.xml.client.Document)

Example 47 with DatabaseConnection

use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.

the class JdbcDatasourceResourceTest method testAdd.

@Test
public void testAdd() throws Exception {
    doNothing().when(jdbcDatasourceResource).validateAccess();
    DatabaseConnection mockDatabaseConnection = mock(DatabaseConnection.class);
    doReturn(true).when(jdbcDatasourceResource.service).addConnection(mockDatabaseConnection);
    Response mockResponse = mock(Response.class);
    doReturn(mockResponse).when(jdbcDatasourceResource).buildOkResponse();
    Response response = jdbcDatasourceResource.addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
    verify(jdbcDatasourceResource, times(1)).addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
    assertEquals(response, mockResponse);
}
Also used : Response(javax.ws.rs.core.Response) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Test(org.junit.Test)

Example 48 with DatabaseConnection

use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.

the class JdbcDatasourceResourceTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    DatabaseConnection mockDatabaseConnection = mock(DatabaseConnection.class);
    doReturn("").when(mockDatabaseConnection).getPassword();
    doReturn("id").when(mockDatabaseConnection).getName();
    IDatabaseConnection mockSavedConn = mock(IDatabaseConnection.class);
    doReturn(mockSavedConn).when(jdbcDatasourceResource.service).getConnectionByName("id");
    doReturn("password").when(mockSavedConn).getPassword();
    doReturn(true).when(jdbcDatasourceResource.service).updateConnection(mockDatabaseConnection);
    doNothing().when(jdbcDatasourceResource).validateAccess();
    Response mockResponse = mock(Response.class);
    doReturn(mockResponse).when(jdbcDatasourceResource).buildOkResponse();
    Response response = jdbcDatasourceResource.addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
    verify(jdbcDatasourceResource, times(1)).addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
    assertEquals(response, mockResponse);
}
Also used : Response(javax.ws.rs.core.Response) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Test(org.junit.Test)

Example 49 with DatabaseConnection

use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.

the class JdbcDatasourceResourceTest method testAddOrUpdateNoPublishPermission.

@Test
public void testAddOrUpdateNoPublishPermission() throws Exception {
    doThrow(new PentahoAccessControlException()).when(jdbcDatasourceResource).validateAccess();
    DatabaseConnection mockDatabaseConnection = mock(DatabaseConnection.class);
    try {
        jdbcDatasourceResource.addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
        fail();
    } catch (WebApplicationException e) {
        assertEquals(401, e.getResponse().getStatus());
    }
    verify(jdbcDatasourceResource.service, never()).addConnection(any());
    verify(jdbcDatasourceResource.service, never()).updateConnection(any());
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Test(org.junit.Test)

Example 50 with DatabaseConnection

use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.

the class QueryDatasource method onFinish.

@Override
public void onFinish(XulServiceCallback<IDatasourceSummary> callback) {
    String name = datasourceModel.getDatasourceName().replace(".", "_").replace(" ", "_");
    String query = datasourceModel.getQuery();
    DatabaseConnection conn = (DatabaseConnection) AutobeanUtilities.connectionBeanToImpl(datasourceModel.getSelectedRelationalConnection());
    datasourceService.generateQueryDomain(name, query, conn, DatasourceDTOUtil.generateDTO(datasourceModel), callback);
}
Also used : DatabaseConnection(org.pentaho.database.model.DatabaseConnection)

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