Search in sources :

Example 11 with TestEvent

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

the class LookupTableFieldValueProviderTest method testWithEventContext.

@Test
public void testWithEventContext() {
    final String fieldValueString = "event";
    final String expectedLookupValue = "lookup-event";
    final TestEvent event = new TestEvent();
    final TestEvent eventContext = new TestEvent();
    eventContext.setField("hello", FieldValue.string(fieldValueString));
    final EventWithContext eventWithContext = EventWithContext.create(event, eventContext);
    final LookupTableFieldValueProvider.Config config = newConfig("test", "hello");
    setupMocks("test");
    when(lookupTableFunction.lookup(fieldValueString)).thenReturn(LookupResult.single("lookup-" + eventContext.getField("hello").value()));
    final FieldValue fieldValue = newProvider(config).doGet("test", eventWithContext);
    assertThat(fieldValue.value()).isEqualTo(expectedLookupValue);
}
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 12 with TestEvent

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

the class TemplateFieldValueProviderTest method templateNumberFormatting.

@Test
public void templateNumberFormatting() {
    final TestEvent event = new TestEvent();
    final EventWithContext eventWithContext = EventWithContext.create(event, newMessage(ImmutableMap.of("count", 10241234, "avg", 1024.42)));
    final FieldValue fieldValue = newTemplate("count: ${source.count} avg: ${source.avg}").doGet("test", eventWithContext);
    assertThat(fieldValue.value()).isEqualTo("count: 10241234 avg: 1024.42");
}
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 13 with TestEvent

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

the class TemplateFieldValueProviderTest method templateDateFormatting.

@Test
public void templateDateFormatting() {
    final TestEvent event = new TestEvent();
    final EventWithContext eventWithContext = EventWithContext.create(event, newMessage(ImmutableMap.of("timestamp", DateTime.parse("2019-07-02T12:21:00.123Z"))));
    final FieldValue fieldValue = newTemplate("timestamp: ${source.timestamp}").doGet("test", eventWithContext);
    assertThat(fieldValue.value()).isEqualTo("timestamp: 2019-07-02T12:21:00.123Z");
}
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 14 with TestEvent

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

the class TemplateFieldValueProviderTest method templateWithMessageContext.

@Test
public void templateWithMessageContext() {
    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.value()).isEqualTo("hello: world");
}
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 15 with TestEvent

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

the class NotificationGracePeriodServiceTest method falseWithDisabledGracePeriod.

@Test
public void falseWithDisabledGracePeriod() {
    final NotificationGracePeriodService notificationGracePeriodService = new NotificationGracePeriodService();
    when(settings.gracePeriodMs()).thenReturn(0L);
    when(definition.notificationSettings()).thenReturn(settings);
    when(definition.id()).thenReturn("1234");
    final Event event = new TestEvent();
    event.setKeyTuple(ImmutableList.of("testkey"));
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).isFalse();
}
Also used : NotificationGracePeriodService(org.graylog.events.notifications.NotificationGracePeriodService) TestEvent(org.graylog.events.event.TestEvent) TestEvent(org.graylog.events.event.TestEvent) Event(org.graylog.events.event.Event) 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