Search in sources :

Example 1 with LambdaContext

use of com.nextdoor.bender.LambdaContext in project bender by Nextdoor.

the class ContextSubstitutionTest method testExcludesContext.

@Test
public void testExcludesContext() throws FieldNotFoundException {
    ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
    substitutions.add(new ContextSubstitution("foo", Collections.emptyList(), Arrays.asList("functionName"), true));
    DummpyMapEvent devent = new DummpyMapEvent();
    TestContext ctx = new TestContext();
    ctx.setFunctionName("fun name");
    ctx.setInvokedFunctionArn("some arn");
    InternalEvent ievent = new InternalEvent("", new LambdaContext(ctx), 10);
    ievent.setEventObj(devent);
    ievent.setEventTime(20);
    SubstitutionOperation op = new SubstitutionOperation(substitutions);
    op.perform(ievent);
    Map<String, Object> expected = new HashMap<String, Object>() {

        {
            put("invokedFunctionArn", "some arn");
        }
    };
    assertEquals(expected, devent.getField("foo"));
}
Also used : HashMap(java.util.HashMap) TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) InternalEvent(com.nextdoor.bender.InternalEvent) ContextSubstitution(com.nextdoor.bender.operation.substitution.context.ContextSubstitution) ContextSubstitution(com.nextdoor.bender.operation.substitution.context.ContextSubstitution) LambdaContext(com.nextdoor.bender.LambdaContext) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) Test(org.junit.Test)

Example 2 with LambdaContext

use of com.nextdoor.bender.LambdaContext in project bender by Nextdoor.

the class ContextSubstitutionTest method testIncludesContext.

@Test
public void testIncludesContext() throws FieldNotFoundException {
    ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
    substitutions.add(new ContextSubstitution("foo", Arrays.asList("functionName"), Collections.emptyList(), true));
    DummpyMapEvent devent = new DummpyMapEvent();
    TestContext ctx = new TestContext();
    ctx.setFunctionName("fun name");
    ctx.setInvokedFunctionArn("some arn");
    InternalEvent ievent = new InternalEvent("", new LambdaContext(ctx), 10);
    ievent.setEventObj(devent);
    ievent.setEventTime(20);
    SubstitutionOperation op = new SubstitutionOperation(substitutions);
    op.perform(ievent);
    Map<String, Object> expected = new HashMap<String, Object>() {

        {
            put("functionName", "fun name");
        }
    };
    assertEquals(expected, devent.getField("foo"));
}
Also used : HashMap(java.util.HashMap) TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) InternalEvent(com.nextdoor.bender.InternalEvent) ContextSubstitution(com.nextdoor.bender.operation.substitution.context.ContextSubstitution) ContextSubstitution(com.nextdoor.bender.operation.substitution.context.ContextSubstitution) LambdaContext(com.nextdoor.bender.LambdaContext) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) Test(org.junit.Test)

Example 3 with LambdaContext

use of com.nextdoor.bender.LambdaContext 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());
}
Also used : ArraySplitOperation(com.nextdoor.bender.operation.json.array.ArraySplitOperation) GenericJsonEvent(com.nextdoor.bender.deserializer.json.GenericJsonEvent) JsonElement(com.google.gson.JsonElement) TestContext(com.nextdoor.bender.aws.TestContext) LambdaContext(com.nextdoor.bender.LambdaContext) JsonParser(com.google.gson.JsonParser) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test) OperationTest(com.nextdoor.bender.operations.json.OperationTest)

Example 4 with LambdaContext

use of com.nextdoor.bender.LambdaContext in project bender by Nextdoor.

the class ArraySplitOperationTest method testMetadataMatch.

@Test
public void testMetadataMatch() 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> events = operation.perform(ievent);
    assertEquals(new Long(1), events.get(0).getEventMetadata().get("arrivalEpochMs"));
    assertEquals("6a00541bfa24fd59884de557be71f3a5a1344613", events.get(0).getEventMetadata().get("eventSha1Hash"));
    assertEquals(new Long(1), events.get(1).getEventMetadata().get("arrivalEpochMs"));
    assertEquals("5cbc013a144777d9ce51385ac24a95ce05f77075", events.get(1).getEventMetadata().get("eventSha1Hash"));
    assertEquals(new Long(1), events.get(2).getEventMetadata().get("arrivalEpochMs"));
    assertEquals("6c3023db7ef03721c27df9f33b26e0d2cbc84d6b", events.get(2).getEventMetadata().get("eventSha1Hash"));
}
Also used : ArraySplitOperation(com.nextdoor.bender.operation.json.array.ArraySplitOperation) GenericJsonEvent(com.nextdoor.bender.deserializer.json.GenericJsonEvent) JsonElement(com.google.gson.JsonElement) TestContext(com.nextdoor.bender.aws.TestContext) LambdaContext(com.nextdoor.bender.LambdaContext) JsonParser(com.google.gson.JsonParser) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test) OperationTest(com.nextdoor.bender.operations.json.OperationTest)

Example 5 with LambdaContext

use of com.nextdoor.bender.LambdaContext in project bender by Nextdoor.

the class ArraySplitOperationTest method testMissingField.

@Test(expected = OperationException.class)
public void testMissingField() 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("$.bar]");
    InternalEvent ievent = new InternalEvent("", lctx, 123);
    ievent.setEventObj(devent);
    ievent.setEventTime(124);
    List<InternalEvent> events = operation.perform(ievent);
}
Also used : ArraySplitOperation(com.nextdoor.bender.operation.json.array.ArraySplitOperation) GenericJsonEvent(com.nextdoor.bender.deserializer.json.GenericJsonEvent) JsonElement(com.google.gson.JsonElement) TestContext(com.nextdoor.bender.aws.TestContext) LambdaContext(com.nextdoor.bender.LambdaContext) JsonParser(com.google.gson.JsonParser) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test) OperationTest(com.nextdoor.bender.operations.json.OperationTest)

Aggregations

LambdaContext (com.nextdoor.bender.LambdaContext)14 TestContext (com.nextdoor.bender.aws.TestContext)10 Test (org.junit.Test)10 InternalEvent (com.nextdoor.bender.InternalEvent)9 JsonElement (com.google.gson.JsonElement)6 GenericJsonEvent (com.nextdoor.bender.deserializer.json.GenericJsonEvent)6 ArraySplitOperation (com.nextdoor.bender.operation.json.array.ArraySplitOperation)6 OperationTest (com.nextdoor.bender.operations.json.OperationTest)6 JsonParser (com.google.gson.JsonParser)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 S3EventNotificationRecord (com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord)2 ContextSubstitution (com.nextdoor.bender.operation.substitution.context.ContextSubstitution)2 DummpyMapEvent (com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent)2 SourceNotFoundException (com.nextdoor.bender.utils.SourceUtils.SourceNotFoundException)2 DynamodbStreamRecord (com.amazonaws.services.lambda.runtime.events.DynamodbEvent.DynamodbStreamRecord)1 KinesisEventRecord (com.amazonaws.services.lambda.runtime.events.KinesisEvent.KinesisEventRecord)1 SNSRecord (com.amazonaws.services.lambda.runtime.events.SNSEvent.SNSRecord)1 S3EventNotification (com.amazonaws.services.s3.event.S3EventNotification)1 GenericTransportBuffer (com.nextdoor.bender.ipc.generic.GenericTransportBuffer)1