Search in sources :

Example 1 with SQSEvent

use of com.amazonaws.services.lambda.runtime.events.SQSEvent in project aws-doc-sdk-examples by awsdocs.

the class SQSEventDeserializer method deserialize.

@Override
public SQSEvent deserialize(JsonElement eventJson, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    SQSEvent event = new SQSEvent();
    logger.info("DESERIALIZING TEST EVENT");
    logger.info("EVENT JSON: " + eventJson.toString());
    // Records key is capitalized in test event, but lowercase in type
    JsonArray recordsArray = eventJson.getAsJsonObject().get("Records").getAsJsonArray();
    ArrayList<SQSMessage> records = gson.fromJson(recordsArray, sqsMessageArray);
    event.setRecords(records);
    return event;
}
Also used : JsonArray(com.google.gson.JsonArray) SQSEvent(com.amazonaws.services.lambda.runtime.events.SQSEvent) SQSMessage(com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage)

Example 2 with SQSEvent

use of com.amazonaws.services.lambda.runtime.events.SQSEvent in project aws-doc-sdk-examples by awsdocs.

the class InvokeTest method invokeTest.

@Test
void invokeTest() {
    AWSXRay.beginSegment("blank-java-test");
    String path = "src/test/resources/event.json";
    String eventString = loadJsonFile(path);
    SQSEvent event = gson.fromJson(eventString, SQSEvent.class);
    Context context = new TestContext();
    String requestId = context.getAwsRequestId();
    Handler handler = new Handler();
    String result = handler.handleRequest(event, context);
    assertTrue(result.contains("totalCodeSize"));
    AWSXRay.endSegment();
}
Also used : Context(com.amazonaws.services.lambda.runtime.Context) SQSEvent(com.amazonaws.services.lambda.runtime.events.SQSEvent) RequestHandler(com.amazonaws.services.lambda.runtime.RequestHandler) Test(org.junit.jupiter.api.Test)

Aggregations

SQSEvent (com.amazonaws.services.lambda.runtime.events.SQSEvent)2 Context (com.amazonaws.services.lambda.runtime.Context)1 RequestHandler (com.amazonaws.services.lambda.runtime.RequestHandler)1 SQSMessage (com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage)1 JsonArray (com.google.gson.JsonArray)1 Test (org.junit.jupiter.api.Test)1