Search in sources :

Example 1 with FieldValue

use of org.graylog.events.fields.FieldValue in project graylog2-server by Graylog2.

the class LookupTableFieldValueProviderTest method testWithMessageContext.

@Test
public void testWithMessageContext() {
    final String fieldValueString = "world";
    final String expectedLookupValue = "lookup-world";
    final TestEvent event = new TestEvent();
    final Message message = newMessage(ImmutableMap.of("hello", fieldValueString));
    final EventWithContext eventWithContext = EventWithContext.create(event, message);
    final LookupTableFieldValueProvider.Config config = newConfig("test", "hello");
    setupMocks("test");
    when(lookupTableFunction.lookup("world")).thenReturn(LookupResult.single("lookup-" + message.getField("hello")));
    final FieldValue fieldValue = newProvider(config).doGet("test", eventWithContext);
    assertThat(fieldValue.value()).isEqualTo(expectedLookupValue);
}
Also used : Message(org.graylog2.plugin.Message) TestEvent(org.graylog.events.event.TestEvent) EventWithContext(org.graylog.events.event.EventWithContext) FieldValue(org.graylog.events.fields.FieldValue) Test(org.junit.Test)

Example 2 with FieldValue

use of org.graylog.events.fields.FieldValue in project graylog2-server by Graylog2.

the class TemplateFieldValueProviderTest method templateWithError.

@Test
public void templateWithError() {
    final TestEvent event = new TestEvent();
    final EventWithContext eventWithContext = EventWithContext.create(event, newMessage(ImmutableMap.of("hello", "world")));
    final FieldValue fieldValue = newTemplate("hello: ${source.yolo}", true).doGet("test", eventWithContext);
    assertThat(fieldValue.dataType()).isEqualTo(FieldValueType.ERROR);
}
Also used : TestEvent(org.graylog.events.event.TestEvent) EventWithContext(org.graylog.events.event.EventWithContext) FieldValue(org.graylog.events.fields.FieldValue) Test(org.junit.Test)

Example 3 with FieldValue

use of org.graylog.events.fields.FieldValue in project graylog2-server by Graylog2.

the class TemplateFieldValueProviderTest method templateWithEventContext.

@Test
public void templateWithEventContext() {
    final TestEvent event = new TestEvent();
    final TestEvent eventContext = new TestEvent();
    eventContext.setField("hello", FieldValue.string("event"));
    final EventWithContext eventWithContext = EventWithContext.create(event, eventContext);
    final FieldValue fieldValue = newTemplate("hello: ${source.hello}").doGet("test", eventWithContext);
    assertThat(fieldValue.value()).isEqualTo("hello: event");
}
Also used : TestEvent(org.graylog.events.event.TestEvent) EventWithContext(org.graylog.events.event.EventWithContext) FieldValue(org.graylog.events.fields.FieldValue) Test(org.junit.Test)

Example 4 with FieldValue

use of org.graylog.events.fields.FieldValue in project graylog2-server by Graylog2.

the class TemplateFieldValueProviderTest method templateWithSyntaxError.

@Test
public void templateWithSyntaxError() {
    final TestEvent event = new TestEvent();
    final EventWithContext eventWithContext = EventWithContext.create(event, newMessage(ImmutableMap.of("hello", "world")));
    final FieldValue fieldValue = newTemplate("hello: ${source.hello").doGet("test", eventWithContext);
    assertThat(fieldValue.dataType()).isEqualTo(FieldValueType.ERROR);
}
Also used : TestEvent(org.graylog.events.event.TestEvent) EventWithContext(org.graylog.events.event.EventWithContext) FieldValue(org.graylog.events.fields.FieldValue) Test(org.junit.Test)

Example 5 with FieldValue

use of org.graylog.events.fields.FieldValue in project graylog2-server by Graylog2.

the class TemplateFieldValueProviderTest method templateBooleanFormatting.

@Test
public void templateBooleanFormatting() {
    final TestEvent event = new TestEvent();
    final EventWithContext eventWithContext = EventWithContext.create(event, newMessage(ImmutableMap.of("success", true)));
    final FieldValue fieldValue = newTemplate("success: ${source.success}").doGet("test", eventWithContext);
    assertThat(fieldValue.value()).isEqualTo("success: true");
}
Also used : TestEvent(org.graylog.events.event.TestEvent) EventWithContext(org.graylog.events.event.EventWithContext) FieldValue(org.graylog.events.fields.FieldValue) Test(org.junit.Test)

Aggregations

EventWithContext (org.graylog.events.event.EventWithContext)10 TestEvent (org.graylog.events.event.TestEvent)10 FieldValue (org.graylog.events.fields.FieldValue)10 Test (org.junit.Test)10 Message (org.graylog2.plugin.Message)1 Ignore (org.junit.Ignore)1