MessageProcessorProxy { public SQSMessageProcessorResponse invoke(final SQSMessageProcessorRequest request) throws MessageProcessorException { log.info("Invoking message processor lambda to process {} messages", request.getMessages().size()); String requestPayload = GSON.toJson(request); InvokeRequest invokeRequest = new InvokeRequest() .withFunctionName(messageProcessorFunctionName) .withInvocationType(InvocationType.RequestResponse) .withPayload(requestPayload); InvokeResult result = lambda.invoke(invokeRequest); if (result.getFunctionError() != null) { throw new MessageProcessorException(result); } return GSON.fromJson(LambdaUtil.getPayloadAsString(result), SQSMessageProcessorResponse.class); }  SQSMessageProcessorResponse invoke(final SQSMessageProcessorRequest request);  }
@Test public void invoke() throws Exception { SQSMessageProcessorRequest sqsMessageProcessorRequest = new SQSMessageProcessorRequest(); sqsMessageProcessorRequest.setMessages(MESSAGES); ByteBuffer byteBuffer = ByteBuffer.wrap("{\"key1\":value1,\"key2\":value2}".getBytes()); InvokeResult invokeResult = mock(InvokeResult.class); when(invokeResult.getPayload()).thenReturn(byteBuffer); when(lambda.invoke(any(InvokeRequest.class))).thenReturn(invokeResult); messageProcessorProxy.invoke(sqsMessageProcessorRequest); }
@Test(expected = MessageProcessorException.class) public void invoke_functionError() throws Exception { SQSMessageProcessorRequest sqsMessageProcessorRequest = new SQSMessageProcessorRequest(); sqsMessageProcessorRequest.setMessages(MESSAGES); InvokeResult invokeResult = mock(InvokeResult.class); when(invokeResult.getFunctionError()).thenReturn("Unhandled"); when(lambda.invoke(any(InvokeRequest.class))).thenReturn(invokeResult); messageProcessorProxy.invoke(sqsMessageProcessorRequest); }