Search in sources :

Example 1 with RegexSubField

use of com.nextdoor.bender.operation.substitution.regex.RegexSubstitutionConfig.RegexSubField in project bender by Nextdoor.

the class RegexSubstitutionTest method testRegexRemoveField.

// TODO: do this somewhere else
// @Test(expected = java.util.regex.PatternSyntaxException.class)
// public void testInvalidRegex() {
// String pattern = "(?q>(expectedstring))";
// new RegexSubSpecConfig(Arrays.asList("foo"), pattern, null, false, true, true);
// }
@Test
public void testRegexRemoveField() 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"), Pattern.compile(pattern), regexSubFields, true, true, 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("q"));
}
Also used : RegexSubField(com.nextdoor.bender.operation.substitution.regex.RegexSubstitutionConfig.RegexSubField) RegexSubstitution(com.nextdoor.bender.operation.substitution.regex.RegexSubstitution) RegexSubstitution(com.nextdoor.bender.operation.substitution.regex.RegexSubstitution) ArrayList(java.util.ArrayList) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 2 with RegexSubField

use of com.nextdoor.bender.operation.substitution.regex.RegexSubstitutionConfig.RegexSubField in project bender by Nextdoor.

the class RegexSubstitutionTest method testRegexFieldCoercionRemove.

@Test
public void testRegexFieldCoercionRemove() 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, true, 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"));
}
Also used : RegexSubField(com.nextdoor.bender.operation.substitution.regex.RegexSubstitutionConfig.RegexSubField) RegexSubstitution(com.nextdoor.bender.operation.substitution.regex.RegexSubstitution) RegexSubstitution(com.nextdoor.bender.operation.substitution.regex.RegexSubstitution) ArrayList(java.util.ArrayList) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 3 with RegexSubField

use of com.nextdoor.bender.operation.substitution.regex.RegexSubstitutionConfig.RegexSubField in project bender by Nextdoor.

the class RegexSubstitutionTest method testRegexRemoveFieldReplace.

@Test
public void testRegexRemoveFieldReplace() throws FieldNotFoundException {
    List<RegexSubField> regexSubFields = Arrays.asList(new RegexSubField("foo", RegexSubField.RegexSubFieldType.STRING, "foo"));
    String pattern = "(?<foo>(expectedstring))";
    ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
    substitutions.add(new RegexSubstitution(Arrays.asList("foo"), Pattern.compile(pattern), regexSubFields, true, true, 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"));
}
Also used : RegexSubField(com.nextdoor.bender.operation.substitution.regex.RegexSubstitutionConfig.RegexSubField) RegexSubstitution(com.nextdoor.bender.operation.substitution.regex.RegexSubstitution) RegexSubstitution(com.nextdoor.bender.operation.substitution.regex.RegexSubstitution) ArrayList(java.util.ArrayList) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 4 with RegexSubField

use of com.nextdoor.bender.operation.substitution.regex.RegexSubstitutionConfig.RegexSubField in project bender by Nextdoor.

the class RegexSubstitutionTest method testRegexSrcNotFoundRemove.

@Test
public void testRegexSrcNotFoundRemove() throws FieldNotFoundException {
    List<RegexSubField> regexSubFields = Arrays.asList(new RegexSubField("q", RegexSubField.RegexSubFieldType.STRING, "q"));
    String pattern = "(?<q>(\\d+))";
    ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
    substitutions.add(new RegexSubstitution(Arrays.asList("foo", "foo1"), Pattern.compile(pattern), regexSubFields, false, false, true));
    DummpyMapEvent devent = new DummpyMapEvent();
    devent.setField("foo", "aaa");
    devent.setField("foo1", "bbb");
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    SubstitutionOperation op = new SubstitutionOperation(substitutions);
    op.perform(ievent);
    assertEquals(2, devent.payload.size());
}
Also used : RegexSubField(com.nextdoor.bender.operation.substitution.regex.RegexSubstitutionConfig.RegexSubField) RegexSubstitution(com.nextdoor.bender.operation.substitution.regex.RegexSubstitution) RegexSubstitution(com.nextdoor.bender.operation.substitution.regex.RegexSubstitution) ArrayList(java.util.ArrayList) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 5 with RegexSubField

use of com.nextdoor.bender.operation.substitution.regex.RegexSubstitutionConfig.RegexSubField in project bender by Nextdoor.

the class RegexSubstitutionTest method testNonMatchingRegex.

@Test
public void testNonMatchingRegex() 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"), Pattern.compile(pattern), regexSubFields, false, false, true));
    DummpyMapEvent devent = new DummpyMapEvent();
    devent.setField("foo", "actualstring");
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    SubstitutionOperation op = new SubstitutionOperation(substitutions);
    op.perform(ievent);
    /*
     * Original field should still be there
     */
    assertEquals(1, devent.payload.size());
    assertEquals("actualstring", devent.getField("foo"));
}
Also used : RegexSubField(com.nextdoor.bender.operation.substitution.regex.RegexSubstitutionConfig.RegexSubField) RegexSubstitution(com.nextdoor.bender.operation.substitution.regex.RegexSubstitution) RegexSubstitution(com.nextdoor.bender.operation.substitution.regex.RegexSubstitution) ArrayList(java.util.ArrayList) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Aggregations

RegexSubField (com.nextdoor.bender.operation.substitution.regex.RegexSubstitutionConfig.RegexSubField)12 InternalEvent (com.nextdoor.bender.InternalEvent)11 RegexSubstitution (com.nextdoor.bender.operation.substitution.regex.RegexSubstitution)11 DummpyMapEvent (com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent)11 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 FieldNotFoundException (com.nextdoor.bender.deserializer.FieldNotFoundException)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1