Search in sources :

Example 1 with RawMessage

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());
    }
}
Also used : JSONObject(org.json.simple.JSONObject) RawMessage(org.apache.metron.common.message.metadata.RawMessage) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.jupiter.api.Test)

Example 2 with RawMessage

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());
    }
}
Also used : JSONObject(org.json.simple.JSONObject) RawMessage(org.apache.metron.common.message.metadata.RawMessage) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.jupiter.api.Test)

Example 3 with RawMessage

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());
    }
}
Also used : JSONObject(org.json.simple.JSONObject) RawMessage(org.apache.metron.common.message.metadata.RawMessage) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.jupiter.api.Test)

Example 4 with RawMessage

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());
    }
}
Also used : JSONObject(org.json.simple.JSONObject) RawMessage(org.apache.metron.common.message.metadata.RawMessage) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.jupiter.api.Test)

Example 5 with RawMessage

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());
}
Also used : JSONObject(org.json.simple.JSONObject) ProcessResult(org.apache.metron.parsers.ParserRunnerImpl.ProcessResult) RawMessage(org.apache.metron.common.message.metadata.RawMessage) Test(org.junit.jupiter.api.Test)

Aggregations

RawMessage (org.apache.metron.common.message.metadata.RawMessage)14 JSONObject (org.json.simple.JSONObject)14 Test (org.junit.jupiter.api.Test)13 MetronError (org.apache.metron.common.error.MetronError)5 ProcessResult (org.apache.metron.parsers.ParserRunnerImpl.ProcessResult)5 ParserConfigurations (org.apache.metron.common.configuration.ParserConfigurations)4 SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)4 Tuple (org.apache.storm.tuple.Tuple)4 BaseBoltTest (org.apache.metron.test.bolt.BaseBoltTest)3 BulkMessage (org.apache.metron.common.writer.BulkMessage)2 MetronErrorJSONMatcher (org.apache.metron.test.error.MetronErrorJSONMatcher)1 InOrder (org.mockito.InOrder)1