@Test public void testReadMultiLineWithErrors() throws Exception { Syslog3164Parser parser = new Syslog3164Parser(); Map<String, Object> config = new HashMap<>(); parser.configure(config); StringBuilder builder = new StringBuilder(); builder .append("HEREWEGO!!!!\n") .append(SYSLOG_LINE_ALL) .append("\n") .append(SYSLOG_LINE_MISSING) .append("\n") .append("BOOM!\n") .append(SYSLOG_LINE_ALL) .append("\nOHMY!"); Optional<MessageParserResult<JSONObject>> output = parser.parseOptionalResult(builder.toString().getBytes()); Assert.assertTrue(output.isPresent()); Assert.assertEquals(3,output.get().getMessages().size()); Assert.assertEquals(3,output.get().getMessageThrowables().size()); } }
parserRunnerResults.addErrors(messageParserResult.getMessageThrowables().entrySet().stream().map(entry -> new MetronError() .withErrorType(Constants.ErrorType.PARSER_ERROR) .withThrowable(entry.getValue())
@Test public void testReadMultiLineWithErrors() throws Exception { Syslog5424Parser parser = new Syslog5424Parser(); Map<String, Object> config = new HashMap<>(); config.put(Syslog5424Parser.NIL_POLICY_CONFIG, NilPolicy.DASH.name()); parser.configure(config); StringBuilder builder = new StringBuilder(); builder .append("HEREWEGO!!!!\n") .append(SYSLOG_LINE_ALL) .append("\n") .append(SYSLOG_LINE_MISSING) .append("\n") .append("BOOM!\n") .append(SYSLOG_LINE_ALL) .append("\nOHMY!"); Optional<MessageParserResult<JSONObject>> output = parser.parseOptionalResult(builder.toString().getBytes()); Assert.assertTrue(output.isPresent()); Assert.assertEquals(3,output.get().getMessages().size()); Assert.assertEquals(3,output.get().getMessageThrowables().size()); }
Optional<Throwable> throwableOptional = resultOptional.get().getMasterThrowable(); List<JSONObject> resultList = resultOptional.get().getMessages(); Map<Object,Throwable> errorMap = resultOptional.get().getMessageThrowables(); Assert.assertFalse(throwableOptional.isPresent()); Assert.assertEquals(0, errorMap.size());
Optional<Throwable> throwableOptional = resultOptional.get().getMasterThrowable(); List<JSONObject> resultList = resultOptional.get().getMessages(); Map<Object,Throwable> errorMap = resultOptional.get().getMessageThrowables(); Assert.assertFalse(throwableOptional.isPresent()); Assert.assertEquals(3, errorMap.size());