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();
}
}
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();
}
}
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("<font color="red">"AAAAAAAAAAAA"", connection.getName());
connection.setName("<input type=\"button\" onClick=\"dangerous code\">");
sanitizer.sanitizeConnectionParameters(connection);
assertEquals("<input type="button" onClick="dangerous code">", connection.getName());
connection.setName("<a href=\"url\">link text");
sanitizer.sanitizeConnectionParameters(connection);
assertEquals("<a href="url">link text", connection.getName());
// check that null is not transformed to an empty string
assertNull(connection.getDatabaseName());
}
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;
}
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);
}
Aggregations