use of org.graylog2.plugin.inputs.Converter 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.Converter 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);
}
use of org.graylog2.plugin.inputs.Converter 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.Converter in project graylog2-server by Graylog2.
the class DateConverterTest method convertObeysTimeZone.
@Test
public void convertObeysTimeZone() throws Exception {
final DateTimeZone timeZone = DateTimeZone.forOffsetHours(12);
final Converter c = new DateConverter(config("YYYY-MM-dd HH:mm:ss", timeZone.toString()));
final DateTime dateOnly = (DateTime) c.convert("2014-03-12 10:00:00");
assertThat(dateOnly.getZone()).isEqualTo(timeZone);
Assertions.assertThat(dateOnly).isEqualTo(new DateTime(2014, 3, 12, 10, 0, 0, timeZone)).isBefore(new DateTime(2014, 3, 13, 10, 0, 0, timeZone));
final DateTime dateTime = (DateTime) c.convert("2014-03-12 12:34:00");
assertThat(dateTime.getZone()).isEqualTo(timeZone);
Assertions.assertThat(dateTime).isEqualTo(new DateTime(2014, 3, 12, 12, 34, 0, timeZone));
}
use of org.graylog2.plugin.inputs.Converter in project graylog2-server by Graylog2.
the class DateConverterTest method convertUsesEtcUTCIfTimeZoneSettingIsBlank.
@Test
public void convertUsesEtcUTCIfTimeZoneSettingIsBlank() throws Exception {
final Converter c = new DateConverter(config("YYYY-MM-dd HH:mm:ss", " "));
final DateTime dateOnly = (DateTime) c.convert("2014-03-12 10:00:00");
assertThat(dateOnly.getZone()).isEqualTo(DateTimeZone.forID("Etc/UTC"));
}
Aggregations