Search in sources :

Example 21 with JdbcExecutionRequest

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

the class JdbcServiceTest method testExecuteJdbcParamValidationS3PropertiesLocationBucketNameBlank.

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

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

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

the class JdbcServiceTest method testExecuteJdbcParamValidationConnectionDatabaseTypeNull.

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

Example 24 with JdbcExecutionRequest

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

the class JdbcServiceTest method testExecuteJdbcParamValidationStatementsExceedMaximum.

/**
 * Parameter validation, request statement list has more statements than configured maximum.
 */
@Test
public void testExecuteJdbcParamValidationStatementsExceedMaximum() {
    /*
         * Update environment variable to use a maximum statement
         */
    int maxStatements = 1;
    try {
        HashMap<String, Object> overrideMap = new HashMap<>();
        overrideMap.put(ConfigurationValue.JDBC_MAX_STATEMENTS.getKey(), maxStatements);
        modifyPropertySourceInEnvironment(overrideMap);
    } catch (Exception e) {
        throw new RuntimeException("Error modifying environment variable.", e);
    }
    /*
         * Add 1 more statement to the JDBC request.
         * The default request should already have 1 statement.
         */
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    jdbcExecutionRequest.getStatements().add(new JdbcStatement());
    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", "The number of JDBC statements exceeded the maximum allowed " + maxStatements + ".", e.getMessage());
    } finally {
        /*
             * 
             */
        try {
            restorePropertySourceInEnvironment();
        } catch (Exception e) {
            throw new RuntimeException("Error restoring environment variables. Subsequent tests may be affected.", e);
        }
    }
}
Also used : JdbcStatement(org.finra.herd.model.api.xml.JdbcStatement) HashMap(java.util.HashMap) JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) Test(org.junit.Test)

Example 25 with JdbcExecutionRequest

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

the class JdbcServiceTest method testExecuteJdbcParamValidationConnectionUrlEmpty.

/**
 * Parameter validation, request connection URL is empty
 */
@Test
public void testExecuteJdbcParamValidationConnectionUrlEmpty() {
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    jdbcExecutionRequest.getConnection().setUrl(" \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 connection URL 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