Search in sources :

Example 11 with ParseException

use of org.graylog.plugins.pipelineprocessor.parser.ParseException in project graylog2-server by Graylog2.

the class FunctionsSnippetsTest method dates.

@Test
public void dates() {
    final InstantMillisProvider clock = new InstantMillisProvider(GRAYLOG_EPOCH);
    DateTimeUtils.setCurrentMillisProvider(clock);
    try {
        final Rule rule;
        try {
            rule = parser.parseRule(ruleForTest(), false);
        } catch (ParseException e) {
            fail("Should not fail to parse", e);
            return;
        }
        final Message message = evaluateRule(rule);
        assertThat(actionsTriggered.get()).isTrue();
        assertThat(message).isNotNull();
        assertThat(message).isNotEmpty();
        assertThat(message.hasField("year")).isTrue();
        assertThat(message.getField("year")).isEqualTo(2010);
        assertThat(message.getField("timezone")).isEqualTo("UTC");
        // Date parsing locales
        assertThat(message.getField("german_year")).isEqualTo(1983);
        assertThat(message.getField("german_month")).isEqualTo(7);
        assertThat(message.getField("german_day")).isEqualTo(24);
        assertThat(message.getField("german_weekday")).isEqualTo(7);
        assertThat(message.getField("english_year")).isEqualTo(1983);
        assertThat(message.getField("english_month")).isEqualTo(7);
        assertThat(message.getField("english_day")).isEqualTo(24);
        assertThat(message.getField("french_year")).isEqualTo(1983);
        assertThat(message.getField("french_month")).isEqualTo(7);
        assertThat(message.getField("french_day")).isEqualTo(24);
        assertThat(message.getField("ts_hour")).isEqualTo(16);
        assertThat(message.getField("ts_minute")).isEqualTo(3);
        assertThat(message.getField("ts_second")).isEqualTo(25);
    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
Also used : CreateMessage(org.graylog.plugins.pipelineprocessor.functions.messages.CreateMessage) CloneMessage(org.graylog.plugins.pipelineprocessor.functions.messages.CloneMessage) DropMessage(org.graylog.plugins.pipelineprocessor.functions.messages.DropMessage) Message(org.graylog2.plugin.Message) InstantMillisProvider(org.graylog2.plugin.InstantMillisProvider) MockitoRule(org.mockito.junit.MockitoRule) Rule(org.graylog.plugins.pipelineprocessor.ast.Rule) ParseException(org.graylog.plugins.pipelineprocessor.parser.ParseException) BaseParserTest(org.graylog.plugins.pipelineprocessor.BaseParserTest) Test(org.junit.Test)

Aggregations

ParseException (org.graylog.plugins.pipelineprocessor.parser.ParseException)11 BadRequestException (javax.ws.rs.BadRequestException)7 ApiOperation (io.swagger.annotations.ApiOperation)6 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)6 Pipeline (org.graylog.plugins.pipelineprocessor.ast.Pipeline)5 Rule (org.graylog.plugins.pipelineprocessor.ast.Rule)5 AuditEvent (org.graylog2.audit.jersey.AuditEvent)5 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 DateTime (org.joda.time.DateTime)4 PUT (javax.ws.rs.PUT)3 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)3 PipelineDao (org.graylog.plugins.pipelineprocessor.db.PipelineDao)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 RuleDao (org.graylog.plugins.pipelineprocessor.db.RuleDao)2 Test (org.junit.Test)2 Lists (com.google.common.collect.Lists)1 Api (io.swagger.annotations.Api)1 ApiParam (io.swagger.annotations.ApiParam)1 ArrayList (java.util.ArrayList)1