use of com.nextdoor.bender.deserializer.json.GenericJsonEvent in project bender by Nextdoor.
the class DeleteFieldOperationTest method testExistingField.
@Test
public void testExistingField() {
InternalEvent ievent = new InternalEvent("foo", null, 1);
JsonObject actualJsonObject = new JsonObject();
actualJsonObject.addProperty("ex", "exists");
GenericJsonEvent jsonEvent = new GenericJsonEvent(actualJsonObject);
ievent.setEventObj(jsonEvent);
DeleteFieldOperation operation = new DeleteFieldOperation("ex");
operation.perform(ievent);
JsonObject expectedJsonObject = new JsonObject();
assertEquals(expectedJsonObject, actualJsonObject);
}
use of com.nextdoor.bender.deserializer.json.GenericJsonEvent in project bender by Nextdoor.
the class DeleteFieldOperationTest method testNonExistingField.
@Test
public void testNonExistingField() {
InternalEvent ievent = new InternalEvent("foo", null, 1);
JsonObject actualJsonObject = new JsonObject();
actualJsonObject.addProperty("different", "exists");
GenericJsonEvent jsonEvent = new GenericJsonEvent(actualJsonObject);
ievent.setEventObj(jsonEvent);
DeleteFieldOperation operation = new DeleteFieldOperation("ex");
operation.perform(ievent);
JsonObject expectedJsonObject = new JsonObject();
expectedJsonObject.addProperty("different", "exists");
assertEquals(expectedJsonObject, actualJsonObject);
}
use of com.nextdoor.bender.deserializer.json.GenericJsonEvent in project bender by Nextdoor.
the class RegexFilterOperationTest method testFilterMatches.
@Test
public void testFilterMatches() throws IOException, FieldNotFoundException {
JsonParser parser = new JsonParser();
JsonElement input = parser.parse(getResourceString("filter_input.json"));
GenericJsonEvent devent = new GenericJsonEvent(input.getAsJsonObject());
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
String path = "$.simple_object.key";
Pattern patternMatch = Pattern.compile("(val)");
Pattern patternFail = Pattern.compile("(fail)");
Boolean match = true;
assertNotNull(devent.getFieldAsString(path));
RegexFilterOperation opMatch = new RegexFilterOperation(patternMatch, path, match);
RegexFilterOperation opFail = new RegexFilterOperation(patternFail, path, match);
assertFalse(opMatch.test(ievent));
assertTrue(opFail.test(ievent));
}
use of com.nextdoor.bender.deserializer.json.GenericJsonEvent in project bender by Nextdoor.
the class ArraySplitOperationTest method testEventString.
@Test
public void testEventString() 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(InternalEvent::getEventString).collect(Collectors.toList());
List<String> expected = Arrays.asList("{\"foo\":1}", "{\"foo\":2}", "{\"foo\":3}");
assertEquals(expected, actual);
}
use of com.nextdoor.bender.deserializer.json.GenericJsonEvent in project bender by Nextdoor.
the class ArraySplitOperationTest method testTimeMatch.
@Test
public void testTimeMatch() 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, 123);
ievent.setEventObj(devent);
ievent.setEventTime(124);
List<InternalEvent> events = operation.perform(ievent);
assertEquals(ievent.getArrivalTime(), events.get(0).getArrivalTime());
assertEquals(ievent.getEventTime(), events.get(0).getEventTime());
assertEquals(ievent.getArrivalTime(), events.get(1).getArrivalTime());
assertEquals(ievent.getEventTime(), events.get(1).getEventTime());
assertEquals(ievent.getArrivalTime(), events.get(2).getArrivalTime());
assertEquals(ievent.getEventTime(), events.get(2).getEventTime());
}
Aggregations