Search in sources :

Example 36 with DummpyMapEvent

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

the class StaticSubstitutionTest method testStaticField.

@Test
public void testStaticField() throws FieldNotFoundException {
    ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
    substitutions.add(new StaticSubstitution("foo", "1234", true));
    DummpyMapEvent devent = new DummpyMapEvent();
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    SubstitutionOperation op = new SubstitutionOperation(substitutions);
    op.perform(ievent);
    assertEquals("1234", devent.getField("foo"));
}
Also used : StaticSubstitution(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitution) ArrayList(java.util.ArrayList) StaticSubstitution(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitution) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 37 with DummpyMapEvent

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

the class FieldSubstitutionTest method testFieldList.

@Test
public void testFieldList() throws FieldNotFoundException {
    ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
    substitutions.add(new FieldSubstitution("bar", Arrays.asList("foo0", "foo1", "foo2"), false, true, true));
    DummpyMapEvent devent = new DummpyMapEvent();
    devent.setField("foo2", "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("foo2"));
}
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)

Example 38 with DummpyMapEvent

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

the class FieldSubstitutionTest method testRemoveField.

@Test
public void testRemoveField() throws FieldNotFoundException {
    ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
    substitutions.add(new FieldSubstitution("bar", Arrays.asList("foo"), true, 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(1, devent.payload.size());
    assertEquals("1234", devent.getField("bar"));
}
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)

Example 39 with DummpyMapEvent

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

the class MetadataSubstitutionTest method testIncludeMetadata.

@Test
public void testIncludeMetadata() throws FieldNotFoundException {
    ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
    substitutions.add(new MetadataSubstitution("foo", Arrays.asList("eventSha1Hash"), Collections.emptyList(), true));
    DummpyMapEvent devent = new DummpyMapEvent();
    InternalEvent ievent = new InternalEvent("", null, 10);
    ievent.setEventObj(devent);
    ievent.setEventTime(20);
    SubstitutionOperation op = new SubstitutionOperation(substitutions);
    op.perform(ievent);
    Map<String, Object> expected = new HashMap<String, Object>() {

        {
            put("eventSha1Hash", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
        }
    };
    assertEquals(expected, devent.getField("foo"));
}
Also used : MetadataSubstitution(com.nextdoor.bender.operation.substitution.metadata.MetadataSubstitution) MetadataSubstitution(com.nextdoor.bender.operation.substitution.metadata.MetadataSubstitution) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 40 with DummpyMapEvent

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

the class MetadataSubstitutionTest method testExcludeMetadata.

@Test
public void testExcludeMetadata() throws FieldNotFoundException {
    ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
    substitutions.add(new MetadataSubstitution("foo", Collections.emptyList(), Arrays.asList("sourceLagMs"), true));
    DummpyMapEvent devent = new DummpyMapEvent();
    InternalEvent ievent = new InternalEvent("", null, 10);
    ievent.setEventObj(devent);
    ievent.setEventTime(20);
    SubstitutionOperation op = new SubstitutionOperation(substitutions);
    op.perform(ievent);
    Map<String, Object> expected = new HashMap<String, Object>() {

        {
            put("arrivalEpochMs", new Long(10));
            put("eventSha1Hash", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
            put("eventEpochMs", new Long(20));
        }
    };
    assertEquals(expected, devent.getField("foo"));
}
Also used : MetadataSubstitution(com.nextdoor.bender.operation.substitution.metadata.MetadataSubstitution) MetadataSubstitution(com.nextdoor.bender.operation.substitution.metadata.MetadataSubstitution) HashMap(java.util.HashMap) 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