Search in sources :

Example 11 with JdbcExecutionResponse

use of org.finra.herd.model.api.xml.JdbcExecutionResponse in project herd by FINRAOS.

the class JdbcServiceTest method testExecuteJdbcStatementSuccess.

/**
 * Use case where a single successful statement is executed.
 */
@Test
public void testExecuteJdbcStatementSuccess() {
    // Get test request
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    // Execute
    JdbcExecutionResponse jdbcExecutionResponse = jdbcService.executeJdbc(jdbcExecutionRequest);
    // Assert results
    Assert.assertNull("JDBC connection is not null", jdbcExecutionResponse.getConnection());
    Assert.assertEquals("JDBC statements size", jdbcExecutionRequest.getStatements().size(), jdbcExecutionResponse.getStatements().size());
    {
        JdbcStatement expectedJdbcStatement = jdbcExecutionRequest.getStatements().get(0);
        JdbcStatement actualJdbcStatement = jdbcExecutionResponse.getStatements().get(0);
        Assert.assertEquals("JDBC statement [0] type", expectedJdbcStatement.getType(), actualJdbcStatement.getType());
        Assert.assertEquals("JDBC statement [0] sql", expectedJdbcStatement.getSql(), actualJdbcStatement.getSql());
        Assert.assertEquals("JDBC statement [0] status", JdbcStatementStatus.SUCCESS, actualJdbcStatement.getStatus());
        Assert.assertEquals("JDBC statement [0] result", "1", actualJdbcStatement.getResult());
    }
}
Also used : JdbcStatement(org.finra.herd.model.api.xml.JdbcStatement) JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) JdbcExecutionResponse(org.finra.herd.model.api.xml.JdbcExecutionResponse) Test(org.junit.Test)

Example 12 with JdbcExecutionResponse

use of org.finra.herd.model.api.xml.JdbcExecutionResponse 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());
    }
}
Also used : JdbcStatementResultSetRow(org.finra.herd.model.api.xml.JdbcStatementResultSetRow) JdbcStatement(org.finra.herd.model.api.xml.JdbcStatement) JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) JdbcExecutionResponse(org.finra.herd.model.api.xml.JdbcExecutionResponse) Test(org.junit.Test)

Example 13 with JdbcExecutionResponse

use of org.finra.herd.model.api.xml.JdbcExecutionResponse in project herd by FINRAOS.

the class ExecuteJdbcTest method testExecuteJdbcSuccess.

@Test
public void testExecuteJdbcSuccess() throws Exception {
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    List<FieldExtension> fieldExtensionList = new ArrayList<>();
    List<Parameter> parameters = new ArrayList<>();
    populateParameters(jdbcExecutionRequest, fieldExtensionList, parameters);
    JdbcExecutionResponse expectedJdbcExecutionResponse = new JdbcExecutionResponse();
    expectedJdbcExecutionResponse.setStatements(jdbcExecutionRequest.getStatements());
    expectedJdbcExecutionResponse.getStatements().get(0).setStatus(JdbcStatementStatus.SUCCESS);
    expectedJdbcExecutionResponse.getStatements().get(0).setResult("1");
    String expectedJdbcExecutionResponseJson = jsonHelper.objectToJson(expectedJdbcExecutionResponse);
    Map<String, Object> variableValuesToValidate = new HashMap<>();
    variableValuesToValidate.put(BaseJavaDelegate.VARIABLE_JSON_RESPONSE, expectedJdbcExecutionResponseJson);
    testActivitiServiceTaskSuccess(JAVA_DELEGATE_CLASS_NAME, fieldExtensionList, parameters, variableValuesToValidate);
}
Also used : HashMap(java.util.HashMap) FieldExtension(org.activiti.bpmn.model.FieldExtension) ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) JdbcExecutionResponse(org.finra.herd.model.api.xml.JdbcExecutionResponse) Test(org.junit.Test)

Example 14 with JdbcExecutionResponse

use of org.finra.herd.model.api.xml.JdbcExecutionResponse in project herd by FINRAOS.

the class ExecuteJdbcTest method testExecuteJdbcErrorStatement.

@Test
public void testExecuteJdbcErrorStatement() throws Exception {
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    jdbcExecutionRequest.getStatements().get(0).setSql(MockJdbcOperations.CASE_2_SQL);
    List<FieldExtension> fieldExtensionList = new ArrayList<>();
    List<Parameter> parameters = new ArrayList<>();
    populateParameters(jdbcExecutionRequest, fieldExtensionList, parameters);
    JdbcExecutionResponse expectedJdbcExecutionResponse = new JdbcExecutionResponse();
    expectedJdbcExecutionResponse.setStatements(jdbcExecutionRequest.getStatements());
    expectedJdbcExecutionResponse.getStatements().get(0).setStatus(JdbcStatementStatus.ERROR);
    expectedJdbcExecutionResponse.getStatements().get(0).setErrorMessage("java.sql.SQLException: test DataIntegrityViolationException cause");
    String expectedJdbcExecutionResponseString = jsonHelper.objectToJson(expectedJdbcExecutionResponse);
    Map<String, Object> variableValuesToValidate = new HashMap<>();
    variableValuesToValidate.put(BaseJavaDelegate.VARIABLE_JSON_RESPONSE, expectedJdbcExecutionResponseString);
    variableValuesToValidate.put(ActivitiRuntimeHelper.VARIABLE_ERROR_MESSAGE, "There are failed executions. See JSON response for details.");
    executeWithoutLogging(ActivitiRuntimeHelper.class, () -> {
        testActivitiServiceTaskFailure(JAVA_DELEGATE_CLASS_NAME, fieldExtensionList, parameters, variableValuesToValidate);
    });
}
Also used : HashMap(java.util.HashMap) FieldExtension(org.activiti.bpmn.model.FieldExtension) ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) JdbcExecutionResponse(org.finra.herd.model.api.xml.JdbcExecutionResponse) Test(org.junit.Test)

Aggregations

JdbcExecutionResponse (org.finra.herd.model.api.xml.JdbcExecutionResponse)14 JdbcExecutionRequest (org.finra.herd.model.api.xml.JdbcExecutionRequest)12 Test (org.junit.Test)12 JdbcStatement (org.finra.herd.model.api.xml.JdbcStatement)9 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 Parameter (org.finra.herd.model.api.xml.Parameter)3 S3PropertiesLocation (org.finra.herd.model.api.xml.S3PropertiesLocation)3 FieldExtension (org.activiti.bpmn.model.FieldExtension)2 DataSource (javax.sql.DataSource)1 JdbcStatementResultSetRow (org.finra.herd.model.api.xml.JdbcStatementResultSetRow)1 Job (org.finra.herd.model.api.xml.Job)1 JobCreateRequest (org.finra.herd.model.api.xml.JobCreateRequest)1 DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)1 Transactional (org.springframework.transaction.annotation.Transactional)1