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());
}
}
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);
}
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations