Search in sources :

Example 1 with MessageParser

use of org.apache.metron.parsers.interfaces.MessageParser in project metron by apache.

the class MessageParserTest method testNullable.

@Test
public void testNullable() throws Exception {
    MessageParser parser = new MessageParser() {

        @Override
        public void init() {
        }

        @Override
        public List parse(byte[] rawMessage) {
            return null;
        }

        @Override
        public boolean validate(Object message) {
            return false;
        }

        @Override
        public void configure(Map<String, Object> config) {
        }
    };
    Assert.assertNotNull(parser.parseOptional(null));
    Assert.assertFalse(parser.parseOptional(null).isPresent());
}
Also used : MessageParser(org.apache.metron.parsers.interfaces.MessageParser) Map(java.util.Map) Test(org.junit.Test)

Example 2 with MessageParser

use of org.apache.metron.parsers.interfaces.MessageParser in project metron by apache.

the class MessageParserTest method testNotNullable.

@Test
public void testNotNullable() throws Exception {
    MessageParser parser = new MessageParser() {

        @Override
        public void init() {
        }

        @Override
        public List parse(byte[] rawMessage) {
            return new ArrayList<>();
        }

        @Override
        public boolean validate(Object message) {
            return false;
        }

        @Override
        public void configure(Map<String, Object> config) {
        }
    };
    Assert.assertNotNull(parser.parseOptional(null));
    Optional<List> ret = parser.parseOptional(null);
    Assert.assertTrue(ret.isPresent());
    Assert.assertEquals(0, ret.get().size());
}
Also used : MessageParser(org.apache.metron.parsers.interfaces.MessageParser) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Map (java.util.Map)2 MessageParser (org.apache.metron.parsers.interfaces.MessageParser)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1