Search in sources :

Example 21 with StreamRouterEngine

use of org.graylog2.streams.StreamRouterEngine in project graylog2-server by Graylog2.

the class StreamRouterEngineTest method testRegexMatch.

@Test
public void testRegexMatch() throws Exception {
    final StreamMock stream = getStreamMock("test");
    final StreamRuleMock rule = new StreamRuleMock(ImmutableMap.of("_id", new ObjectId(), "field", "testfield", "value", "^test", "type", StreamRuleType.REGEX.toInteger(), "stream_id", stream.getId()));
    stream.setStreamRules(Lists.newArrayList(rule));
    final StreamRouterEngine engine = newEngine(Lists.newArrayList(stream));
    final Message message = getMessage();
    // With non-matching value.
    message.addField("testfield", "notestvalue");
    assertTrue(engine.match(message).isEmpty());
    // With matching value.
    message.addField("testfield", "testvalue");
    assertEquals(Lists.newArrayList(stream), engine.match(message));
}
Also used : Message(org.graylog2.plugin.Message) ObjectId(org.bson.types.ObjectId) StreamRuleMock(org.graylog2.streams.matchers.StreamRuleMock) Test(org.junit.Test)

Aggregations

Message (org.graylog2.plugin.Message)20 Test (org.junit.Test)20 ObjectId (org.bson.types.ObjectId)15 StreamRuleMock (org.graylog2.streams.matchers.StreamRuleMock)15 Stream (org.graylog2.plugin.streams.Stream)7 StreamRule (org.graylog2.plugin.streams.StreamRule)7 Timed (com.codahale.metrics.annotation.Timed)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)1 StreamRouterEngine (org.graylog2.streams.StreamRouterEngine)1