Search in sources :

Example 1 with FieldSubstitution

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

Example 2 with FieldSubstitution

use of com.nextdoor.bender.operation.substitution.field.FieldSubstitution in project bender by Nextdoor.

the class FieldSubstitutionTest method testUnknownField.

public void testUnknownField() {
    ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
    substitutions.add(new FieldSubstitution("bar", Arrays.asList("foo"), false, false, true));
    DummpyMapEvent devent = new DummpyMapEvent();
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    SubstitutionOperation op = new SubstitutionOperation(substitutions);
    op.perform(ievent);
}
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)

Example 3 with FieldSubstitution

use of com.nextdoor.bender.operation.substitution.field.FieldSubstitution in project bender by Nextdoor.

the class FieldSubstitutionTest method testUnknownFieldFail.

@Test(expected = OperationException.class)
public void testUnknownFieldFail() {
    ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
    substitutions.add(new FieldSubstitution("bar", Arrays.asList("foo"), false, true, true));
    DummpyMapEvent devent = new DummpyMapEvent();
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    SubstitutionOperation op = new SubstitutionOperation(substitutions);
    op.perform(ievent);
}
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 4 with FieldSubstitution

use of com.nextdoor.bender.operation.substitution.field.FieldSubstitution in project bender by Nextdoor.

the class FieldSubstitutionTest method testRemoveFieldReplace.

@Test
public void testRemoveFieldReplace() throws FieldNotFoundException {
    ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
    substitutions.add(new FieldSubstitution("foo", 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("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)

Example 5 with FieldSubstitution

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

Aggregations

InternalEvent (com.nextdoor.bender.InternalEvent)6 FieldSubstitution (com.nextdoor.bender.operation.substitution.field.FieldSubstitution)6 DummpyMapEvent (com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5