Search in sources :

Example 36 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class GeneratorTest method testGenerateOverview.

@Test
public void testGenerateOverview() throws Exception {
    Generator generator = new Generator("org.graylog2.rest.resources", objectMapper);
    Map<String, Object> result = generator.generateOverview();
    assertEquals(ServerVersion.VERSION.toString(), result.get("apiVersion"));
    assertEquals(Generator.EMULATED_SWAGGER_VERSION, result.get("swaggerVersion"));
    assertNotNull(result.get("apis"));
    assertTrue(((List) result.get("apis")).size() > 0);
}
Also used : List(java.util.List) Generator(org.graylog2.shared.rest.documentation.generator.Generator) Test(org.junit.Test)

Example 37 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class GeneratorTest method testGenerateForRoute.

@Test
public void testGenerateForRoute() throws Exception {
    Generator generator = new Generator("org.graylog2.rest.resources", objectMapper);
    Map<String, Object> result = generator.generateForRoute("/system", "http://localhost:12900/");
}
Also used : Generator(org.graylog2.shared.rest.documentation.generator.Generator) Test(org.junit.Test)

Example 38 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class ExtractorTest method testCursorStrategyCutIfTargetFieldEqualsSourceField.

@Test
public void testCursorStrategyCutIfTargetFieldEqualsSourceField() throws Exception {
    final TestExtractor extractor = new TestExtractor.Builder().cursorStrategy(CUT).sourceField("msg").targetField("msg").callback(new Callable<Result[]>() {

        @Override
        public Result[] call() throws Exception {
            return new Result[] { new Result("the", 0, 3) };
        }
    }).build();
    final Message msg = createMessage("message");
    msg.addField("msg", "the hello");
    extractor.runExtractor(msg);
    // If source and target fields are the same, the field is not touched because it already got set to a new value.
    assertThat(msg.getField("msg")).isEqualTo("the");
}
Also used : Message(org.graylog2.plugin.Message) Callable(java.util.concurrent.Callable) Result(org.graylog2.plugin.inputs.Extractor.Result) Test(org.junit.Test)

Example 39 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class ExtractorTest method testConverters.

@Test
public void testConverters() throws Exception {
    final Converter converter = new TestConverter.Builder().callback(new Function<Object, Object>() {

        @Nullable
        @Override
        public Object apply(Object input) {
            return "converted";
        }
    }).build();
    final TestExtractor extractor = new TestExtractor.Builder().converters(Lists.newArrayList(converter)).callback(new Callable<Result[]>() {

        @Override
        public Result[] call() throws Exception {
            return new Result[] { new Result("1", -1, -1) };
        }
    }).build();
    final Message msg = createMessage("message");
    extractor.runExtractor(msg);
    assertThat(msg.getField("target")).isEqualTo("converted");
}
Also used : Function(com.google.common.base.Function) Message(org.graylog2.plugin.Message) Callable(java.util.concurrent.Callable) Result(org.graylog2.plugin.inputs.Extractor.Result) Test(org.junit.Test)

Example 40 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class ExtractorTest method testConvertersWithNonStringFieldValue.

@Test
public void testConvertersWithNonStringFieldValue() throws Exception {
    final Converter converter = new TestConverter.Builder().callback(new Function<Object, Object>() {

        @Nullable
        @Override
        public Object apply(Object input) {
            return "converted";
        }
    }).build();
    final TestExtractor extractor = new TestExtractor.Builder().converters(Lists.newArrayList(converter)).callback(new Callable<Result[]>() {

        @Override
        public Result[] call() throws Exception {
            return new Result[] { new Result(123, "target", -1, -1) };
        }
    }).build();
    final Message msg = createMessage("message");
    extractor.runExtractor(msg);
    // Only string values will be converted.
    assertThat(msg.getField("target")).isEqualTo(123);
}
Also used : Function(com.google.common.base.Function) Message(org.graylog2.plugin.Message) Callable(java.util.concurrent.Callable) Result(org.graylog2.plugin.inputs.Extractor.Result) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)73 Message (org.graylog2.plugin.Message)51 Result (org.graylog2.plugin.inputs.Extractor.Result)27 Callable (java.util.concurrent.Callable)26 Stream (org.graylog2.plugin.streams.Stream)20 StreamRule (org.graylog2.plugin.streams.StreamRule)19 DateTime (org.joda.time.DateTime)18 Timed (com.codahale.metrics.annotation.Timed)13 ApiOperation (io.swagger.annotations.ApiOperation)13 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)12 ApiResponses (io.swagger.annotations.ApiResponses)11 Produces (javax.ws.rs.Produces)9 AuditEvent (org.graylog2.audit.jersey.AuditEvent)9 Function (com.google.common.base.Function)8 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)8 ZonedDateTime (java.time.ZonedDateTime)8 AbstractAlertCondition (org.graylog2.alerts.AbstractAlertCondition)8 Sorting (org.graylog2.indexer.searches.Sorting)8 URI (java.net.URI)7 MessageSummary (org.graylog2.plugin.MessageSummary)7