Search in sources :

Example 6 with TestEvent

use of org.graylog.events.event.TestEvent 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 7 with TestEvent

use of org.graylog.events.event.TestEvent 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 8 with TestEvent

use of org.graylog.events.event.TestEvent 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)

Example 9 with TestEvent

use of org.graylog.events.event.TestEvent in project graylog2-server by Graylog2.

the class TemplateFieldValueProviderTest method templateCalculation.

@Test
@Ignore("template engine doesn't support expressions")
public void templateCalculation() {
    final TestEvent event = new TestEvent();
    final EventWithContext eventWithContext = EventWithContext.create(event, newMessage(ImmutableMap.of("bytes", 1024)));
    final FieldValue fieldValue = newTemplate("${source.bytes / 1024}").doGet("test", eventWithContext);
    assertThat(fieldValue.value()).isEqualTo("1");
}
Also used : TestEvent(org.graylog.events.event.TestEvent) EventWithContext(org.graylog.events.event.EventWithContext) FieldValue(org.graylog.events.fields.FieldValue) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with TestEvent

use of org.graylog.events.event.TestEvent in project graylog2-server by Graylog2.

the class LookupTableFieldValueProviderTest method testWithMissingLookupTable.

@Test
public void testWithMissingLookupTable() {
    final TestEvent event = new TestEvent();
    final EventWithContext eventWithContext = EventWithContext.create(event, newMessage(ImmutableMap.of("hello", "world")));
    final LookupTableFieldValueProvider.Config config = newConfig("test-doesntexist", "hello");
    setupMocks("test");
    when(lookupTableFunction.lookup("world")).thenReturn(LookupResult.single("lookup-world"));
    assertThatThrownBy(() -> newProvider(config).doGet("test", eventWithContext)).hasMessageContaining("test-doesntexist").isInstanceOf(IllegalArgumentException.class);
}
Also used : TestEvent(org.graylog.events.event.TestEvent) EventWithContext(org.graylog.events.event.EventWithContext) Test(org.junit.Test)

Aggregations

TestEvent (org.graylog.events.event.TestEvent)24 Test (org.junit.Test)23 EventWithContext (org.graylog.events.event.EventWithContext)15 Event (org.graylog.events.event.Event)12 FieldValue (org.graylog.events.fields.FieldValue)10 NotificationGracePeriodService (org.graylog.events.notifications.NotificationGracePeriodService)8 EventDefinitionDto (org.graylog.events.processor.EventDefinitionDto)5 Message (org.graylog2.plugin.Message)5 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)5 DateTime (org.joda.time.DateTime)5 StreamMock (org.graylog2.streams.StreamMock)1 Ignore (org.junit.Ignore)1