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);
}
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/");
}
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");
}
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");
}
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);
}
Aggregations