use of org.finra.herd.model.api.xml.JdbcStatement in project herd by FINRAOS.
the class JdbcServiceTest method testExecuteJdbcStatementTypeQuerySuccess.
/**
* Test case where user specifies a QUERY statement type. A proper result set should be created.
*/
@Test
public void testExecuteJdbcStatementTypeQuerySuccess() {
// Get test request
JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultQueryJdbcExecutionRequest();
JdbcStatement expectedJdbcStatement = jdbcExecutionRequest.getStatements().get(0);
JdbcExecutionResponse jdbcExecutionResponse = jdbcService.executeJdbc(jdbcExecutionRequest);
Assert.assertEquals("JDBC statements size", 1, jdbcExecutionResponse.getStatements().size());
JdbcStatement actualJdbcStatement = jdbcExecutionResponse.getStatements().get(0);
Assert.assertNull("JDBC statement error message is not null", actualJdbcStatement.getErrorMessage());
Assert.assertNull("JDBC statement result not is null", actualJdbcStatement.getResult());
Assert.assertEquals("JDBC statement SQL", expectedJdbcStatement.getSql(), actualJdbcStatement.getSql());
Assert.assertEquals("JDBC statement status", JdbcStatementStatus.SUCCESS, actualJdbcStatement.getStatus());
Assert.assertEquals("JDBC statement type", expectedJdbcStatement.getType(), actualJdbcStatement.getType());
Assert.assertNotNull("JDBC statement result set is null", actualJdbcStatement.getResultSet());
Assert.assertNotNull("JDBC statement result set column names is null", actualJdbcStatement.getResultSet().getColumnNames());
Assert.assertEquals("JDBC statement result set column names", Arrays.asList("COL1", "COL2", "COL3"), actualJdbcStatement.getResultSet().getColumnNames());
Assert.assertNotNull("JDBC statement result set rows is null", actualJdbcStatement.getResultSet().getRows());
Assert.assertEquals("JDBC statement result set rows size", 2, actualJdbcStatement.getResultSet().getRows().size());
{
JdbcStatementResultSetRow row = actualJdbcStatement.getResultSet().getRows().get(0);
Assert.assertNotNull("JDBC statement row [0] columns is null", row.getColumns());
Assert.assertEquals("JDBC statement row [0] columns", Arrays.asList("A", "B", "C"), row.getColumns());
}
{
JdbcStatementResultSetRow row = actualJdbcStatement.getResultSet().getRows().get(1);
Assert.assertNotNull("JDBC statement row [1] columns is null", row.getColumns());
Assert.assertEquals("JDBC statement row [1] columns", Arrays.asList("D", "E", "F"), row.getColumns());
}
}
use of org.finra.herd.model.api.xml.JdbcStatement in project herd by FINRAOS.
the class JdbcServiceTest method testExecuteJdbcParamValidationStatementsExceedMaximum.
/**
* Parameter validation, request statement list has more statements than configured maximum.
*/
@Test
public void testExecuteJdbcParamValidationStatementsExceedMaximum() {
/*
* Update environment variable to use a maximum statement
*/
int maxStatements = 1;
try {
HashMap<String, Object> overrideMap = new HashMap<>();
overrideMap.put(ConfigurationValue.JDBC_MAX_STATEMENTS.getKey(), maxStatements);
modifyPropertySourceInEnvironment(overrideMap);
} catch (Exception e) {
throw new RuntimeException("Error modifying environment variable.", e);
}
/*
* Add 1 more statement to the JDBC request.
* The default request should already have 1 statement.
*/
JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
jdbcExecutionRequest.getStatements().add(new JdbcStatement());
try {
// Execute
jdbcService.executeJdbc(jdbcExecutionRequest);
Assert.fail("expected an IllegalArgumentException, but no exception was thrown");
} catch (Exception e) {
Assert.assertEquals("thrown exception type", IllegalArgumentException.class, e.getClass());
Assert.assertEquals("thrown exception message", "The number of JDBC statements exceeded the maximum allowed " + maxStatements + ".", e.getMessage());
} finally {
/*
*
*/
try {
restorePropertySourceInEnvironment();
} catch (Exception e) {
throw new RuntimeException("Error restoring environment variables. Subsequent tests may be affected.", e);
}
}
}
use of org.finra.herd.model.api.xml.JdbcStatement in project herd by FINRAOS.
the class JdbcServiceTestHelper method createDefaultUpdateJdbcExecutionRequest.
/**
* Creates a default JDBC execution request which is guaranteed to work. The request contains a single statement of UPDATE type.
*
* @return a valid JDBC request
*/
public JdbcExecutionRequest createDefaultUpdateJdbcExecutionRequest() {
JdbcConnection jdbcConnection = createDefaultJdbcConnection();
List<JdbcStatement> jdbcStatements = createDefaultUpdateJdbcStatements();
JdbcExecutionRequest jdbcExecutionRequest = createJdbcExecutionRequest(jdbcConnection, jdbcStatements);
return jdbcExecutionRequest;
}
use of org.finra.herd.model.api.xml.JdbcStatement in project herd by FINRAOS.
the class JdbcServiceTestHelper method createDefaultQueryJdbcExecutionRequest.
/**
* Creates a default JDBC execution request which is guaranteed to work. The request contains a single statement of QUERY type.
*
* @return a valid JDBC request
*/
public JdbcExecutionRequest createDefaultQueryJdbcExecutionRequest() {
JdbcConnection jdbcConnection = createDefaultJdbcConnection();
List<JdbcStatement> jdbcStatements = createDefaultQueryJdbcStatements();
JdbcExecutionRequest jdbcExecutionRequest = createJdbcExecutionRequest(jdbcConnection, jdbcStatements);
return jdbcExecutionRequest;
}
use of org.finra.herd.model.api.xml.JdbcStatement in project herd by FINRAOS.
the class JdbcServiceImpl method validateJdbcStatements.
/**
* Validates parameters specified in the given statements. The statements must not be null, and must not be empty.
*
* @param jdbcStatements the list of statements to validate
*/
private void validateJdbcStatements(List<JdbcStatement> jdbcStatements) {
Assert.notNull(jdbcStatements, "JDBC statements are required");
Assert.isTrue(!jdbcStatements.isEmpty(), "JDBC statements are required");
Integer jdbcMaxStatements = configurationHelper.getProperty(ConfigurationValue.JDBC_MAX_STATEMENTS, Integer.class);
if (jdbcMaxStatements != null) {
Assert.isTrue(jdbcStatements.size() <= jdbcMaxStatements, "The number of JDBC statements exceeded the maximum allowed " + jdbcMaxStatements + ".");
}
for (int i = 0; i < jdbcStatements.size(); i++) {
JdbcStatement jdbcStatement = jdbcStatements.get(i);
validateJdbcStatement(jdbcStatement, i);
}
}
Aggregations