use of org.graylog2.plugin.inputs.Extractor in project graylog2-server by Graylog2.
the class ExtractorTest method testCursorStrategyCutIfBeginAndEndIndexAreDisabled.
@Test
public void testCursorStrategyCutIfBeginAndEndIndexAreDisabled() throws Exception {
final TestExtractor extractor = new TestExtractor.Builder().cursorStrategy(CUT).sourceField("msg").callback(new Callable<Result[]>() {
@Override
public Result[] call() throws Exception {
return new Result[] { new Result("the", -1, -1) };
}
}).build();
final Message msg = createMessage("message");
msg.addField("msg", "the hello");
extractor.runExtractor(msg);
// If the begin and end index is -1, the source field should not be modified.
assertThat(msg.getField("msg")).isEqualTo("the hello");
}
use of org.graylog2.plugin.inputs.Extractor in project graylog2-server by Graylog2.
the class ExtractorTest method testCursorStrategyCutWithAllTextCut.
@Test
public void testCursorStrategyCutWithAllTextCut() throws Exception {
final TestExtractor extractor = new TestExtractor.Builder().cursorStrategy(CUT).sourceField("msg").callback(new Callable<Result[]>() {
@Override
public Result[] call() throws Exception {
return new Result[] { new Result("the hello", 0, 9) };
}
}).build();
final Message msg = createMessage("message");
msg.addField("msg", "the hello");
extractor.runExtractor(msg);
// If all data is cut from the source field, the "fullyCutByExtractor" string gets inserted.
assertThat(msg.getField("msg")).isEqualTo("fullyCutByExtractor");
}
use of org.graylog2.plugin.inputs.Extractor in project graylog2-server by Graylog2.
the class ExtractorTest method testConvertersThatReturnNullValue.
@Test
public void testConvertersThatReturnNullValue() throws Exception {
final Converter converter = new TestConverter.Builder().callback(new Function<Object, Object>() {
@Nullable
@Override
public Object apply(Object input) {
return null;
}
}).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")).isNull();
}
use of org.graylog2.plugin.inputs.Extractor in project graylog2-server by Graylog2.
the class ExtractorTest method testConvertersWithMultipleFieldsAndNull.
@Test
public void testConvertersWithMultipleFieldsAndNull() throws Exception {
final Converter converter = new TestConverter.Builder().multiple(true).callback(new Function<Object, Object>() {
@Nullable
@Override
public Object apply(Object input) {
return null;
}
}).build();
final TestExtractor extractor = new TestExtractor.Builder().converters(Collections.singletonList(converter)).callback(() -> new Result[] { new Result("1", -1, -1) }).build();
final Message msg = createMessage("the message");
extractor.runExtractor(msg);
assertThat(msg.getField("message")).isEqualTo("the message");
assertThat(extractor.getConverterExceptionCount()).isEqualTo(0L);
}
use of org.graylog2.plugin.inputs.Extractor 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