@Test
public void shouldReturnMetronErrorOnInvalidMessage() {
JSONObject inputMessage = new JSONObject();
inputMessage.put("guid", "guid");
RawMessage rawMessage = new RawMessage("raw_message".getBytes(), new HashMap<>());
JSONObject expectedOutput = new JSONObject();
expectedOutput.put("guid", "guid");
expectedOutput.put("source.type", "bro");
MetronError expectedMetronError = new MetronError()
.withErrorType(Constants.ErrorType.PARSER_INVALID)
.withSensorType(Collections.singleton("bro"))
.addRawMessage(inputMessage);
when(stellarFilter.emit(expectedOutput, parserRunner.getStellarContext())).thenReturn(true);
when(broParser.validate(expectedOutput)).thenReturn(false);
parserRunner.setSensorToParserComponentMap(new HashMap<String, ParserComponent>() {{
put("bro", new ParserComponent(broParser, stellarFilter));
}});
Optional<ParserRunnerImpl.ProcessResult> processResult = parserRunner.processMessage("bro", inputMessage, rawMessage, broParser, parserConfigurations);
Assert.assertTrue(processResult.isPresent());
Assert.assertTrue(processResult.get().isError());
Assert.assertEquals(expectedMetronError, processResult.get().getError());
}