Search in sources :

Example 16 with JdbcExecutionRequest

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

the class JdbcServiceTest method testExecuteJdbcWithS3PropertiesParamSqlBlankAfterReplace.

/**
 * If the result of replacing SQL using S3 properties is blank, throws a validation error.
 */
@Test
public void testExecuteJdbcWithS3PropertiesParamSqlBlankAfterReplace() {
    String s3BucketName = "test_bucket";
    String s3ObjectKey = "test_key";
    String content = "foo=";
    putS3Object(s3BucketName, s3ObjectKey, content);
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    jdbcExecutionRequest.getStatements().get(0).setSql("${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 statement [0] SQL is required", e.getMessage());
    }
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) Test(org.junit.Test)

Example 17 with JdbcExecutionRequest

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

the class JdbcServiceTest method testExecuteJdbcStatementTypeQueryMaximumRows.

/**
 * Test case where user specifies a QUERY statement type and a maximum number of rows is specified in the environment.
 */
@Test
public void testExecuteJdbcStatementTypeQueryMaximumRows() {
    int expectedRowSize = 1;
    try {
        Map<String, Object> overrideMap = new HashMap<>();
        overrideMap.put(ConfigurationValue.JDBC_RESULT_MAX_ROWS.getKey(), expectedRowSize);
        modifyPropertySourceInEnvironment(overrideMap);
    } catch (Exception e) {
        throw new RuntimeException("Error modifying environment variables", e);
    }
    try {
        // Get test request
        JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultQueryJdbcExecutionRequest();
        JdbcExecutionResponse jdbcExecutionResponse = jdbcService.executeJdbc(jdbcExecutionRequest);
        Assert.assertEquals("result set row size", expectedRowSize, jdbcExecutionResponse.getStatements().get(0).getResultSet().getRows().size());
    } finally {
        try {
            restorePropertySourceInEnvironment();
        } catch (Exception e) {
            throw new RuntimeException("Error restoring environment variables. Subsequent tests may be affected.", e);
        }
    }
}
Also used : HashMap(java.util.HashMap) JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) JdbcExecutionResponse(org.finra.herd.model.api.xml.JdbcExecutionResponse) Test(org.junit.Test)

Example 18 with JdbcExecutionRequest

use of org.finra.herd.model.api.xml.JdbcExecutionRequest 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 19 with JdbcExecutionRequest

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

the class JdbcServiceTest method testExecuteJdbcParamValidationStatementTypeSqlEmpty.

/**
 * Parameter validation, request statement sql is empty
 */
@Test
public void testExecuteJdbcParamValidationStatementTypeSqlEmpty() {
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    jdbcExecutionRequest.getStatements().get(0).setSql(" \t\n\r");
    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", "JDBC statement [0] SQL is required", e.getMessage());
    }
}
Also used : JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) Test(org.junit.Test)

Example 20 with JdbcExecutionRequest

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

the class JdbcServiceTest method testExecuteJdbcParamValidationConnectionPasswordNull.

/**
 * Parameter validation, request connection password is null. Password can be empty however, since some databases allow that.
 */
@Test
public void testExecuteJdbcParamValidationConnectionPasswordNull() {
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    jdbcExecutionRequest.getConnection().setPassword(null);
    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", "JDBC connection password is required", e.getMessage());
    }
}
Also used : JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) Test(org.junit.Test)

Aggregations

JdbcExecutionRequest (org.finra.herd.model.api.xml.JdbcExecutionRequest)32 Test (org.junit.Test)28 JdbcExecutionResponse (org.finra.herd.model.api.xml.JdbcExecutionResponse)12 JdbcStatement (org.finra.herd.model.api.xml.JdbcStatement)10 HashMap (java.util.HashMap)6 S3PropertiesLocation (org.finra.herd.model.api.xml.S3PropertiesLocation)6 ArrayList (java.util.ArrayList)4 Parameter (org.finra.herd.model.api.xml.Parameter)4 FieldExtension (org.activiti.bpmn.model.FieldExtension)3 JdbcConnection (org.finra.herd.model.api.xml.JdbcConnection)2 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 Transactional (org.springframework.transaction.annotation.Transactional)1