This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 6d06bec732a31ef46bb6598f9d06400cb800b880 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Tue Oct 16 14:15:27 2018 +0200 CAMEL-12884 - Camel-AWS Lambda: Add support for event source mapping, fixed CS --- .../camel/component/aws/lambda/LambdaProducer.java | 22 ++++---- .../component/aws/lambda/LambdaProducerTest.java | 62 ++++++++-------------- 2 files changed, 34 insertions(+), 50 deletions(-) diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaProducer.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaProducer.java index d52a7c3..8760592 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaProducer.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaProducer.java @@ -16,8 +16,6 @@ */ package org.apache.camel.component.aws.lambda; -import static org.apache.camel.component.aws.common.AwsExchangeUtil.getMessageForResponse; - import java.io.File; import java.io.FileInputStream; import java.nio.ByteBuffer; @@ -25,15 +23,6 @@ import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; -import org.apache.camel.Endpoint; -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.impl.DefaultProducer; -import org.apache.camel.util.CastUtils; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.amazonaws.AmazonServiceException; import com.amazonaws.services.lambda.AWSLambda; import com.amazonaws.services.lambda.model.CreateEventSourceMappingRequest; @@ -56,6 +45,17 @@ import com.amazonaws.services.lambda.model.UpdateFunctionCodeResult; import com.amazonaws.services.lambda.model.VpcConfig; import com.amazonaws.util.IOUtils; +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.impl.DefaultProducer; +import org.apache.camel.util.CastUtils; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.camel.component.aws.common.AwsExchangeUtil.getMessageForResponse; + /** * A Producer which sends messages to the Amazon Web Service Lambda <a * href="https://aws.amazon.com/lambda/">AWS Lambda</a> diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaProducerTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaProducerTest.java index 590ad59..32c9896 100644 --- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaProducerTest.java +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaProducerTest.java @@ -16,7 +16,8 @@ */ package org.apache.camel.component.aws.lambda; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; import com.amazonaws.services.lambda.model.CreateEventSourceMappingResult; import com.amazonaws.services.lambda.model.CreateFunctionResult; @@ -25,6 +26,7 @@ import com.amazonaws.services.lambda.model.GetFunctionResult; import com.amazonaws.services.lambda.model.ListFunctionsResult; import com.amazonaws.services.lambda.model.UpdateFunctionCodeResult; import com.amazonaws.util.IOUtils; + import org.apache.camel.EndpointInject; import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; @@ -60,13 +62,13 @@ public class LambdaProducerTest extends CamelTestSupport { assertMockEndpointsSatisfied(); - CreateFunctionResult result = (CreateFunctionResult) exchange.getIn().getBody(); + CreateFunctionResult result = (CreateFunctionResult)exchange.getIn().getBody(); assertEquals(result.getFunctionName(), "GetHelloWithName"); assertEquals(result.getDescription(), "Hello with node.js on Lambda"); assertNotNull(result.getFunctionArn()); assertNotNull(result.getCodeSha256()); } - + @Test public void lambdaUpdateFunctionTest() throws Exception { @@ -87,7 +89,7 @@ public class LambdaProducerTest extends CamelTestSupport { assertMockEndpointsSatisfied(); - UpdateFunctionCodeResult result = (UpdateFunctionCodeResult) exchange.getIn().getBody(); + UpdateFunctionCodeResult result = (UpdateFunctionCodeResult)exchange.getIn().getBody(); assertEquals(result.getFunctionName(), "GetHelloWithName"); assertNotNull(result.getFunctionArn()); assertNotNull(result.getCodeSha256()); @@ -107,7 +109,6 @@ public class LambdaProducerTest extends CamelTestSupport { assertNotNull(exchange.getOut().getBody(DeleteFunctionResult.class)); } - @Test public void lambdaGetFunctionTest() throws Exception { @@ -119,11 +120,10 @@ public class LambdaProducerTest extends CamelTestSupport { }); assertMockEndpointsSatisfied(); - GetFunctionResult result = (GetFunctionResult) exchange.getOut().getBody(); + GetFunctionResult result = (GetFunctionResult)exchange.getOut().getBody(); assertEquals(result.getConfiguration().getFunctionName(), "GetHelloWithName"); } - @Test public void lambdaListFunctionsTest() throws Exception { @@ -135,12 +135,11 @@ public class LambdaProducerTest extends CamelTestSupport { }); assertMockEndpointsSatisfied(); - ListFunctionsResult result = (ListFunctionsResult) exchange.getOut().getBody(); + ListFunctionsResult result = (ListFunctionsResult)exchange.getOut().getBody(); assertEquals(result.getFunctions().size(), 1); assertEquals(result.getFunctions().get(0).getFunctionName(), "GetHelloWithName"); } - @Test public void lambdaInvokeFunctionTest() throws Exception { Exchange exchange = template.send("direct:invokeFunction", ExchangePattern.InOut, new Processor() { @@ -154,7 +153,7 @@ public class LambdaProducerTest extends CamelTestSupport { assertNotNull(exchange.getOut().getBody(String.class)); assertEquals(exchange.getOut().getBody(String.class), "{\"Hello\":\"Camel\"}"); } - + @Test public void lambdaCreateEventSourceMappingTest() throws Exception { Exchange exchange = template.send("direct:createEventSourceMapping", ExchangePattern.InOut, new Processor() { @@ -170,7 +169,6 @@ public class LambdaProducerTest extends CamelTestSupport { assertEquals(result.getFunctionArn(), "arn:aws:lambda:eu-central-1:643534317684:function:GetHelloWithName"); } - @Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry registry = super.createRegistry(); @@ -187,34 +185,20 @@ public class LambdaProducerTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() throws Exception { - from("direct:createFunction") - .to("aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=createFunction") - .to("mock:result"); - - from("direct:getFunction") - .to("aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=getFunction") - .to("mock:result"); - - from("direct:listFunctions") - .to("aws-lambda://myFunction?awsLambdaClient=#awsLambdaClient&operation=listFunctions") - .to("mock:result"); - - from("direct:invokeFunction") - .to("aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=invokeFunction") - .to("mock:result"); - - from("direct:deleteFunction") - .to("aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=deleteFunction") - .to("mock:result"); - - from("direct:updateFunction") - .to("aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=updateFunction") - .to("mock:result"); - - from("direct:createEventSourceMapping") - .to("aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=createEventSourceMapping") - .to("mock:result"); + from("direct:createFunction").to("aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=createFunction").to("mock:result"); + + from("direct:getFunction").to("aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=getFunction").to("mock:result"); + + from("direct:listFunctions").to("aws-lambda://myFunction?awsLambdaClient=#awsLambdaClient&operation=listFunctions").to("mock:result"); + + from("direct:invokeFunction").to("aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=invokeFunction").to("mock:result"); + + from("direct:deleteFunction").to("aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=deleteFunction").to("mock:result"); + + from("direct:updateFunction").to("aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=updateFunction").to("mock:result"); + + from("direct:createEventSourceMapping").to("aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=createEventSourceMapping").to("mock:result"); } }; } -} \ No newline at end of file +}