You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by ijokarumawak <gi...@git.apache.org> on 2018/03/16 09:52:24 UTC

[GitHub] nifi pull request #2473: NIFI-4882: Resolve issue with parsing custom date, ...

Github user ijokarumawak commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2473#discussion_r175000544
  
    --- Diff: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/csv/TestCSVRecordReader.java ---
    @@ -106,6 +117,195 @@ public void testDate() throws IOException, MalformedRecordException {
             }
         }
     
    +    @Test
    +    public void testDateNoCoersionSuccess() throws IOException, MalformedRecordException {
    +        final String text = "date\n11/30/1983";
    +
    +        final List<RecordField> fields = new ArrayList<>();
    +        fields.add(new RecordField("date", RecordFieldType.DATE.getDataType()));
    +        final RecordSchema schema = new SimpleRecordSchema(fields);
    +
    +        try (final InputStream bais = new ByteArrayInputStream(text.getBytes());
    +             final CSVRecordReader reader = new CSVRecordReader(bais, Mockito.mock(ComponentLog.class), schema, format, true, false,
    +                     "MM/dd/yyyy", RecordFieldType.TIME.getDefaultFormat(), RecordFieldType.TIMESTAMP.getDefaultFormat(), "UTF-8")) {
    +
    +            final Record record = reader.nextRecord(false, false);
    +            final java.sql.Date date = (Date) record.getValue("date");
    +            final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("gmt"));
    +            calendar.setTimeInMillis(date.getTime());
    +
    +            assertEquals(1983, calendar.get(Calendar.YEAR));
    +            assertEquals(10, calendar.get(Calendar.MONTH));
    +            assertEquals(30, calendar.get(Calendar.DAY_OF_MONTH));
    +        }
    +    }
    +
    +    @Test
    +    public void testDateNoCoersionFailure() throws IOException, MalformedRecordException {
    --- End diff --
    
    The purpose of test would be clearer if we name this as 'testDateNoCoersionUnexpectedFormat'.
    Same comment goes for time and timestamp tests, too.


---