/** * Creates a default JDBC execution request which is guaranteed to work. The request contains a single statement of QUERY type. * * @return a valid JDBC request */ public JdbcExecutionRequest createDefaultQueryJdbcExecutionRequest() { JdbcConnection jdbcConnection = createDefaultJdbcConnection(); List<JdbcStatement> jdbcStatements = createDefaultQueryJdbcStatements(); JdbcExecutionRequest jdbcExecutionRequest = createJdbcExecutionRequest(jdbcConnection, jdbcStatements); return jdbcExecutionRequest; }
@Test public void testExecuteJdbcErrorValidation() throws Exception { JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest(); jdbcExecutionRequest.setConnection(null); List<FieldExtension> fieldExtensionList = new ArrayList<>(); List<Parameter> parameters = new ArrayList<>(); populateParameters(jdbcExecutionRequest, fieldExtensionList, parameters); Map<String, Object> variableValuesToValidate = new HashMap<>(); variableValuesToValidate.put(BaseJavaDelegate.VARIABLE_JSON_RESPONSE, VARIABLE_VALUE_IS_NULL); variableValuesToValidate.put(ActivitiRuntimeHelper.VARIABLE_ERROR_MESSAGE, "JDBC connection is required"); executeWithoutLogging(ActivitiRuntimeHelper.class, () -> { testActivitiServiceTaskFailure(JAVA_DELEGATE_CLASS_NAME, fieldExtensionList, parameters, variableValuesToValidate); }); }
/** * Creates a default JDBC execution request which is guaranteed to work. The request contains a single statement of UPDATE type. * * @return a valid JDBC request */ public JdbcExecutionRequest createDefaultUpdateJdbcExecutionRequest() { JdbcConnection jdbcConnection = createDefaultJdbcConnection(); List<JdbcStatement> jdbcStatements = createDefaultUpdateJdbcStatements(); JdbcExecutionRequest jdbcExecutionRequest = createJdbcExecutionRequest(jdbcConnection, jdbcStatements); return jdbcExecutionRequest; }
JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultQueryJdbcExecutionRequest();
/** * 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()); }
/** * 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()); } }
JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultQueryJdbcExecutionRequest(); JdbcStatement expectedJdbcStatement = jdbcExecutionRequest.getStatements().get(0);
@Test public void testExecuteJdbcSuccess() throws Exception { JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest(); List<FieldExtension> fieldExtensionList = new ArrayList<>(); List<Parameter> parameters = new ArrayList<>(); populateParameters(jdbcExecutionRequest, fieldExtensionList, parameters); JdbcExecutionResponse expectedJdbcExecutionResponse = new JdbcExecutionResponse(); expectedJdbcExecutionResponse.setStatements(jdbcExecutionRequest.getStatements()); expectedJdbcExecutionResponse.getStatements().get(0).setStatus(JdbcStatementStatus.SUCCESS); expectedJdbcExecutionResponse.getStatements().get(0).setResult("1"); String expectedJdbcExecutionResponseJson = jsonHelper.objectToJson(expectedJdbcExecutionResponse); Map<String, Object> variableValuesToValidate = new HashMap<>(); variableValuesToValidate.put(BaseJavaDelegate.VARIABLE_JSON_RESPONSE, expectedJdbcExecutionResponseJson); testActivitiServiceTaskSuccess(JAVA_DELEGATE_CLASS_NAME, fieldExtensionList, parameters, variableValuesToValidate); }
@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()); } }
/** * 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()); } }
/** * Parameter validation, request statement list is null */ @Test public void testExecuteJdbcParamValidationStatementsNull() { JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest(); jdbcExecutionRequest.setStatements(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 statements are required", e.getMessage()); } }
/** * 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()); } }
/** * 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()); } }
@Test public void testExecuteJdbcErrorStatement() throws Exception { JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest(); jdbcExecutionRequest.getStatements().get(0).setSql(MockJdbcOperations.CASE_2_SQL); List<FieldExtension> fieldExtensionList = new ArrayList<>(); List<Parameter> parameters = new ArrayList<>(); populateParameters(jdbcExecutionRequest, fieldExtensionList, parameters); JdbcExecutionResponse expectedJdbcExecutionResponse = new JdbcExecutionResponse(); expectedJdbcExecutionResponse.setStatements(jdbcExecutionRequest.getStatements()); expectedJdbcExecutionResponse.getStatements().get(0).setStatus(JdbcStatementStatus.ERROR); expectedJdbcExecutionResponse.getStatements().get(0).setErrorMessage("java.sql.SQLException: test DataIntegrityViolationException cause"); String expectedJdbcExecutionResponseString = jsonHelper.objectToJson(expectedJdbcExecutionResponse); Map<String, Object> variableValuesToValidate = new HashMap<>(); variableValuesToValidate.put(BaseJavaDelegate.VARIABLE_JSON_RESPONSE, expectedJdbcExecutionResponseString); variableValuesToValidate.put(ActivitiRuntimeHelper.VARIABLE_ERROR_MESSAGE, "There are failed executions. See JSON response for details."); executeWithoutLogging(ActivitiRuntimeHelper.class, () -> { testActivitiServiceTaskFailure(JAVA_DELEGATE_CLASS_NAME, fieldExtensionList, parameters, variableValuesToValidate); }); }
JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
/** * 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()); } }
/** * 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()); } }
/** * 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()); } }
/** * 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()); } }
JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest(); jdbcExecutionRequest.getStatements().add(new JdbcStatement());