use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent in project bender by Nextdoor.
the class GeoIpOperationTest method testKnownIpLocation.
@Test
public void testKnownIpLocation() throws Throwable {
GeoIpOperation op = setup(Arrays.asList(GeoProperty.LOCATION), true);
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);
expected.put("geo_ip", expectedGeo);
assertEquals(expected, ievent.getEventObj().getPayload());
}
use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent in project bender by Nextdoor.
the class GeoIpOperationTest method testInvalidIpRequired.
@Test(expected = UnknownHostException.class)
public void testInvalidIpRequired() throws Throwable {
GeoIpOperation op = setup(Arrays.asList(GeoProperty.LOCATION), true);
DummpyMapEvent devent = new DummpyMapEvent();
devent.setField("ip_address", "noanip");
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
try {
op.perform(ievent);
} catch (OperationException e) {
throw e.getCause();
}
}
use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent in project bender by Nextdoor.
the class GeoIpOperationTest method testMissingField.
@Test(expected = OperationException.class)
public void testMissingField() throws Throwable {
GeoIpOperation op = setup(Arrays.asList(GeoProperty.LOCATION), true);
DummpyMapEvent devent = spy(new DummpyMapEvent());
doThrow(FieldNotFoundException.class).when(devent).getFieldAsString("ip_address");
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
op.perform(ievent);
}
use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent in project bender by Nextdoor.
the class RegexSubstitutionTest method testRegexSrcNotFoundFail.
@Test(expected = OperationException.class)
public void testRegexSrcNotFoundFail() 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, true, 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);
}
use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent in project bender by Nextdoor.
the class RegexSubstitutionTest method testRegexFieldCoercionSrcNotFound.
@Test(expected = OperationException.class)
public void testRegexFieldCoercionSrcNotFound() 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, 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);
}
Aggregations