diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ValidateJson.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ValidateJson.java index 2c9b1e7b05..b28a40d007 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ValidateJson.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ValidateJson.java @@ -187,15 +187,18 @@ public class ValidateJson extends AbstractProcessor { if (errors.isEmpty()) { getLogger().debug("JSON {} valid", flowFile); + session.getProvenanceReporter().route(flowFile, REL_VALID); session.transfer(flowFile, REL_VALID); } else { final String validationMessages = errors.toString(); flowFile = session.putAttribute(flowFile, ERROR_ATTRIBUTE_KEY, validationMessages); getLogger().warn("JSON {} invalid: Validation Errors {}", flowFile, validationMessages); + session.getProvenanceReporter().route(flowFile, REL_INVALID); session.transfer(flowFile, REL_INVALID); } } catch (final Exception e) { getLogger().error("JSON processing failed {}", flowFile, e); + session.getProvenanceReporter().route(flowFile, REL_FAILURE); session.transfer(flowFile, REL_FAILURE); } } diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateJson.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateJson.java index 49c39838c1..37b4f89408 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateJson.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateJson.java @@ -18,6 +18,7 @@ package org.apache.nifi.processors.standard; import org.apache.commons.io.IOUtils; import org.apache.nifi.processor.Relationship; +import org.apache.nifi.provenance.ProvenanceEventType; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.junit.jupiter.api.BeforeEach; @@ -32,6 +33,7 @@ import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Objects; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -62,6 +64,8 @@ class TestValidateJson { runner.assertTransferCount(ValidateJson.REL_VALID, 1); assertValidationErrors(ValidateJson.REL_VALID, false); + assertEquals(1, runner.getProvenanceEvents().size()); + assertEquals(ProvenanceEventType.ROUTE, runner.getProvenanceEvents().get(0).getEventType()); } @Test @@ -77,6 +81,8 @@ class TestValidateJson { runner.assertTransferCount(ValidateJson.REL_VALID, 1); assertValidationErrors(ValidateJson.REL_VALID, false); + assertEquals(1, runner.getProvenanceEvents().size()); + assertEquals(ProvenanceEventType.ROUTE, runner.getProvenanceEvents().get(0).getEventType()); } @Test @@ -93,6 +99,8 @@ class TestValidateJson { runner.assertTransferCount(ValidateJson.REL_VALID, 1); assertValidationErrors(ValidateJson.REL_VALID, false); + assertEquals(1, runner.getProvenanceEvents().size()); + assertEquals(ProvenanceEventType.ROUTE, runner.getProvenanceEvents().get(0).getEventType()); } @Test @@ -109,6 +117,8 @@ class TestValidateJson { runner.assertTransferCount(ValidateJson.REL_VALID, 0); assertValidationErrors(ValidateJson.REL_INVALID, true); + assertEquals(1, runner.getProvenanceEvents().size()); + assertEquals(ProvenanceEventType.ROUTE, runner.getProvenanceEvents().get(0).getEventType()); } @Test @@ -125,6 +135,8 @@ class TestValidateJson { runner.assertTransferCount(ValidateJson.REL_VALID, 0); assertValidationErrors(ValidateJson.REL_INVALID, true); + assertEquals(1, runner.getProvenanceEvents().size()); + assertEquals(ProvenanceEventType.ROUTE, runner.getProvenanceEvents().get(0).getEventType()); } @Test @@ -141,6 +153,8 @@ class TestValidateJson { runner.assertTransferCount(ValidateJson.REL_VALID, 0); assertValidationErrors(ValidateJson.REL_FAILURE, false); + assertEquals(1, runner.getProvenanceEvents().size()); + assertEquals(ProvenanceEventType.ROUTE, runner.getProvenanceEvents().get(0).getEventType()); } @Test