use of org.finra.herd.model.api.xml.JdbcExecutionRequest in project herd by FINRAOS.
the class JdbcServiceTest method testExecuteJdbcWithS3PropertiesSuccess.
/**
* Execute JDBC using S3 properties file. Unfortunately, not many assertions that can be done through the service layer. Asserts that no errors are thrown,
* and that the response SQL does not expose the secrets.
*/
@Test
public void testExecuteJdbcWithS3PropertiesSuccess() {
String s3BucketName = "test_bucket";
String s3ObjectKey = "test_key";
String content = "foo=bar";
putS3Object(s3BucketName, s3ObjectKey, content);
JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
jdbcExecutionRequest.getConnection().setUrl("test_url_${foo}");
jdbcExecutionRequest.getConnection().setUsername("test_username_${foo}");
jdbcExecutionRequest.getConnection().setPassword("test_password_${foo}");
JdbcStatement jdbcStatement = jdbcExecutionRequest.getStatements().get(0);
jdbcStatement.setSql("test_sql_${foo}");
jdbcExecutionRequest.setS3PropertiesLocation(new S3PropertiesLocation(s3BucketName, s3ObjectKey));
try {
JdbcExecutionResponse jdbcExecutionResponse = jdbcService.executeJdbc(jdbcExecutionRequest);
Assert.assertEquals("jdbc execution response statement [0] sql", "test_sql_${foo}", jdbcExecutionResponse.getStatements().get(0).getSql());
} catch (Exception e) {
Assert.fail("unexpected exception was thrown. " + e);
}
}
use of org.finra.herd.model.api.xml.JdbcExecutionRequest in project herd by FINRAOS.
the class JdbcServiceTest method testExecuteJdbcStatementTypeQueryError.
/**
* Test case where user specifies a QUERY statement type, but there are SQL errors. The status should be ERROR and no result set should exist in the
* result.
*/
@Test
public void testExecuteJdbcStatementTypeQueryError() {
// Get test request
JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultQueryJdbcExecutionRequest();
JdbcStatement expectedJdbcStatement = jdbcExecutionRequest.getStatements().get(0);
expectedJdbcStatement.setSql(MockJdbcOperations.CASE_2_SQL);
JdbcExecutionResponse jdbcExecutionResponse = jdbcService.executeJdbc(jdbcExecutionRequest);
Assert.assertEquals("JDBC statements size", 1, jdbcExecutionResponse.getStatements().size());
JdbcStatement actualJdbcStatement = jdbcExecutionResponse.getStatements().get(0);
Assert.assertNotNull("JDBC statement error message", actualJdbcStatement.getErrorMessage());
Assert.assertEquals("JDBC statement error message", "java.sql.SQLException: test DataIntegrityViolationException cause", actualJdbcStatement.getErrorMessage());
Assert.assertNull("JDBC statement result", actualJdbcStatement.getResult());
Assert.assertEquals("JDBC statement status", JdbcStatementStatus.ERROR, actualJdbcStatement.getStatus());
Assert.assertEquals("JDBC statement type", expectedJdbcStatement.getType(), actualJdbcStatement.getType());
Assert.assertNull("JDBC statement result set", actualJdbcStatement.getResultSet());
}
use of org.finra.herd.model.api.xml.JdbcExecutionRequest in project herd by FINRAOS.
the class JdbcServiceTest method testExecuteJdbcParamValidationStatementsEmpty.
/**
* Parameter validation, request statement list is empty
*/
@Test
public void testExecuteJdbcParamValidationStatementsEmpty() {
JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
jdbcExecutionRequest.getStatements().clear();
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 statements are required", e.getMessage());
}
}
use of org.finra.herd.model.api.xml.JdbcExecutionRequest in project herd by FINRAOS.
the class JdbcServiceTest method testExecuteJdbcParamValidationConnectionUsernameNull.
/**
* Parameter validation, request connection username is null. Username can be empty however, since some databases allow that.
*/
@Test
public void testExecuteJdbcParamValidationConnectionUsernameNull() {
JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
jdbcExecutionRequest.getConnection().setUsername(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 user name is required", e.getMessage());
}
}
use of org.finra.herd.model.api.xml.JdbcExecutionRequest in project herd by FINRAOS.
the class JdbcServiceTest method testExecuteJdbcStatementErrorContinueOnError.
/**
* Test case where statements result in errors, but continue on error flag is set to true for those statements. The subsequent statements should continue
* executing.
*/
@Test
public void testExecuteJdbcStatementErrorContinueOnError() {
// 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, true, null, null, null, null));
jdbcExecutionRequest.getStatements().add(new JdbcStatement(JdbcStatementType.UPDATE, MockJdbcOperations.CASE_1_SQL, false, null, null, null, null));
// 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 actualJdbcStatement = jdbcExecutionResponse.getStatements().get(0);
Assert.assertEquals("JDBC statement [0] status", JdbcStatementStatus.SUCCESS, actualJdbcStatement.getStatus());
}
{
JdbcStatement expectedJdbcStatement = jdbcExecutionResponse.getStatements().get(1);
JdbcStatement actualJdbcStatement = jdbcExecutionResponse.getStatements().get(1);
Assert.assertEquals("JDBC statement [1] continue on error", expectedJdbcStatement.isContinueOnError(), actualJdbcStatement.isContinueOnError());
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 expectedJdbcStatement = jdbcExecutionResponse.getStatements().get(2);
JdbcStatement actualJdbcStatement = jdbcExecutionResponse.getStatements().get(2);
Assert.assertEquals("JDBC statement [2] status", expectedJdbcStatement.isContinueOnError(), actualJdbcStatement.isContinueOnError());
Assert.assertEquals("JDBC statement [2] status", JdbcStatementStatus.SUCCESS, actualJdbcStatement.getStatus());
}
}
Aggregations