use of org.graylog.plugins.pipelineprocessor.functions.ips.IpAddress in project graylog2-server by Graylog2.
the class FunctionsSnippetsTest method conversions.
@Test
public void conversions() {
final Rule rule = parser.parseRule(ruleForTest(), false);
final EvaluationContext context = contextForRuleEval(rule, new Message("test", "test", Tools.nowUTC()));
assertThat(context.evaluationErrors()).isEmpty();
final Message message = context.currentMessage();
assertNotNull(message);
assertThat(message.getField("string_1")).isEqualTo("1");
assertThat(message.getField("string_2")).isEqualTo("2");
// special case, Message doesn't allow adding fields with empty string values
assertThat(message.hasField("string_3")).isFalse();
assertThat(message.getField("string_4")).isEqualTo("default");
assertThat(message.getField("string_5")).isEqualTo("false");
assertThat(message.getField("string_6")).isEqualTo("42");
assertThat(message.getField("string_7")).isEqualTo("23.42");
assertThat(message.getField("long_1")).isEqualTo(1L);
assertThat(message.getField("long_2")).isEqualTo(2L);
assertThat(message.getField("long_3")).isEqualTo(0L);
assertThat(message.getField("long_4")).isEqualTo(1L);
assertThat(message.getField("long_5")).isEqualTo(23L);
assertThat(message.getField("long_6")).isEqualTo(23L);
assertThat(message.getField("long_7")).isEqualTo(1L);
assertThat(message.getField("long_min1")).isEqualTo(Long.MIN_VALUE);
assertThat(message.getField("long_min2")).isEqualTo(1L);
assertThat(message.getField("long_max1")).isEqualTo(Long.MAX_VALUE);
assertThat(message.getField("long_max2")).isEqualTo(1L);
assertThat(message.getField("double_1")).isEqualTo(1d);
assertThat(message.getField("double_2")).isEqualTo(2d);
assertThat(message.getField("double_3")).isEqualTo(0d);
assertThat(message.getField("double_4")).isEqualTo(1d);
assertThat(message.getField("double_5")).isEqualTo(23d);
assertThat(message.getField("double_6")).isEqualTo(23d);
assertThat(message.getField("double_7")).isEqualTo(23.42d);
assertThat(message.getField("double_min1")).isEqualTo(Double.MIN_VALUE);
assertThat(message.getField("double_min2")).isEqualTo(0d);
assertThat(message.getField("double_max1")).isEqualTo(Double.MAX_VALUE);
assertThat(message.getField("double_inf1")).isEqualTo(Double.POSITIVE_INFINITY);
assertThat(message.getField("double_inf2")).isEqualTo(Double.NEGATIVE_INFINITY);
assertThat(message.getField("double_inf3")).isEqualTo(Double.POSITIVE_INFINITY);
assertThat(message.getField("double_inf4")).isEqualTo(Double.NEGATIVE_INFINITY);
assertThat(message.getField("bool_1")).isEqualTo(true);
assertThat(message.getField("bool_2")).isEqualTo(false);
assertThat(message.getField("bool_3")).isEqualTo(false);
assertThat(message.getField("bool_4")).isEqualTo(true);
// the is wrapped in our own class for safety in rules
assertThat(message.getField("ip_1")).isEqualTo(new IpAddress(InetAddresses.forString("127.0.0.1")));
assertThat(message.getField("ip_2")).isEqualTo(new IpAddress(InetAddresses.forString("127.0.0.1")));
assertThat(message.getField("ip_3")).isEqualTo(new IpAddress(InetAddresses.forString("0.0.0.0")));
assertThat(message.getField("ip_4")).isEqualTo(new IpAddress(InetAddresses.forString("::1")));
assertThat(message.getField("map_1")).isEqualTo(Collections.singletonMap("foo", "bar"));
assertThat(message.getField("map_2")).isEqualTo(Collections.emptyMap());
assertThat(message.getField("map_3")).isEqualTo(Collections.emptyMap());
assertThat(message.getField("map_4")).isEqualTo(Collections.emptyMap());
assertThat(message.getField("map_5")).isEqualTo(Collections.emptyMap());
assertThat(message.getField("map_6")).isEqualTo(Collections.emptyMap());
}
Aggregations