use of com.nextdoor.bender.operations.geo.GeoIpOperationTest.DummpyEvent 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();
DummpyEvent devent = new DummpyEvent();
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());
}
Aggregations