Search in sources :

Example 11 with Reference

use of org.graylog2.contentpacks.model.entities.references.Reference in project graylog2-server by Graylog2.

the class ReferenceConverterTest method convertDoubleValue.

@Test
public void convertDoubleValue() {
    final Reference reference = createReference("double", 10d);
    assertThat(reference).isEqualTo(ValueReference.of(10d));
}
Also used : ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) Reference(org.graylog2.contentpacks.model.entities.references.Reference) Test(org.junit.Test)

Example 12 with Reference

use of org.graylog2.contentpacks.model.entities.references.Reference in project graylog2-server by Graylog2.

the class FunctionsSnippetsTest method jsonpath.

@Test
public void jsonpath() {
    final String json = "{\n" + "    \"store\": {\n" + "        \"book\": [\n" + "            {\n" + "                \"category\": \"reference\",\n" + "                \"author\": \"Nigel Rees\",\n" + "                \"title\": \"Sayings of the Century\",\n" + "                \"price\": 8.95\n" + "            },\n" + "            {\n" + "                \"category\": \"fiction\",\n" + "                \"author\": \"Evelyn Waugh\",\n" + "                \"title\": \"Sword of Honour\",\n" + "                \"price\": 12.99\n" + "            },\n" + "            {\n" + "                \"category\": \"fiction\",\n" + "                \"author\": \"Herman Melville\",\n" + "                \"title\": \"Moby Dick\",\n" + "                \"isbn\": \"0-553-21311-3\",\n" + "                \"price\": 8.99\n" + "            },\n" + "            {\n" + "                \"category\": \"fiction\",\n" + "                \"author\": \"J. R. R. Tolkien\",\n" + "                \"title\": \"The Lord of the Rings\",\n" + "                \"isbn\": \"0-395-19395-8\",\n" + "                \"price\": 22.99\n" + "            }\n" + "        ],\n" + "        \"bicycle\": {\n" + "            \"color\": \"red\",\n" + "            \"price\": 19.95\n" + "        }\n" + "    },\n" + "    \"expensive\": 10\n" + "}";
    final Rule rule = parser.parseRule(ruleForTest(), false);
    final Message message = evaluateRule(rule, new Message(json, "test", Tools.nowUTC()));
    assertThat(message.hasField("author_first")).isTrue();
    assertThat(message.getField("author_first")).isEqualTo("Nigel Rees");
    assertThat(message.hasField("author_last")).isTrue();
    assertThat(message.hasField("this_should_exist")).isTrue();
}
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) IsString(org.graylog.plugins.pipelineprocessor.functions.conversion.IsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockitoRule(org.mockito.junit.MockitoRule) Rule(org.graylog.plugins.pipelineprocessor.ast.Rule) BaseParserTest(org.graylog.plugins.pipelineprocessor.BaseParserTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 Reference (org.graylog2.contentpacks.model.entities.references.Reference)8 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)8 Message (org.graylog2.plugin.Message)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 Duration (com.github.joschi.jadconfig.util.Duration)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterators (com.google.common.collect.Iterators)1 Ints (com.google.common.primitives.Ints)1 JestClient (io.searchbox.client.JestClient)1 JestResult (io.searchbox.client.JestResult)1 Health (io.searchbox.cluster.Health)1 State (io.searchbox.cluster.State)1 Bulk (io.searchbox.core.Bulk)1