use of org.graylog2.plugin.streams.StreamRule in project graylog2-server by Graylog2.
the class StreamRouterEngineTest method testAndStreamWithMultipleRules.
@Test
public void testAndStreamWithMultipleRules() {
final String dummyField = "dummyField";
final String dummyValue = "dummyValue";
final StreamRule streamRule1 = getStreamRuleMock("StreamRule1Id", StreamRuleType.EXACT, dummyField, dummyValue);
final StreamRule streamRule2 = getStreamRuleMock("StreamRule2Id", StreamRuleType.EXACT, dummyField, dummyValue);
final Stream stream = mock(Stream.class);
when(stream.getId()).thenReturn("Stream1Id");
when(stream.getMatchingType()).thenReturn(Stream.MatchingType.OR);
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).hasSize(1);
assertThat(result).contains(stream);
}
use of org.graylog2.plugin.streams.StreamRule in project graylog2-server by Graylog2.
the class ExactMatcherTest method testInvertedMatch.
@Test
public void testInvertedMatch() {
StreamRule rule = getSampleRule();
rule.setInverted(true);
Message msg = getSampleMessage();
msg.addField("something", "nonono");
StreamRuleMatcher matcher = getMatcher(rule);
assertTrue(matcher.match(msg, rule));
}
use of org.graylog2.plugin.streams.StreamRule in project graylog2-server by Graylog2.
the class ExactMatcherTest method testNonExistantFieldInverted.
@Test
public void testNonExistantFieldInverted() {
StreamRule rule = getSampleRule();
rule.setInverted(true);
Message msg = getSampleMessage();
msg.addField("someother", "foo");
StreamRuleMatcher matcher = getMatcher(rule);
assertTrue(matcher.match(msg, rule));
}
use of org.graylog2.plugin.streams.StreamRule in project graylog2-server by Graylog2.
the class ExactMatcherTest method testNullFieldShouldNotMatch.
@Test
public void testNullFieldShouldNotMatch() {
final String fieldName = "nullfield";
final StreamRule rule = getSampleRule();
rule.setField(fieldName);
final Message msg = getSampleMessage();
msg.addField(fieldName, null);
final StreamRuleMatcher matcher = getMatcher(rule);
assertFalse(matcher.match(msg, rule));
}
use of org.graylog2.plugin.streams.StreamRule in project graylog2-server by Graylog2.
the class ExactMatcherTest method getSampleRule.
@Override
protected StreamRule getSampleRule() {
StreamRule rule = super.getSampleRule();
rule.setType(StreamRuleType.EXACT);
rule.setValue("foo");
return rule;
}
Aggregations