Search in sources :

Example 41 with DummpyMapEvent

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

the class URLDecodeOperationTest method testDecodeTwoThings.

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

Example 42 with DummpyMapEvent

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

the class FormattedSubstitutionTest method testStringSubNumberKnown.

@Test
public void testStringSubNumberKnown() 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("number = {0}"), Arrays.asList(v), true));
    DummpyMapEvent devent = new DummpyMapEvent();
    devent.setField("foo", new Float(1.234f));
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    SubstitutionOperation op = new SubstitutionOperation(substitutions);
    op.perform(ievent);
    assertEquals(2, devent.payload.size());
    assertEquals("number = 1.234", 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 43 with DummpyMapEvent

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

the class FormattedSubstitutionTest method testStringSubUnknownFail.

@Test(expected = OperationException.class)
public void testStringSubUnknownFail() throws FieldNotFoundException {
    Variable.FieldVariable v = new Variable.FieldVariable();
    v.setFailSrcNotFound(true);
    v.setSrcFields(Arrays.asList("baz"));
    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);
}
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 44 with DummpyMapEvent

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

the class FormattedSubstitutionTest method testStringSubRemove.

@Test
public void testStringSubRemove() throws FieldNotFoundException {
    Variable.FieldVariable v = new Variable.FieldVariable();
    v.setFailSrcNotFound(true);
    v.setRemoveSrcField(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(1, devent.payload.size());
    assertEquals("foo = 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 45 with DummpyMapEvent

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

the class FormattedSubstitutionTest method testStringSubUnknown.

@Test
public void testStringSubUnknown() throws FieldNotFoundException {
    Variable.FieldVariable v = new Variable.FieldVariable();
    v.setFailSrcNotFound(false);
    v.setSrcFields(Arrays.asList("baz"));
    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 = null", 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)

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