@Test public void testJSONFilterCode_convertFields() throws Exception { init(new FilterJsonDescriptorImpl()); mockOutputManager.write(EasyMock.capture(capture), EasyMock.anyObject(InputFileMarker.class)); EasyMock.expectLastCall(); EasyMock.replay(mockOutputManager); Date d = new Date(); DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); String dateString = sdf.format(d); filterJson.apply("{ logtime: '" + d.getTime() + "', line_number: 100 }", new InputFileMarker(null, null, 0)); EasyMock.verify(mockOutputManager); Map<String, Object> jsonParams = capture.getValue(); assertEquals("Incorrect decoding: log time", dateString, jsonParams.remove("logtime")); assertEquals("Incorrect decoding: in memory timestamp", d.getTime(), jsonParams.remove(LogFeederConstants.IN_MEMORY_TIMESTAMP)); assertEquals("Incorrect decoding: line number", 100l, jsonParams.remove("line_number")); assertTrue("jsonParams are not empty!", jsonParams.isEmpty()); }
@Override public void apply(String inputStr, InputMarker inputMarker) throws Exception { Map<String, Object> jsonMap = null; try { jsonMap = LogFeederUtil.toJSONObject(inputStr); } catch (Exception e) { logger.error(e.getLocalizedMessage()); throw new LogFeederException("Json parsing failed for inputstr = " + inputStr ,e.getCause()); } Double lineNumberD = (Double) jsonMap.get("line_number"); if (lineNumberD != null) { long lineNumber = lineNumberD.longValue(); jsonMap.put("line_number", lineNumber); } String timeStampStr = (String) jsonMap.get("logtime"); if (timeStampStr != null && !timeStampStr.isEmpty()) { String logtime = DateUtil.getDate(timeStampStr); jsonMap.put("logtime", logtime); jsonMap.put(LogFeederConstants.IN_MEMORY_TIMESTAMP, Long.parseLong(timeStampStr)); } super.apply(jsonMap, inputMarker); }
FilterJSON extends Filter<LogFeederProps> { @Override public void apply(String inputStr, InputMarker inputMarker) throws Exception { Map<String, Object> jsonMap = null; try { jsonMap = LogFeederUtil.toJSONObject(inputStr); } catch (Exception e) { logger.error(e.getLocalizedMessage()); throw new LogFeederException("Json parsing failed for inputstr = " + inputStr ,e.getCause()); } Double lineNumberD = (Double) jsonMap.get("line_number"); if (lineNumberD != null) { long lineNumber = lineNumberD.longValue(); jsonMap.put("line_number", lineNumber); } String timeStampStr = (String) jsonMap.get("logtime"); if (timeStampStr != null && !timeStampStr.isEmpty()) { String logtime = DateUtil.getDate(timeStampStr); jsonMap.put("logtime", logtime); jsonMap.put(LogFeederConstants.IN_MEMORY_TIMESTAMP, Long.parseLong(timeStampStr)); } super.apply(jsonMap, inputMarker); } }
FilterJSON extends Filter<LogFeederProps> { @Override public void apply(String inputStr, InputMarker inputMarker) throws Exception { Map<String, Object> jsonMap = null; try { jsonMap = LogFeederUtil.toJSONObject(inputStr); } catch (Exception e) { logger.error(e.getLocalizedMessage()); throw new LogFeederException("Json parsing failed for inputstr = " + inputStr ,e.getCause()); } Double lineNumberD = (Double) jsonMap.get("line_number"); if (lineNumberD != null) { long lineNumber = lineNumberD.longValue(); jsonMap.put("line_number", lineNumber); } String timeStampStr = (String) jsonMap.get("logtime"); if (timeStampStr != null && !timeStampStr.isEmpty()) { String logtime = DateUtil.getDate(timeStampStr); jsonMap.put("logtime", logtime); jsonMap.put(LogFeederConstants.IN_MEMORY_TIMESTAMP, Long.parseLong(timeStampStr)); } super.apply(jsonMap, inputMarker); }  }
FilterJSON extends Filter<LogFeederProps> { @Override public void apply(String inputStr, InputMarker inputMarker) throws Exception { Map<String, Object> jsonMap = null; try { jsonMap = LogFeederUtil.toJSONObject(inputStr); } catch (Exception e) { logger.error(e.getLocalizedMessage()); throw new LogFeederException("Json parsing failed for inputstr = " + inputStr ,e.getCause()); } Double lineNumberD = (Double) jsonMap.get("line_number"); if (lineNumberD != null) { long lineNumber = lineNumberD.longValue(); jsonMap.put("line_number", lineNumber); } String timeStampStr = (String) jsonMap.get("logtime"); if (timeStampStr != null && !timeStampStr.isEmpty()) { String logtime = DateUtil.getDate(timeStampStr); jsonMap.put("logtime", logtime); jsonMap.put(LogFeederConstants.IN_MEMORY_TIMESTAMP, Long.parseLong(timeStampStr)); } super.apply(jsonMap, inputMarker); }  @Override void apply(String inputStr, InputMarker inputMarker); @Override String getShortDescription(); }
FilterJSON extends Filter<LogFeederProps> { @Override public void apply(String inputStr, InputMarker inputMarker) throws Exception { Map<String, Object> jsonMap = null; try { jsonMap = LogFeederUtil.toJSONObject(inputStr); } catch (Exception e) { logger.error(e.getLocalizedMessage()); throw new LogFeederException("Json parsing failed for inputstr = " + inputStr ,e.getCause()); } Double lineNumberD = (Double) jsonMap.get("line_number"); if (lineNumberD != null) { long lineNumber = lineNumberD.longValue(); jsonMap.put("line_number", lineNumber); } String timeStampStr = (String) jsonMap.get("logtime"); if (timeStampStr != null && !timeStampStr.isEmpty()) { String logtime = DateUtil.getDate(timeStampStr); jsonMap.put("logtime", logtime); jsonMap.put(LogFeederConstants.IN_MEMORY_TIMESTAMP, Long.parseLong(timeStampStr)); } super.apply(jsonMap, inputMarker); }  @Override void apply(String inputStr, InputMarker inputMarker); @Override String getShortDescription();  }