Search in sources :

Example 51 with DatabaseConnection

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

the class InMemoryConnectionServiceImplTest method testGetConnections.

@Test
public void testGetConnections() {
    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);
        conns = serv.getConnections();
        assertTrue(conns != null && conns.size() > 0);
    } 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 52 with DatabaseConnection

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

the class InMemoryConnectionServiceImplTest method testUpdateConnection.

@Test
public void testUpdateConnection() {
    try {
        InMemoryConnectionServiceImpl serv = new InMemoryConnectionServiceImpl();
        List<IDatabaseConnection> conns = serv.getConnections();
        assertTrue(conns != null && conns.size() == 0);
        IDatabaseConnection connection = new DatabaseConnection();
        connection.setName("Connection 1");
        connection.setUsername("admin");
        connection.setPassword("password");
        serv.addConnection(connection);
        conns = serv.getConnections();
        assertTrue(conns.get(0).getUsername().equals("admin"));
        assertTrue(conns.get(0).getPassword().equals("password"));
        connection = new DatabaseConnection();
        connection.setName("Connection 1");
        connection.setUsername("root");
        connection.setPassword("pass");
        serv.updateConnection(connection);
        List<IDatabaseConnection> conns1 = serv.getConnections();
        assertTrue(conns1 != null && conns1.size() > 0);
        assertTrue(conns1.size() == conns.size());
        assertTrue(conns1.get(0).getUsername().equals("root"));
        assertTrue(conns1.get(0).getPassword().equals("pass"));
    } 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 53 with DatabaseConnection

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

the class UtilHtmlSanitizerTest method testSanitizeConnectionParameters.

@Test
public void testSanitizeConnectionParameters() throws Exception {
    DatabaseConnection connection = new DatabaseConnection();
    // see http://jira.pentaho.com/browse/PPP-3546
    connection.setName("<font color=\"red\">\"AAAAAAAAAAAA\"");
    sanitizer.sanitizeConnectionParameters(connection);
    assertEquals("&lt;font color=&quot;red&quot;&gt;&quot;AAAAAAAAAAAA&quot;", connection.getName());
    connection.setName("<input type=\"button\" onClick=\"dangerous code\">");
    sanitizer.sanitizeConnectionParameters(connection);
    assertEquals("&lt;input type=&quot;button&quot; onClick=&quot;dangerous code&quot;&gt;", connection.getName());
    connection.setName("<a href=\"url\">link text");
    sanitizer.sanitizeConnectionParameters(connection);
    assertEquals("&lt;a href=&quot;url&quot;&gt;link text", connection.getName());
    // check that null is not transformed to an empty string
    assertNull(connection.getDatabaseName());
}
Also used : DatabaseConnection(org.pentaho.database.model.DatabaseConnection) Test(org.junit.Test)

Example 54 with DatabaseConnection

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

the class AutobeanUtilities method connectionBeanToImpl.

/**
 * @param connectionBean - IDatabaseConnection backed by a Autobean implementation
 * @return an IDatabaseConnection that is backed by a concrete DatabaseConnection
 * <p/>
 * This method will take an autobean implementation of IDatabaseConnection and return a DatabaseConnection
 */
public static IDatabaseConnection connectionBeanToImpl(IDatabaseConnection connectionBean) {
    DatabaseConnection connectionImpl = new DatabaseConnection();
    connectionImpl.setAccessType(connectionBean.getAccessType());
    if (connectionImpl.getAccessType() != null) {
        connectionImpl.setAccessTypeValue(connectionImpl.getAccessType().toString());
    }
    connectionImpl.setAttributes(mapBeanToImpl(connectionBean.getAttributes()));
    connectionImpl.setConnectionPoolingProperties(mapBeanToImpl(connectionBean.getConnectionPoolingProperties()));
    connectionImpl.setConnectSql(connectionBean.getConnectSql());
    connectionImpl.setDatabaseName(connectionBean.getDatabaseName());
    connectionImpl.setDatabasePort(connectionBean.getDatabasePort());
    connectionImpl.setDatabaseType(dbTypeBeanToImpl(connectionBean.getDatabaseType()));
    connectionImpl.setDataTablespace(connectionBean.getDataTablespace());
    connectionImpl.setForcingIdentifiersToLowerCase(connectionBean.isForcingIdentifiersToLowerCase());
    connectionImpl.setForcingIdentifiersToUpperCase(connectionBean.isForcingIdentifiersToUpperCase());
    connectionImpl.setHostname(connectionBean.getHostname());
    connectionImpl.setId(connectionBean.getId());
    connectionImpl.setIndexTablespace(connectionBean.getIndexTablespace());
    connectionImpl.setInformixServername(connectionBean.getInformixServername());
    connectionImpl.setInitialPoolSize(connectionBean.getInitialPoolSize());
    connectionImpl.setMaximumPoolSize(connectionBean.getMaximumPoolSize());
    connectionImpl.setName(connectionBean.getName());
    connectionImpl.setPartitioned(connectionBean.isPartitioned());
    connectionImpl.setPartitioningInformation(connectionBean.getPartitioningInformation());
    connectionImpl.setPassword(connectionBean.getPassword());
    connectionImpl.setDatabasePort(connectionBean.getDatabasePort());
    connectionImpl.setQuoteAllFields(connectionBean.isQuoteAllFields());
    connectionImpl.setSQLServerInstance(connectionBean.getSQLServerInstance());
    connectionImpl.setStreamingResults(connectionBean.isStreamingResults());
    connectionImpl.setUsername(connectionBean.getUsername());
    connectionImpl.setUsingConnectionPool(connectionBean.isUsingConnectionPool());
    connectionImpl.setUsingDoubleDecimalAsSchemaTableSeparator(connectionBean.isUsingDoubleDecimalAsSchemaTableSeparator());
    connectionImpl.setExtraOptions(mapBeanToImpl(connectionBean.getExtraOptions()));
    connectionImpl.setExtraOptionsOrder(mapBeanToImpl(connectionBean.getExtraOptionsOrder()));
    return connectionImpl;
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatabaseConnection(org.pentaho.database.model.DatabaseConnection)

Example 55 with DatabaseConnection

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

the class DatabaseConnectionReaderWriter method readFrom.

@Override
public DatabaseConnection readFrom(Class<DatabaseConnection> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    JSONDeserializer<DatabaseConnection> jsonD = new JSONDeserializer<DatabaseConnection>();
    jsonD.use("databaseType", DatabaseType.class);
    return jsonD.deserialize(new InputStreamReader(entityStream), DatabaseConnection.class);
}
Also used : InputStreamReader(java.io.InputStreamReader) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) JSONDeserializer(flexjson.JSONDeserializer)

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