use of org.apache.logging.log4j.lookup.MapMessageLookup in project logging-log4j2 by apache.
the class MapMessageLookupTest method testStructuredDataMessageLookup.
@Test
public void testStructuredDataMessageLookup() {
// GIVEN: A StructuredDataMessage object
final StructuredDataMessage message = new StructuredDataMessage("id", "msg", "type");
message.put("A", "a");
message.put("B", "b");
message.put("C", "c");
// AND: An event with that message
final LogEvent event = Log4jLogEvent.newBuilder().setLevel(Level.DEBUG).setMessage(message).build();
// AND: A MapMessageLookup object
final MapMessageLookup lookup = new MapMessageLookup();
// WHEN: Lookup is performed
final String a = lookup.lookup(event, "A");
final String b = lookup.lookup(event, "B");
final String c = lookup.lookup(event, "C");
// THEN: The looked up values are correct
assertEquals("a", a);
assertEquals("b", b);
assertEquals("c", c);
}
use of org.apache.logging.log4j.lookup.MapMessageLookup in project logging-log4j2 by apache.
the class MapMessageLookupTest method testStringMapMessageLookup.
@Test
public void testStringMapMessageLookup() {
// GIVEN: A StringMapMessage object
final Map<String, String> values = new HashMap<>(3);
values.put("A", "a");
values.put("B", "b");
values.put("C", "c");
final MapMessage message = new StringMapMessage(values);
// AND: An event with that message
final LogEvent event = Log4jLogEvent.newBuilder().setLevel(Level.DEBUG).setMessage(message).build();
// AND: A MapMessageLookup object
final MapMessageLookup lookup = new MapMessageLookup();
// WHEN: Lookup is performed
final String a = lookup.lookup(event, "A");
final String b = lookup.lookup(event, "B");
final String c = lookup.lookup(event, "C");
// THEN: The looked up values are correct
assertEquals("a", a);
assertEquals("b", b);
assertEquals("c", c);
}
Aggregations