Search in sources :

Example 16 with DummpyMapEvent

use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent 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 17 with DummpyMapEvent

use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent 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 18 with DummpyMapEvent

use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent 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)

Example 19 with DummpyMapEvent

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

the class GeoIpOperationFactoryTest method testFactoryCreated.

@Test
public void testFactoryCreated() {
    GeoIpOperationConfig config = new GeoIpOperationConfig();
    config.setDstFieldName("test");
    config.setFailOnNotFound(false);
    config.setGeoLiteDb("s3://" + BUCKET + "/my-ip-data.mmdb");
    config.setSrcFieldName("ip_address");
    config.setGeoProperties(Arrays.asList(GeoProperty.COUNTRY_NAME, GeoProperty.COUNTRY_ISO_CODE, GeoProperty.SUBDIVISION_NAME, GeoProperty.SUBDIVISION_ISO_CODE, GeoProperty.CITY_NAME, GeoProperty.POSTAL_CODE, GeoProperty.LOCATION));
    this.opFactory.setConf(config);
    GeoIpOperation op = this.opFactory.newInstance();
    DummpyMapEvent devent = new DummpyMapEvent();
    devent.setField("ip_address", "5.5.5.5");
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    op.perform(ievent);
    HashMap<String, Object> expected = new HashMap<String, Object>();
    expected.put("ip_address", "5.5.5.5");
    HashMap<String, Object> expectedLoc = new HashMap<String, Object>();
    expectedLoc.put("lat", new Double("51.75"));
    expectedLoc.put("lon", new Double("2.25"));
    Map<String, Object> expectedGeo = new HashMap<String, Object>();
    expectedGeo.put("location", expectedLoc);
    expectedGeo.put("country_name", "Eriador");
    expectedGeo.put("country_iso_code", "ER");
    expectedGeo.put("subdivision_name", "Rivendell");
    expectedGeo.put("subdivision_iso_code", "ENG");
    expectedGeo.put("city_name", "Rivendell");
    expectedGeo.put("postal_code", "1234");
    expected.put("test", expectedGeo);
    assertEquals(expected, ievent.getEventObj().getPayload());
}
Also used : HashMap(java.util.HashMap) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 20 with DummpyMapEvent

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

the class GeoIpOperationTest method testUnkownIpPass.

@Test
public void testUnkownIpPass() throws Throwable {
    GeoIpOperation op = setup(Arrays.asList(GeoProperty.LOCATION), false);
    DummpyMapEvent devent = new DummpyMapEvent();
    devent.setField("ip_address", "10.0.0.1");
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    op.perform(ievent);
}
Also used : 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