Search in sources :

Example 31 with Converter

use of org.graylog2.plugin.inputs.Converter in project graylog2-server by Graylog2.

the class FlexibleDateConverterTest method convertUsesEtcUTCIfTimeZoneSettingIsNotAString.

@Test
public void convertUsesEtcUTCIfTimeZoneSettingIsNotAString() throws Exception {
    Converter c = new FlexibleDateConverter(ImmutableMap.<String, Object>of("time_zone", 42));
    final DateTime dateOnly = (DateTime) c.convert("2014-3-12");
    assertThat(dateOnly.getZone()).isEqualTo(DateTimeZone.forID("Etc/UTC"));
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 32 with Converter

use of org.graylog2.plugin.inputs.Converter in project graylog2-server by Graylog2.

the class FlexibleDateConverterTest method convertUsesEtcUTCIfTimeZoneSettingIsInvalid.

@Test
public void convertUsesEtcUTCIfTimeZoneSettingIsInvalid() throws Exception {
    Converter c = new FlexibleDateConverter(ImmutableMap.<String, Object>of("time_zone", "TEST"));
    final DateTime dateOnly = (DateTime) c.convert("2014-3-12");
    assertThat(dateOnly.getZone()).isEqualTo(DateTimeZone.forID("Etc/UTC"));
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 33 with Converter

use of org.graylog2.plugin.inputs.Converter in project graylog2-server by Graylog2.

the class HashConverterTest method testConvert.

@Test
public void testConvert() throws Exception {
    Converter hc = new HashConverter(new HashMap<String, Object>());
    assertNull(hc.convert(null));
    assertEquals("", hc.convert(""));
    assertEquals("c029b5a72ae255853d7151a9e28c6260", hc.convert("graylog2"));
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) Test(org.junit.Test)

Example 34 with Converter

use of org.graylog2.plugin.inputs.Converter in project graylog2-server by Graylog2.

the class LowercaseConverterTest method testConvert.

@Test
public void testConvert() throws Exception {
    Converter c = new LowercaseConverter(new HashMap<String, Object>());
    assertNull(c.convert(null));
    assertEquals("", c.convert(""));
    assertEquals("foobar", c.convert("foobar"));
    assertEquals("foo bar", c.convert("foo BAR"));
    assertEquals("foobar", c.convert("FooBar"));
    assertEquals("foobar ", c.convert("foobar "));
    assertEquals(" foobar", c.convert(" foobar"));
    assertEquals("foobar", c.convert("FOOBAR"));
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) Test(org.junit.Test)

Example 35 with Converter

use of org.graylog2.plugin.inputs.Converter in project graylog2-server by Graylog2.

the class NumericConverterTest method testConvert.

@Test
public void testConvert() throws Exception {
    Converter hc = new NumericConverter(new HashMap<String, Object>());
    assertNull(hc.convert(null));
    assertEquals("", hc.convert(""));
    assertEquals("lol no number", hc.convert("lol no number"));
    assertEquals(9001, hc.convert("9001"));
    assertEquals(2147483648L, hc.convert("2147483648"));
    assertEquals(10.4D, hc.convert("10.4"));
    assertEquals(Integer.class, hc.convert("4").getClass());
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)37 Converter (org.graylog2.plugin.inputs.Converter)22 Message (org.graylog2.plugin.Message)14 DateTime (org.joda.time.DateTime)10 Function (com.google.common.base.Function)8 Result (org.graylog2.plugin.inputs.Extractor.Result)8 Callable (java.util.concurrent.Callable)7 MetricRegistry (com.codahale.metrics.MetricRegistry)6 Extractor (org.graylog2.plugin.inputs.Extractor)6 BadRequestException (javax.ws.rs.BadRequestException)2 ConfigurationException (org.graylog2.ConfigurationException)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 BasicDBList (com.mongodb.BasicDBList)1 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NotFoundException (org.graylog2.database.NotFoundException)1 ConverterFactory (org.graylog2.inputs.converters.ConverterFactory)1