Search in sources :

Example 21 with DummpyMapEvent

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());
}
Also used : HashMap(java.util.HashMap) DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 22 with DummpyMapEvent

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();
    }
}
Also used : DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) OperationException(com.nextdoor.bender.operation.OperationException) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 23 with DummpyMapEvent

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);
}
Also used : DummpyMapEvent(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 24 with DummpyMapEvent

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);
}
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 25 with DummpyMapEvent

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);
}
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

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