Search in sources :

Example 6 with FormattedSubstitution

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

Example 7 with FormattedSubstitution

use of com.nextdoor.bender.operation.substitution.formatted.FormattedSubstitution in project bender by Nextdoor.

the class FormattedSubstitutionTest method testStringReplace.

@Test
public void testStringReplace() 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("foo", 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("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)7 FormattedSubstitution (com.nextdoor.bender.operation.substitution.formatted.FormattedSubstitution)7 DummpyMapEvent (com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent)7 ArrayList (java.util.ArrayList)7 ExtendedMessageFormat (org.apache.commons.text.ExtendedMessageFormat)7 Test (org.junit.Test)7