/** * Returns a valid list of JDBC QUERY statements.It contains only 1 statement, and the statement is CASE_1_SQL in mock JDBC (success, result 1) * * @return list of statements */ private List<JdbcStatement> createDefaultQueryJdbcStatements() { List<JdbcStatement> jdbcStatements = new ArrayList<>(); { JdbcStatement jdbcStatement = new JdbcStatement(); jdbcStatement.setType(JdbcStatementType.QUERY); jdbcStatement.setSql(MockJdbcOperations.CASE_1_SQL); jdbcStatements.add(jdbcStatement); } return jdbcStatements; }
/** * Returns a valid list of JDBC UPDATE statements. It contains only 1 statement, and the statement is CASE_1_SQL in mock JDBC (success, result 1) * * @return list of statements. */ private List<JdbcStatement> createDefaultUpdateJdbcStatements() { List<JdbcStatement> jdbcStatements = new ArrayList<>(); { JdbcStatement jdbcStatement = new JdbcStatement(); jdbcStatement.setType(JdbcStatementType.UPDATE); jdbcStatement.setSql(MockJdbcOperations.CASE_1_SQL); jdbcStatements.add(jdbcStatement); } return jdbcStatements; } }
/** * Creates and returns a {@link JdbcStatement} at a state which has not yet been executed based on the given request. * <p/> * The status will be set to {@link JdbcStatementStatus#SKIPPED} and result null. * * @param requestJdbcStatement the requested JDBC statement * * @return a new {@link JdbcStatement} */ private JdbcStatement createDefaultResponseJdbcStatement(JdbcStatement requestJdbcStatement) { JdbcStatement responseJdbcStatement = new JdbcStatement(); responseJdbcStatement.setType(requestJdbcStatement.getType()); responseJdbcStatement.setSql(requestJdbcStatement.getSql()); responseJdbcStatement.setContinueOnError(requestJdbcStatement.isContinueOnError()); responseJdbcStatement.setStatus(JdbcStatementStatus.SKIPPED); return responseJdbcStatement; }
/** * Creates and returns a {@link JdbcStatement} at a state which has not yet been executed based on the given request. * <p/> * The status will be set to {@link JdbcStatementStatus#SKIPPED} and result null. * * @param requestJdbcStatement the requested JDBC statement * * @return a new {@link JdbcStatement} */ private JdbcStatement createDefaultResponseJdbcStatement(JdbcStatement requestJdbcStatement) { JdbcStatement responseJdbcStatement = new JdbcStatement(); responseJdbcStatement.setType(requestJdbcStatement.getType()); responseJdbcStatement.setSql(requestJdbcStatement.getSql()); responseJdbcStatement.setContinueOnError(requestJdbcStatement.isContinueOnError()); responseJdbcStatement.setStatus(JdbcStatementStatus.SKIPPED); return responseJdbcStatement; }
@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()); } }
@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); }); }
/** * 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()); } }
/** * 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()); }
/** * 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()); }
/** * 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); } }
JdbcStatement expectedJdbcStatement = new JdbcStatement(); expectedJdbcStatement.setType(originalJdbcStatement.getType()); expectedJdbcStatement.setSql(originalJdbcStatement.getSql()); expectedJdbcStatement.setStatus(JdbcStatementStatus.SUCCESS); expectedJdbcStatement.setResult("1");
sourceSql = this.getSql(); String copySql = ((String) strategy.copy(LocatorUtils.property(locator, "sql", sourceSql), sourceSql, (this.sql!= null))); copy.setSql(copySql); } else { if (sqlShouldBeCopiedAndSet == Boolean.FALSE) {
sourceSql = this.getSql(); String copySql = ((String) strategy.copy(LocatorUtils.property(locator, "sql", sourceSql), sourceSql, (this.sql!= null))); copy.setSql(copySql); } else { if (sqlShouldBeCopiedAndSet == Boolean.FALSE) {
sourceSql = this.getSql(); String copySql = ((String) strategy.copy(LocatorUtils.property(locator, "sql", sourceSql), sourceSql, (this.sql!= null))); copy.setSql(copySql); } else { if (sqlShouldBeCopiedAndSet == Boolean.FALSE) {