Search in sources :

Example 6 with DeserializationException

use of com.nextdoor.bender.deserializer.DeserializationException in project bender by Nextdoor.

the class BaseHandlerTest method testDeserializationException.

@Test
public void testDeserializationException() throws HandlerException {
    BaseHandler.CONFIG_FILE = "/config/handler_config.json";
    handler.skipWriteStats = true;
    List<DummyEvent> events = new ArrayList<DummyEvent>(1);
    events.add(new DummyEvent("foo", 0));
    TestContext context = new TestContext();
    context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag");
    handler.init(context);
    DeserializerProcessor proc = handler.sources.get(0).getDeserProcessor();
    Deserializer deserSpy = spy(proc.getDeserializer());
    doThrow(new DeserializationException("expected")).when(deserSpy).deserialize(anyString());
    proc.setDeserializer(deserSpy);
    handler.handler(events, context);
    assertEquals(1, proc.getErrorCountStat().getValue());
}
Also used : Deserializer(com.nextdoor.bender.deserializer.Deserializer) TestContext(com.nextdoor.bender.aws.TestContext) ArrayList(java.util.ArrayList) DeserializerProcessor(com.nextdoor.bender.deserializer.DeserializerProcessor) DeserializationException(com.nextdoor.bender.deserializer.DeserializationException) Test(org.junit.Test)

Aggregations

DeserializationException (com.nextdoor.bender.deserializer.DeserializationException)6 TestContext (com.nextdoor.bender.aws.TestContext)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Deserializer (com.nextdoor.bender.deserializer.Deserializer)2 DeserializerProcessor (com.nextdoor.bender.deserializer.DeserializerProcessor)2 HashMap (java.util.HashMap)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 Matcher (com.google.re2j.Matcher)1 FieldConfig (com.nextdoor.bender.deserializer.json.GenericJsonDeserializerConfig.FieldConfig)1 Serializer (com.nextdoor.bender.serializer.Serializer)1 Matcher (java.util.regex.Matcher)1