Skip to content

Commit d9eb462

Browse files
hwu2024pvillard31
authored andcommitted
NIFI-11362 - Stabilize TestValidateRecord#testValidateJsonTimestamp by reordering scenarios and resetting reader properties
Signed-off-by: Pierre Villard <[email protected]> This closes #10359.
1 parent 066b3d6 commit d9eb462

File tree

1 file changed

+19
-14
lines changed
  • nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard

1 file changed

+19
-14
lines changed

nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateRecord.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -546,40 +546,45 @@ public void testValidateJsonTimestamp() throws IOException, InitializationExcept
546546

547547
runner.setProperty(ValidateRecord.STRICT_TYPE_CHECKING, "true");
548548
final Path timestampPath = Paths.get("src/test/resources/TestValidateRecord/timestamp.json");
549+
550+
// 1) Valid with explicit schema + slash format
549551
runner.enqueue(timestampPath);
550552
runner.run();
551553

552554
runner.assertTransferCount(ValidateRecord.REL_VALID, 1);
553555
final MockFlowFile validFlowFile = runner.getFlowFilesForRelationship(ValidateRecord.REL_VALID).getFirst();
554556
validFlowFile.assertContentEquals(new File("src/test/resources/TestValidateRecord/timestamp.json"));
555557

556-
// Test with a timestamp that has an invalid format.
558+
// 2) Inferred schema — run this BEFORE the invalid-format scenario to avoid order-dependence
557559
runner.clearTransferState();
558560

559-
runner.disableControllerService(jsonReader);
560-
runner.setProperty(jsonReader, DateTimeUtils.TIMESTAMP_FORMAT, "yyyy-MM-dd HH:mm:ss");
561-
runner.enqueue(timestampPath);
562-
runner.enableControllerService(jsonReader);
563-
564-
runner.run();
565-
566-
runner.assertTransferCount(ValidateRecord.REL_INVALID, 1);
567-
final MockFlowFile invalidFlowFile = runner.getFlowFilesForRelationship(ValidateRecord.REL_INVALID).getFirst();
568-
invalidFlowFile.assertContentEquals(new File("src/test/resources/TestValidateRecord/timestamp.json"));
569-
570-
// Test with an Inferred Schema.
571561
runner.disableControllerService(jsonReader);
572562
runner.setProperty(jsonReader, ValidateRecord.SCHEMA_ACCESS_STRATEGY, SchemaInferenceUtil.INFER_SCHEMA.getValue());
573563
runner.setProperty(jsonReader, DateTimeUtils.TIMESTAMP_FORMAT, "yyyy/MM/dd HH:mm:ss");
574564
runner.enableControllerService(jsonReader);
575565

576-
runner.clearTransferState();
577566
runner.enqueue(timestampPath);
578567
runner.run();
579568

580569
runner.assertTransferCount(ValidateRecord.REL_VALID, 1);
581570
final MockFlowFile validFlowFileInferredSchema = runner.getFlowFilesForRelationship(ValidateRecord.REL_VALID).getFirst();
582571
validFlowFileInferredSchema.assertContentEquals(new File("src/test/resources/TestValidateRecord/timestamp.json"));
572+
573+
// 3) Invalid timestamp format
574+
runner.clearTransferState();
575+
576+
runner.disableControllerService(jsonReader);
577+
// IMPORTANT: switch the READER back to schema-text strategy before changing the format
578+
runner.setProperty(jsonReader, ValidateRecord.SCHEMA_ACCESS_STRATEGY, "schema-text-property");
579+
runner.setProperty(jsonReader, SCHEMA_TEXT, validateSchema);
580+
runner.setProperty(jsonReader, DateTimeUtils.TIMESTAMP_FORMAT, "yyyy-MM-dd HH:mm:ss");
581+
runner.enableControllerService(jsonReader);
582+
583+
runner.enqueue(timestampPath);
584+
runner.run();
585+
runner.assertTransferCount(ValidateRecord.REL_INVALID, 1);
586+
final MockFlowFile invalidFlowFile = runner.getFlowFilesForRelationship(ValidateRecord.REL_INVALID).getFirst();
587+
invalidFlowFile.assertContentEquals(new File("src/test/resources/TestValidateRecord/timestamp.json"));
583588
}
584589

585590
@Test

0 commit comments

Comments
 (0)