From b0ab364f61612b48d7ccddad010be97b759379c2 Mon Sep 17 00:00:00 2001 From: exceptionfactory Date: Thu, 8 Dec 2022 22:15:55 -0600 Subject: [PATCH] NIFI-10967 Corrected TestWriteJsonResult mixed arrays Signed-off-by: Matthew Burgess This closes #6773 --- .../org/apache/nifi/json/TestWriteJsonResult.java | 14 ++++++++------ .../choice-of-array-string-or-array-record.json | 9 --------- 2 files changed, 8 insertions(+), 15 deletions(-) delete mode 100644 nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/resources/json/choice-of-array-string-or-array-record.json diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/json/TestWriteJsonResult.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/json/TestWriteJsonResult.java index 3929070e64..1cb0133b7d 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/json/TestWriteJsonResult.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/json/TestWriteJsonResult.java @@ -34,8 +34,8 @@ import org.apache.nifi.serialization.record.SerializedForm; import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; import java.io.IOException; import java.math.BigDecimal; import java.math.BigInteger; @@ -513,9 +513,12 @@ class TestWriteJsonResult { @Test void testChoiceArrayOfStringsOrArrayOfRecords() throws IOException { - final String FILE_LOCATION = "src/test/resources/json/choice-of-array-string-or-array-record.json"; + final String jsonFirstItem = "{\"itemData\":[\"test\"]}"; + final String jsonSecondItem = "{\"itemData\":[{\"quantity\":10}]}"; + final String json = String.format("[{\"items\":[%s,%s]}]", jsonFirstItem, jsonSecondItem); + final JsonSchemaInference jsonSchemaInference = new JsonSchemaInference(new TimeValueInference(null, null, null)); - final RecordSchema schema = jsonSchemaInference.inferSchema(new JsonRecordSource(new FileInputStream(FILE_LOCATION))); + final RecordSchema schema = jsonSchemaInference.inferSchema(new JsonRecordSource(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)))); final Map itemData1 = new HashMap<>(); itemData1.put("itemData", new String[]{"test"}); @@ -539,7 +542,7 @@ class TestWriteJsonResult { Record topLevelRecord = new MapRecord(schema, values); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (final WriteJsonResult writer = new WriteJsonResult(Mockito.mock(ComponentLog.class), schema, new SchemaNameAsAttribute(), baos, true, + try (final WriteJsonResult writer = new WriteJsonResult(Mockito.mock(ComponentLog.class), schema, new SchemaNameAsAttribute(), baos, false, NullSuppression.NEVER_SUPPRESS, OutputGrouping.OUTPUT_ARRAY, null, null, null)) { writer.beginRecordSet(); writer.writeRecord(topLevelRecord); @@ -548,8 +551,7 @@ class TestWriteJsonResult { final byte[] data = baos.toByteArray(); - final String expected = new String(Files.readAllBytes(Paths.get(FILE_LOCATION)), StandardCharsets.UTF_8); final String output = new String(data, StandardCharsets.UTF_8); - assertEquals(expected, output); + assertEquals(json, output); } } diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/resources/json/choice-of-array-string-or-array-record.json b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/resources/json/choice-of-array-string-or-array-record.json deleted file mode 100644 index 3e48dd0204..0000000000 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/resources/json/choice-of-array-string-or-array-record.json +++ /dev/null @@ -1,9 +0,0 @@ -[ { - "items" : [ { - "itemData" : [ "test" ] - }, { - "itemData" : [ { - "quantity" : 10 - } ] - } ] -} ] \ No newline at end of file