use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class FunctionsSnippetsTest method stringConcat.
@Test
public void stringConcat() {
final Rule rule = parser.parseRule(ruleForTest(), false);
final Message message = evaluateRule(rule, new Message("Dummy Message", "test", Tools.nowUTC()));
assertThat(message.hasField("result")).isTrue();
assertThat(message.getField("result")).isEqualTo("aabbcc");
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class FunctionsSnippetsTest method lookupSetStringList.
@Test
public void lookupSetStringList() {
final ImmutableList<String> testList = ImmutableList.of("foo", "bar");
doReturn(LookupResult.withoutTTL().stringListValue(testList).build()).when(lookupTable).setStringList(any(), any());
final Rule rule = parser.parseRule(ruleForTest(), true);
final Message message = evaluateRule(rule);
verify(lookupTable).setStringList("key", testList);
verifyNoMoreInteractions(lookupTable);
assertThat(message.getField("new_value")).isEqualTo(testList);
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class FunctionsSnippetsTest method newlyCreatedMessage.
@Test
public void newlyCreatedMessage() {
final Message message = new Message("test", "test", Tools.nowUTC());
message.addField("foo", "bar");
message.addStream(mock(Stream.class));
final Rule rule = parser.parseRule(ruleForTest(), false);
final EvaluationContext context = contextForRuleEval(rule, message);
final Message origMessage = context.currentMessage();
final Message newMessage = Iterables.getOnlyElement(context.createdMessages());
assertThat(origMessage).isNotSameAs(newMessage);
assertThat(newMessage.getMessage()).isEqualTo("new");
assertThat(newMessage.getSource()).isEqualTo("synthetic");
assertThat(newMessage.getStreams()).isEmpty();
assertThat(newMessage.hasField("removed_again")).isFalse();
assertThat(newMessage.getFieldAs(Boolean.class, "has_source")).isTrue();
assertThat(newMessage.getFieldAs(String.class, "only_in")).isEqualTo("new message");
assertThat(newMessage.getFieldAs(String.class, "multi")).isEqualTo("new message");
assertThat(newMessage.getFieldAs(String.class, "foo")).isNull();
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class FunctionsSnippetsTest method notExpressionTypeCheck.
@Test
public void notExpressionTypeCheck() {
try {
Rule rule = parser.parseRule(ruleForTest(), true);
Message in = new Message("test", "source", Tools.nowUTC());
in.addField("facility", "mail");
evaluateRule(rule, in);
fail("missing type check for non-boolean type in unary NOT");
} catch (Exception e) {
assertThat(e).isInstanceOf(ParseException.class).hasMessageContaining("Expected type Boolean but found String");
}
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class FunctionsSnippetsTest method lookupAddStringList.
@Test
public void lookupAddStringList() {
final ImmutableList<String> testList = ImmutableList.of("foo", "bar");
doReturn(LookupResult.withoutTTL().stringListValue(testList).build()).when(lookupTable).addStringList(any(), any(), anyBoolean());
final Rule rule = parser.parseRule(ruleForTest(), true);
final Message message = evaluateRule(rule);
verify(lookupTable).addStringList("key", testList, false);
verifyNoMoreInteractions(lookupTable);
assertThat(message.getField("new_value")).isEqualTo(testList);
}
Aggregations