Search in sources :

Example 1 with JdbcExecutionRequest

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

the class JdbcServiceTest method testExecuteJdbcParamValidationS3PropertiesLocationKeyBlank.

/**
 * When S3 properties location is specified, object key must not be a blank string.
 */
@Test
public void testExecuteJdbcParamValidationS3PropertiesLocationKeyBlank() {
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    jdbcExecutionRequest.setS3PropertiesLocation(new S3PropertiesLocation("test_bucket", BLANK_TEXT));
    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", "S3 properties location key 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 2 with JdbcExecutionRequest

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

the class JdbcServiceTest method testExecuteJdbcErrorConnection.

@Test
public void testExecuteJdbcErrorConnection() {
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    jdbcExecutionRequest.getStatements().get(0).setSql(MockJdbcOperations.CASE_3_SQL);
    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", "java.sql.SQLException: test CannotGetJdbcConnectionException cause", e.getMessage());
    }
}
Also used : JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) Test(org.junit.Test)

Example 3 with JdbcExecutionRequest

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

the class JdbcServiceTest method testExecuteJdbcParamValidationConnectionNull.

/**
 * Parameter validation, request connection is null
 */
@Test
public void testExecuteJdbcParamValidationConnectionNull() {
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    jdbcExecutionRequest.setConnection(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 is required", e.getMessage());
    }
}
Also used : JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) Test(org.junit.Test)

Example 4 with JdbcExecutionRequest

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

the class JdbcServiceTest method testExecuteJdbcSensitiveDataIsMaskedInErrorMessage.

/**
 * Some JDBC exception messages echoes back parts of the SQL statement. This is problem for security if some of the variables were replaced, and may
 * accidentally expose secret information in the response error message. The application should mask any values given in the properties which exist in the
 * exception message.
 * <p/>
 * This test will use a SQL that will throw an exception, and the exception message is known. Then asserts that the value has been replaced with a mask in
 * the response error message.
 */
@Test
public void testExecuteJdbcSensitiveDataIsMaskedInErrorMessage() {
    String s3BucketName = "test_bucket";
    String s3ObjectKey = "test_key";
    String content = "foo=DataIntegrityViolationException";
    putS3Object(s3BucketName, s3ObjectKey, content);
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    jdbcExecutionRequest.getStatements().get(0).setSql(MockJdbcOperations.CASE_2_SQL);
    jdbcExecutionRequest.setS3PropertiesLocation(new S3PropertiesLocation(s3BucketName, s3ObjectKey));
    JdbcExecutionResponse jdbcExecutionResponse = jdbcService.executeJdbc(jdbcExecutionRequest);
    Assert.assertEquals("jdbc execution response statement [0] error message", "java.sql.SQLException: test **** cause", jdbcExecutionResponse.getStatements().get(0).getErrorMessage());
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) JdbcExecutionResponse(org.finra.herd.model.api.xml.JdbcExecutionResponse) Test(org.junit.Test)

Example 5 with JdbcExecutionRequest

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

the class JdbcServiceTest method testExecuteJdbcParamValidationStatementTypeNull.

/**
 * Parameter validation, request statement type is null
 */
@Test
public void testExecuteJdbcParamValidationStatementTypeNull() {
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    jdbcExecutionRequest.getStatements().get(0).setType(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 statement [0] type 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