|
@@ -141,60 +141,4 @@ public class MapperDateTest {
|
|
|
assertEquals("Invalid value wasn't returned as it is", invalidValue, mappedValue);
|
|
|
assertTrue("jsonObj is not empty", jsonObj.isEmpty());
|
|
|
}
|
|
|
-
|
|
|
- @Test
|
|
|
- public void testMapperDate_patternWithoutYear_previousYearLog() throws Exception {
|
|
|
- LOG.info("testMapperDate_patternWithoutYear_previousYearLog()");
|
|
|
- String fieldName = "logtime";
|
|
|
- Calendar currentCalendar = Calendar.getInstance();
|
|
|
- Map<String, Object> mapConfigs = new HashMap<>();
|
|
|
- mapConfigs.put("target_date_pattern", "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
- String srcDatePattern ="MMM dd HH:mm:ss";
|
|
|
- mapConfigs.put("src_date_pattern", srcDatePattern);
|
|
|
- MapperDate mapperDate = new MapperDate();
|
|
|
- assertTrue("Could not initialize!", mapperDate.init(null, fieldName, null, mapConfigs));
|
|
|
- Map<String, Object> jsonObj = new HashMap<>();
|
|
|
- Calendar nextMonthCalendar = Calendar.getInstance();
|
|
|
-
|
|
|
- nextMonthCalendar.set(Calendar.MONTH, currentCalendar.get(Calendar.MONTH)+1 );
|
|
|
- String inputDateStr = new SimpleDateFormat("MMM").format(nextMonthCalendar.getTime()) + " 01 12:01:45";
|
|
|
- Object mappedValue = mapperDate.apply(jsonObj, inputDateStr);
|
|
|
- Date mappedDateValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse(mappedValue.toString());
|
|
|
- String mappedDateValueStr = new SimpleDateFormat(srcDatePattern).format(mappedDateValue);
|
|
|
- assertEquals(Date.class, mappedDateValue.getClass());
|
|
|
-
|
|
|
- int expectedLogYear = currentCalendar.get(Calendar.YEAR)-1;
|
|
|
- Calendar mapppedValueCalendar = Calendar.getInstance();
|
|
|
- mapppedValueCalendar.setTime(mappedDateValue);
|
|
|
- assertEquals("Mapped year wasn't matched properly", expectedLogYear, mapppedValueCalendar.get(Calendar.YEAR));
|
|
|
- assertEquals("Mapped date wasn't matched properly", inputDateStr, mappedDateValueStr);
|
|
|
- assertEquals("Value wasn't put into jsonObj",mappedValue, jsonObj.remove(fieldName));
|
|
|
- assertTrue("jsonObj is not empty", jsonObj.isEmpty());
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void testMapperDate_patternWithoutYear_currentYearLog() throws Exception {
|
|
|
- LOG.info("testMapperDate_patternWithoutYear_currentYearLog()");
|
|
|
- String fieldName = "logtime";
|
|
|
- Calendar currentCalendar = Calendar.getInstance();
|
|
|
- Map<String, Object> mapConfigs = new HashMap<>();
|
|
|
- mapConfigs.put("target_date_pattern", "yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
- String srcDatePattern ="MMM dd HH:mm:ss";
|
|
|
- mapConfigs.put("src_date_pattern", srcDatePattern);
|
|
|
- MapperDate mapperDate = new MapperDate();
|
|
|
- assertTrue("Could not initialize!", mapperDate.init(null, fieldName, null, mapConfigs));
|
|
|
- Map<String, Object> jsonObj = new HashMap<>();
|
|
|
- String inputDateStr = new SimpleDateFormat("MMM").format(currentCalendar.getTime()) + " 01 12:01:45";
|
|
|
- Object mappedValue = mapperDate.apply(jsonObj, inputDateStr);
|
|
|
- Date mappedDateValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse(mappedValue.toString());
|
|
|
- String mappedDateValueStr = new SimpleDateFormat(srcDatePattern).format(mappedDateValue);
|
|
|
- assertEquals(Date.class, mappedDateValue.getClass());
|
|
|
- int expectedLogYear = currentCalendar.get(Calendar.YEAR);
|
|
|
- Calendar mapppedValueCalendar = Calendar.getInstance();
|
|
|
- mapppedValueCalendar.setTime(mappedDateValue);
|
|
|
- assertEquals("Mapped year wasn't matched properly", expectedLogYear, mapppedValueCalendar.get(Calendar.YEAR));
|
|
|
- assertEquals("Mapped date wasn't matched properly", inputDateStr, mappedDateValueStr);
|
|
|
- assertEquals("Value wasn't put into jsonObj",mappedValue, jsonObj.remove(fieldName));
|
|
|
- assertTrue("jsonObj is not empty", jsonObj.isEmpty());
|
|
|
- }
|
|
|
}
|