use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.
the class JdbcDatasourceResourceTest method testAddError.
@Test
public void testAddError() throws Exception {
doNothing().when(jdbcDatasourceResource).validateAccess();
DatabaseConnection mockDatabaseConnection = mock(DatabaseConnection.class);
// Test 1
doReturn(false).when(jdbcDatasourceResource.service).addConnection(mockDatabaseConnection);
Response mockResponse = mock(Response.class);
doReturn(mockResponse).when(jdbcDatasourceResource).buildNotModifiedResponse();
Response response = jdbcDatasourceResource.addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
assertEquals(response, mockResponse);
// Test 2
RuntimeException mockException = mock(RuntimeException.class);
doThrow(mockException).when(jdbcDatasourceResource.service).addConnection(mockDatabaseConnection);
mockResponse = mock(Response.class);
doReturn(mockResponse).when(jdbcDatasourceResource).buildServerErrorResponse();
response = jdbcDatasourceResource.addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
assertEquals(response, mockResponse);
verify(jdbcDatasourceResource, times(2)).addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
}
use of org.pentaho.database.model.DatabaseConnection 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);
}
use of org.pentaho.database.model.DatabaseConnection 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);
}
use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.
the class DatabaseConnectionConverterTest method testConvertToXml.
@Test
public void testConvertToXml() {
DatabaseConnection dbConnection = new DatabaseConnection();
dbConnection.setId("my id");
dbConnection.setAccessType(DatabaseAccessType.NATIVE);
List<DatabaseAccessType> accessTypes = new LinkedList<DatabaseAccessType>();
accessTypes.add(DatabaseAccessType.NATIVE);
DatabaseType dbType = new DatabaseType("name", "short name", accessTypes, 100500, "helpUri");
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);
List<IDatabaseType> databaseTypes = new LinkedList<IDatabaseType>();
databaseTypes.add(dbType);
DatabaseTypeHelper dbh = new DatabaseTypeHelper(databaseTypes);
DatabaseConnectionConverter dbcc = new DatabaseConnectionConverter(dbh);
String xmlCOnnection = dbcc.convertToXml(dbConnection);
}
use of org.pentaho.database.model.DatabaseConnection 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");
}
}
;
}
Aggregations