Search in sources :

Example 6 with OperationException

use of com.nextdoor.bender.operation.OperationException in project bender by Nextdoor.

the class JsonRootNodeOperation method mutateEvent.

/**
 * The {@link DeserializedEvent} payload must be a {@link JsonObject}.
 *
 * @param event Event with payload to mutate.
 */
protected void mutateEvent(DeserializedEvent event) throws OperationException {
    Object payload = event.getPayload();
    if (payload == null) {
        return;
    }
    if (!(payload instanceof JsonObject)) {
        throw new OperationException("Payload data is not a JsonObject");
    }
    JsonObject jsonPayload = (JsonObject) payload;
    event.setPayload(JsonPathProvider.read(jsonPayload, path));
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) OperationException(com.nextdoor.bender.operation.OperationException)

Example 7 with OperationException

use of com.nextdoor.bender.operation.OperationException in project bender by Nextdoor.

the class GeoIpOperationTest method testUnkownIpRequired.

@Test(expected = AddressNotFoundException.class)
public void testUnkownIpRequired() throws Throwable {
    GeoIpOperation op = setup(Arrays.asList(GeoProperty.LOCATION), true);
    DummpyEvent devent = new DummpyEvent();
    devent.setField("ip_address", "10.0.0.1");
    InternalEvent ievent = new InternalEvent("", null, 0);
    ievent.setEventObj(devent);
    try {
        op.perform(ievent);
    } catch (OperationException e) {
        throw e.getCause();
    }
}
Also used : OperationException(com.nextdoor.bender.operation.OperationException) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Aggregations

OperationException (com.nextdoor.bender.operation.OperationException)7 JsonObject (com.google.gson.JsonObject)3 Test (org.junit.Test)3 InternalEvent (com.nextdoor.bender.InternalEvent)2 DeserializedEvent (com.nextdoor.bender.deserializer.DeserializedEvent)2 JsonElement (com.google.gson.JsonElement)1 GeoIp2Exception (com.maxmind.geoip2.exception.GeoIp2Exception)1 CityResponse (com.maxmind.geoip2.model.CityResponse)1 TestContext (com.nextdoor.bender.aws.TestContext)1 BaseOperation (com.nextdoor.bender.operation.BaseOperation)1 OperationProcessor (com.nextdoor.bender.operation.OperationProcessor)1 GeoProperty (com.nextdoor.bender.operations.geo.GeoIpOperationConfig.GeoProperty)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1 NoSuchElementException (java.util.NoSuchElementException)1