use of org.apache.metron.common.message.metadata.RawMessage in project metron by apache.
the class RawMessageUtilTest method testEnvelopeStrategy_withoutKafkaMetadata_withAppMetadata.
@Test
public void testEnvelopeStrategy_withoutKafkaMetadata_withAppMetadata() {
Tuple t = createTuple(new HashMap<>(), appMetadata);
Map<String, Object> config = ImmutableMap.of(EnvelopedRawMessageStrategy.MESSAGE_FIELD_CONFIG, "data");
{
RawMessage m = RawMessageUtil.INSTANCE.getRawMessage(RawMessageStrategies.ENVELOPE, t, envelopedData.getBytes(StandardCharsets.UTF_8), true, config);
assertFalse(m.getMetadata().containsKey("data"));
checkMergedData(m);
assertEquals("raw_message", new String(m.getMessage(), StandardCharsets.UTF_8));
checkEnvelopeMetadata(m);
checkKafkaMetadata(m, true);
checkAppMetadata(m, false);
}
{
RawMessage m = RawMessageUtil.INSTANCE.getRawMessage(RawMessageStrategies.ENVELOPE, t, envelopedData.getBytes(StandardCharsets.UTF_8), false, config);
assertFalse(m.getMetadata().containsKey("data"));
checkMergedData(m);
assertEquals("raw_message", new String(m.getMessage(), StandardCharsets.UTF_8));
assertTrue(m.getMetadata().isEmpty());
}
}
use of org.apache.metron.common.message.metadata.RawMessage in project metron by apache.
the class RawMessageUtilTest method testEnvelopeStrategy_withoutKafkaMetadata_withoutAppMetadata.
@Test
public void testEnvelopeStrategy_withoutKafkaMetadata_withoutAppMetadata() {
Tuple t = createTuple(new HashMap<>(), "{}");
Map<String, Object> config = ImmutableMap.of(EnvelopedRawMessageStrategy.MESSAGE_FIELD_CONFIG, "data");
{
RawMessage m = RawMessageUtil.INSTANCE.getRawMessage(RawMessageStrategies.ENVELOPE, t, envelopedData.getBytes(StandardCharsets.UTF_8), true, config);
assertFalse(m.getMetadata().containsKey("data"));
checkMergedData(m);
assertEquals("raw_message", new String(m.getMessage(), StandardCharsets.UTF_8));
checkEnvelopeMetadata(m);
checkKafkaMetadata(m, true);
checkAppMetadata(m, true);
}
{
RawMessage m = RawMessageUtil.INSTANCE.getRawMessage(RawMessageStrategies.ENVELOPE, t, envelopedData.getBytes(StandardCharsets.UTF_8), false, config);
assertFalse(m.getMetadata().containsKey("data"));
checkMergedData(m);
assertEquals("raw_message", new String(m.getMessage(), StandardCharsets.UTF_8));
assertTrue(m.getMetadata().isEmpty());
}
}
use of org.apache.metron.common.message.metadata.RawMessage in project metron by apache.
the class RawMessageUtilTest method testEnvelopeStrategy_withKafkaMetadata_withAppMetadata.
@Test
public void testEnvelopeStrategy_withKafkaMetadata_withAppMetadata() {
Tuple t = createTuple(kafkaMetadata, appMetadata);
Map<String, Object> config = ImmutableMap.of(EnvelopedRawMessageStrategy.MESSAGE_FIELD_CONFIG, "data");
{
RawMessage m = RawMessageUtil.INSTANCE.getRawMessage(RawMessageStrategies.ENVELOPE, t, envelopedData.getBytes(StandardCharsets.UTF_8), true, config);
assertEquals("raw_message", new String(m.getMessage(), StandardCharsets.UTF_8));
assertFalse(m.getMetadata().containsKey("data"));
checkEnvelopeMetadata(m);
checkMergedData(m);
checkKafkaMetadata(m, false);
checkAppMetadata(m, false);
}
{
RawMessage m = RawMessageUtil.INSTANCE.getRawMessage(RawMessageStrategies.ENVELOPE, t, envelopedData.getBytes(StandardCharsets.UTF_8), false, config);
checkMergedData(m);
assertEquals("raw_message", new String(m.getMessage(), StandardCharsets.UTF_8));
assertFalse(m.getMetadata().containsKey("data"));
assertTrue(m.getMetadata().isEmpty());
}
}
use of org.apache.metron.common.message.metadata.RawMessage in project metron by apache.
the class RawMessageUtilTest method testEnvelopeStrategy_withKafkaMetadata_withoutAppMetadata.
@Test
public void testEnvelopeStrategy_withKafkaMetadata_withoutAppMetadata() {
Tuple t = createTuple(kafkaMetadata, "{}");
Map<String, Object> config = ImmutableMap.of(EnvelopedRawMessageStrategy.MESSAGE_FIELD_CONFIG, "data");
{
RawMessage m = RawMessageUtil.INSTANCE.getRawMessage(RawMessageStrategies.ENVELOPE, t, envelopedData.getBytes(StandardCharsets.UTF_8), true, config);
assertEquals("raw_message", new String(m.getMessage(), StandardCharsets.UTF_8));
assertFalse(m.getMetadata().containsKey("data"));
checkMergedData(m);
checkEnvelopeMetadata(m);
checkKafkaMetadata(m, false);
checkAppMetadata(m, true);
}
{
RawMessage m = RawMessageUtil.INSTANCE.getRawMessage(RawMessageStrategies.ENVELOPE, t, envelopedData.getBytes(StandardCharsets.UTF_8), false, config);
assertFalse(m.getMetadata().containsKey("data"));
checkMergedData(m);
assertEquals("raw_message", new String(m.getMessage(), StandardCharsets.UTF_8));
assertTrue(m.getMetadata().isEmpty());
}
}
use of org.apache.metron.common.message.metadata.RawMessage in project metron by apache.
the class ParserRunnerImplTest method shouldPopulateMessagesOnProcessMessage.
/**
* This is only testing the processMessage method
*/
@Test
public void shouldPopulateMessagesOnProcessMessage() {
JSONObject inputMessage = new JSONObject();
inputMessage.put("guid", "guid");
inputMessage.put("ip_src_addr", "192.168.1.1");
inputMessage.put("ip_dst_addr", "192.168.1.2");
RawMessage rawMessage = new RawMessage("raw_message_for_testing".getBytes(StandardCharsets.UTF_8), new HashMap<>());
JSONObject expectedOutput = new JSONObject();
expectedOutput.put("guid", "guid");
expectedOutput.put("source.type", "bro");
expectedOutput.put("ip_src_addr", "192.168.1.1");
expectedOutput.put("ip_dst_addr", "192.168.1.2");
expectedOutput.put(Fields.ORIGINAL.getName(), "raw_message_for_testing");
when(stellarFilter.emit(expectedOutput, parserRunner.getStellarContext())).thenReturn(true);
when(broParser.validate(expectedOutput)).thenReturn(true);
parserRunner.setSensorToParserComponentMap(new HashMap<String, ParserComponent>() {
{
put("bro", new ParserComponent(broParser, stellarFilter));
}
});
Optional<ParserRunnerImpl.ProcessResult> processResult = parserRunner.processMessage("bro", inputMessage, rawMessage, broParser, parserConfigurations);
assertTrue(processResult.isPresent());
assertFalse(processResult.get().isError());
assertEquals(expectedOutput, processResult.get().getMessage());
}
Aggregations