Search in sources :

Example 16 with StreamRule

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

the class StreamRouterEngineTest method testOrMatchingShouldNotMatch.

@Test
public void testOrMatchingShouldNotMatch() {
    final String dummyField = "dummyField";
    final String dummyValue = "dummyValue";
    final Stream stream = mock(Stream.class);
    when(stream.getMatchingType()).thenReturn(Stream.MatchingType.OR);
    final StreamRule streamRule1 = getStreamRuleMock("StreamRule1Id", StreamRuleType.EXACT, dummyField, "not" + dummyValue);
    final StreamRule streamRule2 = getStreamRuleMock("StreamRule2Id", StreamRuleType.EXACT, dummyField, "alsoNot" + dummyValue);
    when(stream.getStreamRules()).thenReturn(Lists.newArrayList(streamRule1, streamRule2));
    final Message message = mock(Message.class);
    when(message.getField(eq(dummyField))).thenReturn(dummyValue);
    final StreamRouterEngine engine = newEngine(Lists.newArrayList(stream));
    final List<Stream> result = engine.match(message);
    assertThat(result).isEmpty();
}
Also used : Message(org.graylog2.plugin.Message) StreamRule(org.graylog2.plugin.streams.StreamRule) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 17 with StreamRule

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

the class ExactMatcherTest method testSuccessfulMatch.

@Test
public void testSuccessfulMatch() {
    StreamRule rule = getSampleRule();
    Message msg = getSampleMessage();
    msg.addField("something", "foo");
    StreamRuleMatcher matcher = getMatcher(rule);
    assertTrue(matcher.match(msg, rule));
}
Also used : Message(org.graylog2.plugin.Message) StreamRule(org.graylog2.plugin.streams.StreamRule) Test(org.junit.Test)

Example 18 with StreamRule

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

the class ExactMatcherTest method testNonExistantField.

@Test
public void testNonExistantField() {
    StreamRule rule = getSampleRule();
    Message msg = getSampleMessage();
    msg.addField("someother", "foo");
    StreamRuleMatcher matcher = getMatcher(rule);
    assertFalse(matcher.match(msg, rule));
}
Also used : Message(org.graylog2.plugin.Message) StreamRule(org.graylog2.plugin.streams.StreamRule) Test(org.junit.Test)

Example 19 with StreamRule

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

the class ExactMatcherTest method testMissedMatch.

@Test
public void testMissedMatch() {
    StreamRule rule = getSampleRule();
    Message msg = getSampleMessage();
    msg.addField("something", "nonono");
    StreamRuleMatcher matcher = getMatcher(rule);
    assertFalse(matcher.match(msg, rule));
}
Also used : Message(org.graylog2.plugin.Message) StreamRule(org.graylog2.plugin.streams.StreamRule) Test(org.junit.Test)

Example 20 with StreamRule

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

the class ExactMatcherTest method testInvertedNullFieldShouldMatch.

@Test
public void testInvertedNullFieldShouldMatch() {
    final String fieldName = "nullfield";
    final StreamRule rule = getSampleRule();
    rule.setField(fieldName);
    rule.setInverted(true);
    final Message msg = getSampleMessage();
    msg.addField(fieldName, null);
    final StreamRuleMatcher matcher = getMatcher(rule);
    assertTrue(matcher.match(msg, rule));
}
Also used : Message(org.graylog2.plugin.Message) StreamRule(org.graylog2.plugin.streams.StreamRule) Test(org.junit.Test)

Aggregations

StreamRule (org.graylog2.plugin.streams.StreamRule)85 Message (org.graylog2.plugin.Message)65 Test (org.junit.Test)64 Stream (org.graylog2.plugin.streams.Stream)13 Timed (com.codahale.metrics.annotation.Timed)7 ApiOperation (io.swagger.annotations.ApiOperation)7 ObjectId (org.bson.types.ObjectId)6 Produces (javax.ws.rs.Produces)5 BasicDBObject (com.mongodb.BasicDBObject)4 DBObject (com.mongodb.DBObject)4 ApiResponses (io.swagger.annotations.ApiResponses)4 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 AuditEvent (org.graylog2.audit.jersey.AuditEvent)4 NotFoundException (org.graylog2.database.NotFoundException)4 URI (java.net.URI)3 Map (java.util.Map)3 BadRequestException (javax.ws.rs.BadRequestException)3 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)3