use of com.nextdoor.bender.operation.json.array.ArraySplitOperation in project bender by Nextdoor.
the class ArraySplitOperationTest method testArraySplitWithFieldsToKeep.
@Test
public void testArraySplitWithFieldsToKeep() throws IOException {
TestContext t = new TestContext();
t.setFunctionName("foo");
LambdaContext lctx = new LambdaContext(t);
JsonElement input = JsonParser.parseString(getResourceString("array_input_kinesis_format.json"));
GenericJsonEvent devent = new GenericJsonEvent(input.getAsJsonObject());
List<String> fieldsToKeep = Arrays.asList("owner", "logGroup", "logStream");
ArraySplitOperation operation = new ArraySplitOperation("$.logEvents", fieldsToKeep);
InternalEvent ievent = new InternalEvent("", lctx, 123);
ievent.setEventObj(devent);
ievent.setEventTime(124);
List<InternalEvent> events = operation.perform(ievent);
assertEquals(4, events.size());
JsonElement actual = JsonParser.parseString(events.get(0).getEventString());
assertTrue(actual.getAsJsonObject().has("owner"));
assertTrue(actual.getAsJsonObject().has("logGroup"));
assertTrue(actual.getAsJsonObject().has("logStream"));
assertTrue(actual.getAsJsonObject().has("id"));
assertTrue(actual.getAsJsonObject().has("message"));
assertTrue(actual.getAsJsonObject().has("timestamp"));
actual = JsonParser.parseString(events.get(1).getEventString());
assertTrue(actual.getAsJsonObject().has("owner"));
assertTrue(actual.getAsJsonObject().has("logGroup"));
assertTrue(actual.getAsJsonObject().has("logStream"));
assertTrue(actual.getAsJsonObject().has("id"));
assertTrue(actual.getAsJsonObject().has("message"));
assertTrue(actual.getAsJsonObject().has("timestamp"));
actual = JsonParser.parseString(events.get(2).getEventString());
assertTrue(actual.getAsJsonObject().has("owner"));
assertTrue(actual.getAsJsonObject().has("logGroup"));
assertTrue(actual.getAsJsonObject().has("logStream"));
assertTrue(actual.getAsJsonObject().has("id"));
assertTrue(actual.getAsJsonObject().has("message"));
assertTrue(actual.getAsJsonObject().has("timestamp"));
actual = JsonParser.parseString(events.get(3).getEventString());
assertTrue(actual.getAsJsonObject().has("owner"));
assertTrue(actual.getAsJsonObject().has("logGroup"));
assertTrue(actual.getAsJsonObject().has("logStream"));
assertTrue(actual.getAsJsonObject().has("id"));
assertTrue(actual.getAsJsonObject().has("message"));
assertTrue(actual.getAsJsonObject().has("timestamp"));
}
use of com.nextdoor.bender.operation.json.array.ArraySplitOperation in project bender by Nextdoor.
the class ArraySplitOperationTest method testContextMatch.
@Test
public void testContextMatch() throws JsonSyntaxException, UnsupportedEncodingException, IOException {
JsonParser parser = new JsonParser();
TestContext t = new TestContext();
t.setFunctionName("foo");
LambdaContext lctx = new LambdaContext(t);
JsonElement input = parser.parse(getResourceString("array_input.json"));
GenericJsonEvent devent = new GenericJsonEvent(input.getAsJsonObject());
ArraySplitOperation operation = new ArraySplitOperation("$.arr");
InternalEvent ievent = new InternalEvent("", lctx, 1);
ievent.setEventObj(devent);
List<InternalEvent> actual = operation.perform(ievent);
assertEquals(lctx, actual.get(0).getCtx());
assertEquals(lctx, actual.get(1).getCtx());
assertEquals(lctx, actual.get(2).getCtx());
}
use of com.nextdoor.bender.operation.json.array.ArraySplitOperation in project bender by Nextdoor.
the class ArraySplitOperationTest method testEventObject.
@Test
public void testEventObject() throws JsonSyntaxException, UnsupportedEncodingException, IOException {
JsonParser parser = new JsonParser();
JsonElement input = parser.parse(getResourceString("array_input.json"));
GenericJsonEvent devent = new GenericJsonEvent(input.getAsJsonObject());
ArraySplitOperation operation = new ArraySplitOperation("$.arr");
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
List<String> actual = operation.perform(ievent).stream().map(i -> {
return i.getEventObj().getPayload().toString();
}).collect(Collectors.toList());
List<String> expected = Arrays.asList("{\"foo\":1}", "{\"foo\":2}", "{\"foo\":3}");
assertEquals(expected, actual);
}
Aggregations