use of org.graylog2.plugin.inputs.Extractor 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 in project graylog2-server by Graylog2.
the class ExtractorTest method testWithStringCondition.
@Test
public void testWithStringCondition() throws Exception {
final TestExtractor extractor = new TestExtractor.Builder().conditionType(STRING).conditionValue("hello").build();
// Extractor runs if the message contains the condition value "hello".
final Message msg1 = createMessage("hello world");
extractor.runExtractor(msg1);
assertThat(msg1.hasField("target")).isTrue();
// Extractor does not run if the message does not contain the condition value.
final Message msg2 = createMessage("the message");
extractor.runExtractor(msg2);
assertThat(msg2.hasField("target")).isFalse();
}
use of org.graylog2.plugin.inputs.Extractor 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 in project graylog2-server by Graylog2.
the class ExtractorTest method testWithOneTargetValueResult.
@Test
public void testWithOneTargetValueResult() throws Exception {
final TestExtractor extractor = new TestExtractor.Builder().callback(new Callable<Result[]>() {
@Override
public Result[] call() throws Exception {
return new Result[] { new Result("hello", "world", -1, -1) };
}
}).build();
final Message msg = createMessage("the hello");
extractor.runExtractor(msg);
assertThat(msg.hasField("target")).isFalse();
assertThat(msg.getField("world")).isEqualTo("hello");
}
use of org.graylog2.plugin.inputs.Extractor 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");
}
Aggregations