LinuxSyslog3164ParserBase extends LinuxSyslogLineParser { @Override public final Date toDate(String source, String s) { DateTime dt = null; for (DateTimeFormatter fmt : dt_formatters) { try { dt = fmt.parseDateTime(s); dt = dt.withZoneRetainFields(INPUT_TIME_ZONE); dt = dt.withZone(OUTPUT_TIME_ZONE); dt = dt.withYear(curYear); if (s_linuxAdeExtProperties.isYearDefined()) { yearSetter = LinuxSyslogYearSetter.getYearSetter(source); final int yearToUse = yearSetter.getDesiredYear(dt); dt = dt.withYear(yearToUse); } else if (dt.isAfter(END_OF_TODAY)) { dt = dt.withYear(curYear - 1); } else { dt = dt.withYear(curYear); } return dt.toDate(); } catch (IllegalArgumentException e) { if (dt != null) { s_logger.error("Invalid argument encountered.", e); } } } throw new IllegalArgumentException("Failed to parse date " + s); } LinuxSyslog3164ParserBase(LinuxAdeExtProperties linuxAdeExtProperties);  LinuxSyslog3164ParserBase(); static void setAdeExtProperties(LinuxAdeExtProperties linuxAdeExtProperties); static int getAdeExtPropertiesYear(); static DateTimeZone getInputTimeZone(); static DateTimeZone getOutputTimeZone(); @Override final Date toDate(String source, String s); final DateTime getLastDeterminedDateTime(); static final String RFC3164_TIMESTAMP; }
@Test (expected = IllegalArgumentException.class) public void testToDateWithIllegalArgumentException() throws AdeException { LinuxSyslog3164ParserBase pid = new LinuxSyslog3164ParserWithCompAndPid(null); assertEquals("Illegal Argument = bad String ",null,pid.toDate("01/20/2016","")); }
@Test public void testToDate() throws AdeException { LinuxSyslog3164ParserBase pid = new LinuxSyslog3164ParserWithCompAndPid(null); LinuxAdeExtProperties laep = mock(LinuxAdeExtProperties.class, RETURNS_DEEP_STUBS); when(laep.isYearDefined()).thenReturn(true); pid.setAdeExtProperties(laep); DateTime date = DateTimeFormat.forPattern("MMM d HH:mm:ss").withZoneUTC().parseDateTime("JAN 20 10:00:00"); assertEquals("toDate with good input. Since yearSetter is null the year will be 1 " ,date.withYear(0).toDate(),pid.toDate("1","JAN 20 10:00:00")); }