Search in sources :

Example 1 with DummpyMapEvent

use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent 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 DummpyMapEvent

use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent 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 DummpyMapEvent

use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent in project bender by Nextdoor.

the class FormattedSubstitutionTest method testStringSubStatic.

@Test
public void testStringSubStatic() throws FieldNotFoundException {
    Variable.StaticVariable v = new Variable.StaticVariable();
    v.setValue("1234");
    ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
    substitutions.add(new FormattedSubstitution("bar", new ExtendedMessageFormat("static = {0}"), Arrays.asList(v), true));
    DummpyMapEvent devent = new DummpyMapEvent();
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    SubstitutionOperation op = new SubstitutionOperation(substitutions);
    op.perform(ievent);
    assertEquals(1, devent.payload.size());
    assertEquals("static = 1234", devent.getField("bar"));
}
Also used : FormattedSubstitution(com.nextdoor.bender.operation.substitution.formatted.FormattedSubstitution) ArrayList(java.util.ArrayList) ExtendedMessageFormat(org.apache.commons.text.ExtendedMessageFormat) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) FormattedSubstitution(com.nextdoor.bender.operation.substitution.formatted.FormattedSubstitution) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 4 with DummpyMapEvent

use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent in project bender by Nextdoor.

the class FormattedSubstitutionTest method testStringSubKnown.

@Test
public void testStringSubKnown() throws FieldNotFoundException {
    Variable.FieldVariable v = new Variable.FieldVariable();
    v.setFailSrcNotFound(true);
    v.setSrcFields(Arrays.asList("foo"));
    ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
    substitutions.add(new FormattedSubstitution("bar", new ExtendedMessageFormat("foo = {0}"), Arrays.asList(v), true));
    DummpyMapEvent devent = new DummpyMapEvent();
    devent.setField("foo", "1234");
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    SubstitutionOperation op = new SubstitutionOperation(substitutions);
    op.perform(ievent);
    assertEquals(2, devent.payload.size());
    assertEquals("foo = 1234", devent.getField("bar"));
    assertEquals("1234", devent.getField("foo"));
}
Also used : FormattedSubstitution(com.nextdoor.bender.operation.substitution.formatted.FormattedSubstitution) ArrayList(java.util.ArrayList) ExtendedMessageFormat(org.apache.commons.text.ExtendedMessageFormat) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) FormattedSubstitution(com.nextdoor.bender.operation.substitution.formatted.FormattedSubstitution) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 5 with DummpyMapEvent

use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent in project bender by Nextdoor.

the class NestedSubstitutionTest method testNestedNested.

@Test
public void testNestedNested() throws FieldNotFoundException {
    /*
     * Expected output {a={b={bar=1234, static=value}}, foo2=1234}
     */
    /*
     * Inner nest substitutions
     */
    FieldSubstitutionConfig fieldSubConfig = new FieldSubstitutionConfig("bar", Arrays.asList("foo0", "foo1", "foo2"), false, true, true);
    StaticSubstitutionConfig staticSubConfig = new StaticSubstitutionConfig("static", "value", true);
    /*
     * Substitutions in outer nest
     */
    List<SubstitutionConfig> nscInner = Arrays.asList(fieldSubConfig, staticSubConfig);
    NestedSubstitutionConfig nsfInner = new NestedSubstitutionConfig("b", nscInner, true);
    /*
     * Substitution
     */
    NestedSubstitutionConfig nsfOuter = new NestedSubstitutionConfig("a", Arrays.asList(nsfInner), true);
    NestedSubstitutionFactory subFactory = new NestedSubstitutionFactory();
    subFactory.setConf(nsfOuter);
    DummpyMapEvent devent = new DummpyMapEvent();
    devent.setField("foo2", "1234");
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    List<Substitution> sub = Arrays.asList(subFactory.newInstance());
    SubstitutionOperation op = new SubstitutionOperation(sub);
    op.perform(ievent);
    Map<String, Object> expectedNest2 = new HashMap<String, Object>() {

        {
            put("bar", "1234");
            put("static", "value");
        }
    };
    Map<String, Object> expectedNest1 = new HashMap<String, Object>() {

        {
            put("b", expectedNest2);
        }
    };
    assertEquals(expectedNest1, devent.getField("a"));
    assertEquals("1234", devent.getField("foo2"));
}
Also used : FieldSubstitutionConfig(com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig) HashMap(java.util.HashMap) InternalEvent(com.nextdoor.bender.InternalEvent) StaticSubstitutionConfig(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig) ContextSubstitution(com.nextdoor.bender.operation.substitution.context.ContextSubstitution) FieldSubstitution(com.nextdoor.bender.operation.substitution.field.FieldSubstitution) StaticSubstitution(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitution) MetadataSubstitution(com.nextdoor.bender.operation.substitution.metadata.MetadataSubstitution) RegexSubstitution(com.nextdoor.bender.operation.substitution.regex.RegexSubstitution) FieldSubstitutionConfig(com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig) StaticSubstitutionConfig(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) Test(org.junit.Test)

Aggregations

InternalEvent (com.nextdoor.bender.InternalEvent)46 DummpyMapEvent (com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent)46 Test (org.junit.Test)45 ArrayList (java.util.ArrayList)29 RegexSubstitution (com.nextdoor.bender.operation.substitution.regex.RegexSubstitution)12 RegexSubField (com.nextdoor.bender.operation.substitution.regex.RegexSubstitutionConfig.RegexSubField)11 HashMap (java.util.HashMap)10 FieldSubstitution (com.nextdoor.bender.operation.substitution.field.FieldSubstitution)7 FormattedSubstitution (com.nextdoor.bender.operation.substitution.formatted.FormattedSubstitution)7 ExtendedMessageFormat (org.apache.commons.text.ExtendedMessageFormat)7 ContextSubstitution (com.nextdoor.bender.operation.substitution.context.ContextSubstitution)3 MetadataSubstitution (com.nextdoor.bender.operation.substitution.metadata.MetadataSubstitution)3 LambdaContext (com.nextdoor.bender.LambdaContext)2 TestContext (com.nextdoor.bender.aws.TestContext)2 OperationException (com.nextdoor.bender.operation.OperationException)2 FieldSubstitutionConfig (com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig)2 StaticSubstitution (com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitution)2 StaticSubstitutionConfig (com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig)2