Search in sources :

Example 6 with DummpyMapEvent

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

the class NestedSubstitutionTest method testBasicNested.

@Test
public void testBasicNested() throws FieldNotFoundException {
    /*
     * Substitutions in nest
     */
    FieldSubstitutionConfig fieldSubConfig = new FieldSubstitutionConfig("bar", Arrays.asList("foo0", "foo1", "foo2"), false, true, true);
    StaticSubstitutionConfig staticSubConfig = new StaticSubstitutionConfig("static", "value", true);
    /*
     * Nested substitution
     */
    List<SubstitutionConfig> nsc = Arrays.asList(fieldSubConfig, staticSubConfig);
    NestedSubstitutionFactory nsf = new NestedSubstitutionFactory();
    nsf.setConf(new NestedSubstitutionConfig("a", nsc, true));
    DummpyMapEvent devent = new DummpyMapEvent();
    devent.setField("foo2", "1234");
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    SubstitutionOperation op = new SubstitutionOperation(Arrays.asList(nsf.newInstance()));
    op.perform(ievent);
    Map<String, Object> expectedNested = new HashMap<String, Object>() {

        {
            put("bar", "1234");
            put("static", "value");
        }
    };
    assertEquals(expectedNested, 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) 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)

Example 7 with DummpyMapEvent

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

the class URLDecodeOperationTest method testDecodeOnce.

@Test
public void testDecodeOnce() throws FieldNotFoundException {
    DummpyMapEvent devent = new DummpyMapEvent();
    devent.setField("foo", "%3Ffoo%3Dbar%26baz%3Dqux");
    URLDecodeOperation op = new URLDecodeOperation(Arrays.asList("foo"), 1);
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    op.perform(ievent);
    assertEquals(1, devent.payload.size());
    assertEquals("?foo=bar&baz=qux", devent.getFieldAsString("foo"));
}
Also used : DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 8 with DummpyMapEvent

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

the class URLDecodeOperationTest method testDecodeTwoThingsEmpty.

@Test
public void testDecodeTwoThingsEmpty() throws FieldNotFoundException {
    DummpyMapEvent devent = new DummpyMapEvent();
    devent.setField("foo", "%3Ffoo%3Dbar%26baz%3Dqux");
    URLDecodeOperation op = new URLDecodeOperation(Arrays.asList("foo", "bar"), 1);
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    op.perform(ievent);
    assertEquals(1, devent.payload.size());
    assertEquals("?foo=bar&baz=qux", devent.getFieldAsString("foo"));
}
Also used : DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 9 with DummpyMapEvent

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

the class URLDecodeOperationTest method testDecodeTwice.

@Test
public void testDecodeTwice() throws FieldNotFoundException {
    DummpyMapEvent devent = new DummpyMapEvent();
    devent.setField("foo", "%253Ffoo%253Dbar%2526baz%253Dqux");
    URLDecodeOperation op = new URLDecodeOperation(Arrays.asList("foo"), 2);
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    op.perform(ievent);
    assertEquals(1, devent.payload.size());
    assertEquals("?foo=bar&baz=qux", devent.getFieldAsString("foo"));
}
Also used : DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 10 with DummpyMapEvent

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

the class FieldSubstitutionTest method testKnownField.

@Test
public void testKnownField() throws FieldNotFoundException {
    ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
    substitutions.add(new FieldSubstitution("bar", Arrays.asList("foo"), false, true, 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("1234", devent.getField("bar"));
    assertEquals("1234", devent.getField("foo"));
}
Also used : FieldSubstitution(com.nextdoor.bender.operation.substitution.field.FieldSubstitution) FieldSubstitution(com.nextdoor.bender.operation.substitution.field.FieldSubstitution) ArrayList(java.util.ArrayList) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) InternalEvent(com.nextdoor.bender.InternalEvent) 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