Search in sources :

Example 1 with ContextSubstitution

use of com.nextdoor.bender.operation.substitution.context.ContextSubstitution 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 ContextSubstitution

use of com.nextdoor.bender.operation.substitution.context.ContextSubstitution 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)

Aggregations

InternalEvent (com.nextdoor.bender.InternalEvent)2 LambdaContext (com.nextdoor.bender.LambdaContext)2 TestContext (com.nextdoor.bender.aws.TestContext)2 ContextSubstitution (com.nextdoor.bender.operation.substitution.context.ContextSubstitution)2 DummpyMapEvent (com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2