Search in sources :

Example 21 with DeserializedEvent

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

the class GenericJsonDeserializerTest method testEmptyBrace.

@Test
public void testEmptyBrace() throws UnsupportedEncodingException, IOException {
    DeserializedEvent devent = getEvent("nested_brace.json");
    JsonObject obj = (JsonObject) devent.getPayload();
    /*
     * Verify nested parser does not break when there is just a single {
     */
    assertTrue(obj.has("MESSAGE"));
    assertTrue(obj.get("MESSAGE").isJsonPrimitive());
    assertTrue(obj.get("MESSAGE").getAsJsonPrimitive().isString());
    assertEquals("{", obj.get("MESSAGE").getAsString());
}
Also used : DeserializedEvent(com.nextdoor.bender.deserializer.DeserializedEvent) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test)

Example 22 with DeserializedEvent

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

the class GenericJsonDeserializerTest method testRootNodeChange.

@Test
public void testRootNodeChange() throws UnsupportedEncodingException, IOException {
    DeserializedEvent devent = getEvent("nested.json", "$.MESSAGE");
    JsonObject obj = (JsonObject) devent.getPayload();
    /*
     * Check members of MESSAGE object
     */
    assertTrue(obj.has("a_string"));
    assertTrue(obj.has("an_obj"));
    assertTrue(obj.get("an_obj").isJsonObject());
    /*
     * Verify sub nested json was also converted
     */
    obj = obj.get("an_obj").getAsJsonObject();
    assertTrue(obj.has("a_num"));
    assertEquals(123, obj.get("a_num").getAsInt());
}
Also used : DeserializedEvent(com.nextdoor.bender.deserializer.DeserializedEvent) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test)

Example 23 with DeserializedEvent

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

the class GenericJsonDeserializerTest method testNestedOffsetJson.

@Test
public void testNestedOffsetJson() throws UnsupportedEncodingException, IOException {
    DeserializedEvent devent = getEvent("nested_offset.json");
    JsonObject obj = (JsonObject) devent.getPayload();
    /*
     * Verify that nested string json is found when there is an offset
     */
    assertTrue(obj.has("MESSAGE"));
    assertTrue(obj.get("MESSAGE").isJsonObject());
    JsonObject nested = obj.get("MESSAGE").getAsJsonObject();
    assertTrue(nested.has("a_string"));
}
Also used : DeserializedEvent(com.nextdoor.bender.deserializer.DeserializedEvent) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test)

Aggregations

DeserializedEvent (com.nextdoor.bender.deserializer.DeserializedEvent)23 Test (org.junit.Test)20 JsonObject (com.google.gson.JsonObject)11 ArrayList (java.util.ArrayList)7 Pattern (java.util.regex.Pattern)4 Pattern (com.google.re2j.Pattern)3 OperationException (com.nextdoor.bender.operation.OperationException)2 Context (com.amazonaws.services.lambda.runtime.Context)1 AmazonS3URI (com.amazonaws.services.s3.AmazonS3URI)1 JsonElement (com.google.gson.JsonElement)1 InternalEvent (com.nextdoor.bender.InternalEvent)1 AmazonS3ClientFactory (com.nextdoor.bender.aws.AmazonS3ClientFactory)1 BenderConfig (com.nextdoor.bender.config.BenderConfig)1 ConfigurationException (com.nextdoor.bender.config.ConfigurationException)1 HandlerResources (com.nextdoor.bender.config.HandlerResources)1 Source (com.nextdoor.bender.config.Source)1 DeserializerProcessor (com.nextdoor.bender.deserializer.DeserializerProcessor)1 IpcSenderService (com.nextdoor.bender.ipc.IpcSenderService)1 TransportException (com.nextdoor.bender.ipc.TransportException)1 BenderLayout (com.nextdoor.bender.logging.BenderLayout)1