Search in sources :

Example 6 with IDatabaseConnection

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

the class JdbcDatasourceResourceTest method testUpdateError.

@Test
public void testUpdateError() throws Exception {
    DatabaseConnection mockDatabaseConnection = mock(DatabaseConnection.class);
    doReturn("").when(mockDatabaseConnection).getPassword();
    doReturn("id").when(mockDatabaseConnection).getId();
    IDatabaseConnection mockSavedConn = mock(IDatabaseConnection.class);
    doReturn(mockSavedConn).when(jdbcDatasourceResource.service).getConnectionById("id");
    doReturn("password").when(mockSavedConn).getPassword();
    // Test 1
    doReturn(false).when(jdbcDatasourceResource.service).updateConnection(mockDatabaseConnection);
    Response mockResponse = mock(Response.class);
    doReturn(mockResponse).when(jdbcDatasourceResource).buildNotModifiedResponse();
    Response response = jdbcDatasourceResource.addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
    assertEquals(500, response.getStatus());
    // Test 2
    RuntimeException mockException = mock(RuntimeException.class);
    doThrow(mockException).when(jdbcDatasourceResource.service).updateConnection(mockDatabaseConnection);
    doReturn(mockResponse).when(jdbcDatasourceResource).buildServerErrorResponse();
    response = jdbcDatasourceResource.addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
    assertEquals(response, mockResponse);
    verify(jdbcDatasourceResource, times(2)).addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
}
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 7 with IDatabaseConnection

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

the class AutobeanUtilitiesTest method testConnectionBeanToImpl.

@Test
public void testConnectionBeanToImpl() {
    DatabaseConnection dbConnection = new DatabaseConnection();
    dbConnection.setId("my id");
    dbConnection.setAccessType(DatabaseAccessType.NATIVE);
    DatabaseType dbType = new DatabaseType();
    List<DatabaseAccessType> accessTypes = new LinkedList<DatabaseAccessType>();
    accessTypes.add(DatabaseAccessType.NATIVE);
    dbType.setSupportedAccessTypes(accessTypes);
    dbConnection.setDatabaseType(dbType);
    Map<String, String> extraOptions = new HashMap<String, String>();
    extraOptions.put("opt", "value");
    dbConnection.setExtraOptions(extraOptions);
    dbConnection.setName("Best name");
    dbConnection.setHostname("localhost");
    dbConnection.setDatabaseName("foodmart");
    dbConnection.setDatabasePort("2233");
    dbConnection.setUsername("username");
    dbConnection.setPassword("password");
    dbConnection.setStreamingResults(true);
    dbConnection.setDataTablespace("tables");
    dbConnection.setIndexTablespace("indexes");
    dbConnection.setSQLServerInstance("INSTANCE_0");
    dbConnection.setUsingDoubleDecimalAsSchemaTableSeparator(true);
    dbConnection.setInformixServername("INFORM_1");
    dbConnection.addExtraOption("100", "option", "value");
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("attr1", "value");
    dbConnection.setAttributes(attributes);
    dbConnection.setChanged(true);
    dbConnection.setQuoteAllFields(true);
    dbConnection.setForcingIdentifiersToLowerCase(true);
    dbConnection.setForcingIdentifiersToUpperCase(true);
    dbConnection.setConnectSql("select * from 1");
    dbConnection.setUsingConnectionPool(true);
    dbConnection.setInitialPoolSize(3);
    dbConnection.setMaximumPoolSize(9);
    dbConnection.setPartitioned(true);
    Map<String, String> connectionPoolingProperties = new HashMap<String, String>();
    connectionPoolingProperties.put("pool", "abc");
    dbConnection.setConnectionPoolingProperties(connectionPoolingProperties);
    List<PartitionDatabaseMeta> partitioningInformation = new LinkedList<PartitionDatabaseMeta>();
    PartitionDatabaseMeta pdm = new PartitionDatabaseMeta();
    partitioningInformation.add(pdm);
    dbConnection.setPartitioningInformation(partitioningInformation);
    IDatabaseConnection conn = AutobeanUtilities.connectionBeanToImpl(dbConnection);
    assertEquals(conn.getId(), "my id");
    assertEquals(conn.getAccessType(), DatabaseAccessType.NATIVE);
    assertEquals(conn.getDatabaseType().getSupportedAccessTypes().size(), 1);
    assertEquals(conn.getExtraOptions().size(), 3);
    assertEquals(conn.getName(), "Best name");
    assertEquals(conn.getHostname(), "localhost");
    assertEquals(conn.getDatabaseName(), "foodmart");
    assertEquals(conn.getDatabasePort(), "2233");
    assertEquals(conn.getUsername(), "username");
    assertEquals(conn.getPassword(), "password");
    assertEquals(conn.isStreamingResults(), true);
    assertEquals(conn.getDataTablespace(), "tables");
    assertEquals(conn.getIndexTablespace(), "indexes");
    assertEquals(conn.getSQLServerInstance(), "INSTANCE_0");
    assertEquals(conn.isUsingDoubleDecimalAsSchemaTableSeparator(), true);
    assertEquals(conn.getInformixServername(), "INFORM_1");
    assertEquals(conn.getAttributes().size(), 1);
    assertEquals(conn.getChanged(), false);
    assertEquals(conn.isQuoteAllFields(), true);
    assertEquals(conn.isForcingIdentifiersToLowerCase(), true);
    assertEquals(conn.isForcingIdentifiersToUpperCase(), true);
    assertEquals(conn.getConnectSql(), "select * from 1");
    assertEquals(conn.isUsingConnectionPool(), true);
    assertEquals(conn.getInitialPoolSize(), 3);
    assertEquals(conn.getMaximumPoolSize(), 9);
    assertEquals(conn.isPartitioned(), true);
    assertEquals(conn.getConnectionPoolingProperties().size(), 1);
    assertEquals(conn.getPartitioningInformation().size(), 1);
}
Also used : DatabaseType(org.pentaho.database.model.DatabaseType) IDatabaseType(org.pentaho.database.model.IDatabaseType) DatabaseAccessType(org.pentaho.database.model.DatabaseAccessType) HashMap(java.util.HashMap) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) PartitionDatabaseMeta(org.pentaho.database.model.PartitionDatabaseMeta) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 8 with IDatabaseConnection

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

the class JDBCDatasourceResource method getConnectionIDs.

/**
 * Get a list of JDBC datasource IDs.
 *
 * <p><b>Example Request:</b><br />
 *    GET pentaho/plugin/data-access/api/datasource/jdbc/connection
 * </p>
 *
 * @return A list of JDBC datasource IDs.
 *
 * <p><b>Example Response:</b></p>
 *    <pre function="syntax.xml">
 *      {
 *        "Item": [
 *          {
 *            "@type": "xs:string",
 *            "$": "AgileBI"
 *          },
 *          {
 *            "@type": "xs:string",
 *            "$": "Audit"
 *          },
 *          {
 *            "@type": "xs:string",
 *            "$": "SampleData"
 *          },
 *          {
 *            "@type": "xs:string",
 *            "$": "TestDataSourceResource"
 *          },
 *          {
 *            "@type": "xs:string",
 *            "$": "baseball connection"
 *          },
 *          {
 *            "@type": "xs:string",
 *            "$": "baseball connection"
 *          },
 *          {
 *            "@type": "xs:string",
 *            "$": "live_logging_info"
 *          },
 *          {
 *            "@type": "xs:string",
 *            "$": "pentaho_operations_mart"
 *          }
 *        ]
 *      }
 *    </pre>
 */
@GET
@Path("/")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
@StatusCodes({ @ResponseCode(code = 200, condition = "Successfully retrieved the list of JDBC datasource IDs"), @ResponseCode(code = 500, condition = "Internal error retrieving JDBC datasource IDs") })
public JaxbList<String> getConnectionIDs() {
    List<String> connStrList = new ArrayList<String>();
    try {
        List<IDatabaseConnection> conns = service.getConnections();
        for (IDatabaseConnection conn : conns) {
            conn.setPassword(null);
            connStrList.add(conn.getName());
        }
    } catch (ConnectionServiceException e) {
        logger.error("Error " + e.getMessage());
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
    JaxbList<String> connections = new JaxbList<String>(connStrList);
    return connections;
}
Also used : ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) JaxbList(org.pentaho.platform.web.http.api.resources.JaxbList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes)

Example 9 with IDatabaseConnection

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

the class ConnectionServiceImplIT method testDeleteConnection.

// we should remove connection if it is have the same name
@Test
public void testDeleteConnection() throws Exception {
    DatabaseConnection connection = new DatabaseConnection();
    connection.setName(EXIST_CONNECTION_NAME);
    assertTrue(connectionServiceImpl.deleteConnection(connection));
    for (Iterator<IDatabaseConnection> iterator = connectionServiceImpl.getConnections().iterator(); iterator.hasNext(); ) {
        if (iterator.next().getName().equals(EXIST_CONNECTION_NAME)) {
            fail("connection should be deleted");
        }
    }
    ;
}
Also used : DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Test(org.junit.Test)

Example 10 with IDatabaseConnection

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

the class ConnectionServiceImplIT method testGetConnectionByName.

@Test
public void testGetConnectionByName() throws ConnectionServiceException {
    IDatabaseConnection connection = connectionServiceImpl.getConnectionByName(EXIST_CONNECTION_NAME);
    assertNotNull(connection);
    assertEquals(EXIST_CONNECTION_NAME, connection.getName());
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) 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