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"));
}
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());
}
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"));
}
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());
}
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);
}
Aggregations