use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class ExtractorTest method testWithOneValueOnlyResult.
@Test
public void testWithOneValueOnlyResult() throws Exception {
final TestExtractor extractor = new TestExtractor.Builder().callback(new Callable<Result[]>() {
@Override
public Result[] call() throws Exception {
return new Result[] { new Result("1", -1, -1) };
}
}).build();
final Message msg = createMessage("the hello");
extractor.runExtractor(msg);
assertThat(msg.getField("target")).isEqualTo("1");
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class ExtractorTest method testCursorStrategyCopy.
@Test
public void testCursorStrategyCopy() throws Exception {
final TestExtractor extractor = new TestExtractor.Builder().cursorStrategy(COPY).sourceField("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);
// With the copy strategy, the source field should not be modified.
assertThat(msg.getField("msg")).isEqualTo("the hello");
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class ExtractorTest method testConvertersAreExecutedInOrder.
@Test
public void testConvertersAreExecutedInOrder() throws Exception {
final Converter converter1 = new TestConverter.Builder().callback(new Function<Object, Object>() {
@Nullable
@Override
public Object apply(Object input) {
return ((String) input) + "1";
}
}).build();
final Converter converter2 = new TestConverter.Builder().callback(new Function<Object, Object>() {
@Nullable
@Override
public Object apply(Object input) {
return ((String) input) + "2";
}
}).build();
final Converter converter3 = new TestConverter.Builder().callback(new Function<Object, Object>() {
@Nullable
@Override
public Object apply(Object input) {
return ((String) input) + "3";
}
}).build();
final TestExtractor extractor = new TestExtractor.Builder().converters(Lists.newArrayList(converter1, converter2, converter3)).callback(new Callable<Result[]>() {
@Override
public Result[] call() throws Exception {
return new Result[] { new Result("converter", -1, -1) };
}
}).build();
final Message msg = createMessage("message");
extractor.runExtractor(msg);
assertThat(msg.getField("target")).isEqualTo("converter123");
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class ExtractorTest method testCursorStrategyCutIfSourceFieldIsReservedField.
@Test
public void testCursorStrategyCutIfSourceFieldIsReservedField() throws Exception {
final TestExtractor extractor = new TestExtractor.Builder().cursorStrategy(CUT).sourceField("message").callback(new Callable<Result[]>() {
@Override
public Result[] call() throws Exception {
return new Result[] { new Result("the", 0, 3) };
}
}).build();
final Message msg = createMessage("the hello");
extractor.runExtractor(msg);
// The source value is not modified if it is a reserved field.
assertThat(msg.getField("message")).isEqualTo("the hello");
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class ExtractorTest method testWithOneValueOnlyResultsAndValueIsNull.
@Test
public void testWithOneValueOnlyResultsAndValueIsNull() throws Exception {
final TestExtractor extractor = new TestExtractor.Builder().callback(new Callable<Result[]>() {
@Override
public Result[] call() throws Exception {
return new Result[] { new Result(null, -1, -1) };
}
}).build();
final Message msg = createMessage("the hello");
extractor.runExtractor(msg);
assertThat(msg.hasField("target")).isFalse();
}
Aggregations