use of org.graylog2.plugin.inputs.Converter in project graylog2-server by Graylog2.
the class DateConverterTest method convertUsesEtcUTCIfTimeZoneSettingIsEmpty.
@Test
public void convertUsesEtcUTCIfTimeZoneSettingIsEmpty() 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"));
}
use of org.graylog2.plugin.inputs.Converter in project graylog2-server by Graylog2.
the class FlexibleDateConverterTest method testConvert.
@Test
public void testConvert() throws Exception {
Converter c = new FlexibleDateConverter(Collections.<String, Object>emptyMap());
assertNull(c.convert(null));
assertEquals(null, c.convert(""));
assertEquals(null, c.convert("foo"));
// Using startsWith here to avoid time zone problems in tests.
assertTrue(c.convert("2014-3-12").toString().startsWith("2014-03-12T"));
assertTrue(c.convert("2014-3-12 12:27").toString().startsWith("2014-03-12T12:27:00.000"));
assertTrue(c.convert("Mar 12").toString().contains("-03-12T"));
assertTrue(c.convert("Mar 12 2pm").toString().contains("-03-12T14:00:00.000"));
assertTrue(c.convert("Mar 12 14:45:38").toString().contains("-03-12T14:45:38.000"));
assertTrue(c.convert("Mar 2 13:48:18").toString().contains("-03-02T13:48:18.000"));
}
use of org.graylog2.plugin.inputs.Converter in project graylog2-server by Graylog2.
the class FlexibleDateConverterTest method convertUsesEtcUTCIfTimeZoneSettingIsBlank.
@Test
public void convertUsesEtcUTCIfTimeZoneSettingIsBlank() throws Exception {
Converter c = new FlexibleDateConverter(ImmutableMap.<String, Object>of("time_zone", " "));
final DateTime dateOnly = (DateTime) c.convert("2014-3-12");
assertThat(dateOnly.getZone()).isEqualTo(DateTimeZone.forID("Etc/UTC"));
}
use of org.graylog2.plugin.inputs.Converter in project graylog2-server by Graylog2.
the class FlexibleDateConverterTest method convertObeysTimeZone.
@Test
public void convertObeysTimeZone() throws Exception {
Converter c = new FlexibleDateConverter(ImmutableMap.<String, Object>of("time_zone", "+12:00"));
final DateTime dateOnly = (DateTime) c.convert("2014-3-12");
assertThat(dateOnly.getZone()).isEqualTo(DateTimeZone.forOffsetHours(12));
Assertions.assertThat(dateOnly).isAfterOrEqualTo(new DateTime(2014, 3, 12, 0, 0, DateTimeZone.forOffsetHours(12))).isBefore(new DateTime(2014, 3, 13, 0, 0, DateTimeZone.forOffsetHours(12)));
final DateTime dateTime = (DateTime) c.convert("2014-3-12 12:34");
assertThat(dateTime.getZone()).isEqualTo(DateTimeZone.forOffsetHours(12));
Assertions.assertThat(dateTime).isEqualTo(new DateTime(2014, 3, 12, 12, 34, DateTimeZone.forOffsetHours(12)));
final DateTime textualDateTime = (DateTime) c.convert("Mar 12, 2014 2pm");
assertThat(textualDateTime.getZone()).isEqualTo(DateTimeZone.forOffsetHours(12));
Assertions.assertThat(textualDateTime).isEqualTo(new DateTime(2014, 3, 12, 14, 0, DateTimeZone.forOffsetHours(12)));
}
use of org.graylog2.plugin.inputs.Converter in project graylog2-server by Graylog2.
the class JsonExtractorTest method testRunWithFlattenedObject.
@Test
public void testRunWithFlattenedObject() throws Exception {
final JsonExtractor jsonExtractor = new JsonExtractor(new MetricRegistry(), "json", "title", 0L, Extractor.CursorStrategy.COPY, "source", "target", ImmutableMap.<String, Object>of("flatten", true), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, "");
final String value = "{" + "\"object\": {" + "\"text\": \"foobar\", " + "\"number\": 1234.5678, " + "\"bool\": true, " + "\"null\": null, " + "\"nested\": {\"text\": \"foobar\"}" + "}" + "}";
final Extractor.Result[] results = jsonExtractor.run(value);
assertThat(results).contains(new Extractor.Result("text=foobar, number=1234.5678, bool=true, nested={text=foobar}", "object", -1, -1));
}
Aggregations