@@ -546,40 +546,45 @@ public void testValidateJsonTimestamp() throws IOException, InitializationExcept
546
546
547
547
runner .setProperty (ValidateRecord .STRICT_TYPE_CHECKING , "true" );
548
548
final Path timestampPath = Paths .get ("src/test/resources/TestValidateRecord/timestamp.json" );
549
+
550
+ // 1) Valid with explicit schema + slash format
549
551
runner .enqueue (timestampPath );
550
552
runner .run ();
551
553
552
554
runner .assertTransferCount (ValidateRecord .REL_VALID , 1 );
553
555
final MockFlowFile validFlowFile = runner .getFlowFilesForRelationship (ValidateRecord .REL_VALID ).getFirst ();
554
556
validFlowFile .assertContentEquals (new File ("src/test/resources/TestValidateRecord/timestamp.json" ));
555
557
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
557
559
runner .clearTransferState ();
558
560
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.
571
561
runner .disableControllerService (jsonReader );
572
562
runner .setProperty (jsonReader , ValidateRecord .SCHEMA_ACCESS_STRATEGY , SchemaInferenceUtil .INFER_SCHEMA .getValue ());
573
563
runner .setProperty (jsonReader , DateTimeUtils .TIMESTAMP_FORMAT , "yyyy/MM/dd HH:mm:ss" );
574
564
runner .enableControllerService (jsonReader );
575
565
576
- runner .clearTransferState ();
577
566
runner .enqueue (timestampPath );
578
567
runner .run ();
579
568
580
569
runner .assertTransferCount (ValidateRecord .REL_VALID , 1 );
581
570
final MockFlowFile validFlowFileInferredSchema = runner .getFlowFilesForRelationship (ValidateRecord .REL_VALID ).getFirst ();
582
571
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" ));
583
588
}
584
589
585
590
@ Test
0 commit comments