use of org.finra.herd.model.api.xml.JdbcExecutionRequest in project herd by FINRAOS.
the class JdbcServiceTest method testExecuteJdbcStatementError.
/**
* Use case where 3 statements are requested to be executed, but the 2nd is erroneous. The first statement should result in SUCCESS. The second should
* result in ERROR, with appropriate result message. The third should result in SKIPPED with no result.
*/
@Test
public void testExecuteJdbcStatementError() {
// Create test request
JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
// First statement already included
// Second statement uses case 2 which throws an error
jdbcExecutionRequest.getStatements().add(new JdbcStatement(JdbcStatementType.UPDATE, MockJdbcOperations.CASE_2_SQL, null, null, null, null, null));
jdbcExecutionRequest.getStatements().add(new JdbcStatement(JdbcStatementType.UPDATE, MockJdbcOperations.CASE_1_SQL, null, null, null, null, null));
// Execute
JdbcExecutionResponse jdbcExecutionResponse = jdbcService.executeJdbc(jdbcExecutionRequest);
// Assert results
Assert.assertNull("JDBC connection is null", jdbcExecutionResponse.getConnection());
Assert.assertEquals("JDBC statements size", jdbcExecutionRequest.getStatements().size(), jdbcExecutionResponse.getStatements().size());
{
JdbcStatement actualJdbcStatement = jdbcExecutionResponse.getStatements().get(0);
Assert.assertEquals("JDBC statement [0] status", JdbcStatementStatus.SUCCESS, actualJdbcStatement.getStatus());
}
{
JdbcStatement actualJdbcStatement = jdbcExecutionResponse.getStatements().get(1);
Assert.assertEquals("JDBC statement [1] status", JdbcStatementStatus.ERROR, actualJdbcStatement.getStatus());
Assert.assertNull("JDBC statement [1] result is not null", actualJdbcStatement.getResult());
Assert.assertEquals("JDBC statement [1] error message", "java.sql.SQLException: test DataIntegrityViolationException cause", actualJdbcStatement.getErrorMessage());
}
{
JdbcStatement actualJdbcStatement = jdbcExecutionResponse.getStatements().get(2);
Assert.assertEquals("JDBC statement [2] status", JdbcStatementStatus.SKIPPED, actualJdbcStatement.getStatus());
Assert.assertNull("JDBC statement [2] result is not null", actualJdbcStatement.getResult());
}
}
use of org.finra.herd.model.api.xml.JdbcExecutionRequest in project herd by FINRAOS.
the class JdbcServiceTest method testExecuteJdbcParamValidationStatementsMaximumStatementsSpecified.
/**
* Parameter validation, request statement list has less statements than configured maximum.
*/
@Test
public void testExecuteJdbcParamValidationStatementsMaximumStatementsSpecified() {
/*
* 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();
try {
// Execute
JdbcExecutionResponse jdbcExecutionResponse = jdbcService.executeJdbc(jdbcExecutionRequest);
Assert.assertNotNull("jdbcExecutionResponse", jdbcExecutionResponse);
} 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.JdbcExecutionRequest in project herd by FINRAOS.
the class JdbcServiceTest method testExecuteJdbcWithS3PropertiesParamUrlBlankAfterReplace.
/**
* If the result of replacing URL using S3 properties is blank, throws a validation error.
*/
@Test
public void testExecuteJdbcWithS3PropertiesParamUrlBlankAfterReplace() {
String s3BucketName = "test_bucket";
String s3ObjectKey = "test_key";
String content = "foo=";
putS3Object(s3BucketName, s3ObjectKey, content);
JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
jdbcExecutionRequest.getConnection().setUrl("${foo}");
jdbcExecutionRequest.setS3PropertiesLocation(new S3PropertiesLocation(s3BucketName, s3ObjectKey));
try {
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", "JDBC connection URL is required", e.getMessage());
}
}
use of org.finra.herd.model.api.xml.JdbcExecutionRequest in project herd by FINRAOS.
the class JdbcServiceTestHelper method createJdbcExecutionRequest.
/**
* Creates a JDBC request with the specified values.
*
* @param jdbcConnection JDBC connection
* @param jdbcStatements JDBC statements
*
* @return an execution request.
*/
public JdbcExecutionRequest createJdbcExecutionRequest(JdbcConnection jdbcConnection, List<JdbcStatement> jdbcStatements) {
JdbcExecutionRequest jdbcExecutionRequest = new JdbcExecutionRequest();
jdbcExecutionRequest.setConnection(jdbcConnection);
jdbcExecutionRequest.setStatements(jdbcStatements);
return jdbcExecutionRequest;
}
use of org.finra.herd.model.api.xml.JdbcExecutionRequest in project herd by FINRAOS.
the class ExecuteJdbcTest method testExecuteJdbcWithReceiveTask.
/**
* Asserts that the task executes asynchronously when receiveTaskId is specified.
* <p/>
* This is a very special test case which involves multithreading and transactions, therefore we cannot use the standard test methods we have. The
* transaction MUST BE DISABLED for this test to work correctly - since we have 2 threads which both access the database, if we run transactionally, the
* threads cannot share information.
* <p/>
* TODO this test could be made generic once we have async support for other tasks.
*/
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void testExecuteJdbcWithReceiveTask() throws Exception {
// Create and persist a test job definition.
executeJdbcTestHelper.prepareHerdDatabaseForExecuteJdbcWithReceiveTaskTest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, "classpath:org/finra/herd/service/testActivitiWorkflowExecuteJdbcTaskWithReceiveTask.bpmn20.xml");
try {
// Create a JDBC execution request.
JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
// Create and initialize a list of parameters.
List<Parameter> parameters = new ArrayList<>();
parameters.add(new Parameter("contentType", "xml"));
parameters.add(new Parameter("jdbcExecutionRequest", xmlHelper.objectToXml(jdbcExecutionRequest)));
// Get a job create request.
JobCreateRequest jobCreateRequest = jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
jobCreateRequest.setParameters(parameters);
// Start the job.
Job jobStartResponse = jobService.createAndStartJob(jobCreateRequest);
// Wait for the process to finish
waitUntilAllProcessCompleted();
// Validate that the job is completed.
Job jobGetResponse = jobService.getJob(jobStartResponse.getId(), true);
assertEquals(JobStatusEnum.COMPLETED, jobGetResponse.getStatus());
// Validate the task status.
assertTrue(jobGetResponse.getParameters().contains(new Parameter("service_taskStatus", "SUCCESS")));
// Validate the JDBC execution response.
JdbcExecutionResponse expectedJdbcExecutionResponse = new JdbcExecutionResponse();
JdbcStatement originalJdbcStatement = jdbcExecutionRequest.getStatements().get(0);
JdbcStatement expectedJdbcStatement = new JdbcStatement();
expectedJdbcStatement.setType(originalJdbcStatement.getType());
expectedJdbcStatement.setSql(originalJdbcStatement.getSql());
expectedJdbcStatement.setStatus(JdbcStatementStatus.SUCCESS);
expectedJdbcStatement.setResult("1");
expectedJdbcExecutionResponse.setStatements(Arrays.asList(expectedJdbcStatement));
Parameter expectedJdbcExecutionResponseParameter = new Parameter("service_jsonResponse", jsonHelper.objectToJson(expectedJdbcExecutionResponse));
assertTrue(jobGetResponse.getParameters().contains(expectedJdbcExecutionResponseParameter));
} finally {
// Clean up the Herd database.
executeJdbcTestHelper.cleanUpHerdDatabaseAfterExecuteJdbcWithReceiveTaskTest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
// Clean up the Activiti.
deleteActivitiDeployments();
}
}
Aggregations