GelfOperation implements EventOperation { public InternalEvent perform(InternalEvent ievent) { ievent = subOp.perform(ievent); ievent = flattenOp.perform(ievent); ievent = prefix(ievent); ievent = setTimestamp(ievent); return ievent; } GelfOperation(List<Substitution> substitutions); InternalEvent perform(InternalEvent ievent);  }
@Test public void testPrefixingNoCustomTimestamp() throws JsonSyntaxException, UnsupportedEncodingException, IOException { JsonParser parser = new JsonParser(); JsonElement input = parser.parse(getResourceString("prefixed_input.json")); String expectedOutput = getResourceString("prefixed_output.json"); DummpyEvent devent = new DummpyEvent(); devent.payload = input.getAsJsonObject(); GelfOperation op = new GelfOperation(new ArrayList<>()); InternalEvent ievent = new InternalEvent("", null, 0); ievent.setEventObj(devent); op.perform(ievent); assertEquals(parser.parse(expectedOutput), devent.payload); }
@Test public void testEventTimestamp() throws JsonSyntaxException, IOException { JsonParser parser = new JsonParser(); JsonElement input = parser.parse(getResourceString("prefixed_input.json")); DummpyEvent devent = new DummpyEvent(); devent.payload = input.getAsJsonObject(); GelfOperation op = new GelfOperation(new ArrayList<>()); InternalEvent ievent = new InternalEvent("", null, 1234567890123L); ievent.setEventObj(devent); ievent.setEventTime(1522686301055L); op.perform(ievent); assertTrue(devent.payload.toString().contains("\"timestamp\":1.522686301055E9")); }
@Test public void testFlattenPrefix() throws JsonSyntaxException, UnsupportedEncodingException, IOException { JsonParser parser = new JsonParser(); JsonElement input = parser.parse(getResourceString("flatten_prefixed_input.json")); String expectedOutput = getResourceString("flatten_prefixed_output.json"); DummpyEvent devent = new DummpyEvent(); devent.payload = input.getAsJsonObject(); GelfOperation op = new GelfOperation(new ArrayList<>()); InternalEvent ievent = new InternalEvent("", null, 0); ievent.setEventObj(devent); op.perform(ievent); assertEquals(parser.parse(expectedOutput), devent.payload); }