use of com.nextdoor.bender.operation.substitution.regex.RegexSubstitutionConfig.RegexSubField in project bender by Nextdoor.
the class RegexSubstitutionTest method testRegexMultipleSources.
@Test
public void testRegexMultipleSources() throws FieldNotFoundException {
List<RegexSubField> regexSubFields = Arrays.asList(new RegexSubField("q", RegexSubField.RegexSubFieldType.STRING, "q"));
String pattern = "(?<q>(expectedstring))";
ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
substitutions.add(new RegexSubstitution(Arrays.asList("foo", "foo1", "foo2"), Pattern.compile(pattern), regexSubFields, false, true, true));
DummpyMapEvent devent = new DummpyMapEvent();
devent.setField("foo2", "expectedstring");
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
SubstitutionOperation op = new SubstitutionOperation(substitutions);
op.perform(ievent);
assertEquals(2, devent.payload.size());
assertEquals("expectedstring", devent.getField("foo2"));
assertEquals("expectedstring", devent.getField("q"));
}
use of com.nextdoor.bender.operation.substitution.regex.RegexSubstitutionConfig.RegexSubField in project bender by Nextdoor.
the class RegexSubstitutionTest method testRegexFieldCoercionNoFail.
@Test
public void testRegexFieldCoercionNoFail() throws FieldNotFoundException {
List<RegexSubField> regexSubFields = Arrays.asList(new RegexSubField("q", RegexSubField.RegexSubFieldType.NUMBER, "q"));
String pattern = "(?<q>(expectedstring))";
ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
substitutions.add(new RegexSubstitution(Arrays.asList("foo"), Pattern.compile(pattern), regexSubFields, false, false, true));
DummpyMapEvent devent = new DummpyMapEvent();
devent.setField("foo", "expectedstring");
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
SubstitutionOperation op = new SubstitutionOperation(substitutions);
op.perform(ievent);
assertEquals(1, devent.payload.size());
assertEquals("expectedstring", devent.getField("foo"));
}
Aggregations