You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/12/11 12:29:40 UTC

[camel] 02/02: CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-lambda

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 b862e018b25dff176048213f6a81209360919acd
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Dec 11 13:29:03 2019 +0100

    CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-lambda
---
 .../component/aws/lambda/LambdaComponent.java      | 35 ++++++++--------------
 .../lambda/LambdaComponentClientRegistryTest.java  |  4 +--
 .../lambda/LambdaComponentConfigurationTest.java   | 18 +++++------
 3 files changed, 24 insertions(+), 33 deletions(-)

diff --git a/components/camel-aws-lambda/src/main/java/org/apache/camel/component/aws/lambda/LambdaComponent.java b/components/camel-aws-lambda/src/main/java/org/apache/camel/component/aws/lambda/LambdaComponent.java
index 04d0b19..2d88ac9 100644
--- a/components/camel-aws-lambda/src/main/java/org/apache/camel/component/aws/lambda/LambdaComponent.java
+++ b/components/camel-aws-lambda/src/main/java/org/apache/camel/component/aws/lambda/LambdaComponent.java
@@ -25,7 +25,6 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.annotations.Component;
 import org.apache.camel.support.DefaultComponent;
-import org.apache.camel.util.ObjectHelper;
 
 @Component("aws-lambda")
 public class LambdaComponent extends DefaultComponent {
@@ -46,31 +45,23 @@ public class LambdaComponent extends DefaultComponent {
     public LambdaComponent(CamelContext context) {
         super(context);
         
-        this.configuration = new LambdaConfiguration();
         registerExtension(new LambdaComponentVerifierExtension());
     }
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
-        LambdaConfiguration configuration = this.configuration.copy();
-        setProperties(configuration, parameters);
+        LambdaConfiguration configuration = this.configuration != null ? this.configuration.copy() : new LambdaConfiguration();
         configuration.setFunction(remaining);
-
-        if (ObjectHelper.isEmpty(configuration.getAccessKey())) {
-            setAccessKey(accessKey);
-        }
-        if (ObjectHelper.isEmpty(configuration.getSecretKey())) {
-            setSecretKey(secretKey);
-        }
-        if (ObjectHelper.isEmpty(configuration.getRegion())) {
-            setRegion(region);
-        }
+        LambdaEndpoint endpoint = new LambdaEndpoint(uri, this, configuration);
+        endpoint.getConfiguration().setAccessKey(accessKey);
+        endpoint.getConfiguration().setSecretKey(secretKey);
+        endpoint.getConfiguration().setRegion(region);
+        setProperties(endpoint, parameters);
         checkAndSetRegistryClient(configuration);
-        if (ObjectHelper.isEmpty(configuration.getAwsLambdaClient()) && (ObjectHelper.isEmpty(configuration.getAccessKey()) || ObjectHelper.isEmpty(configuration.getSecretKey()))) {
+        if (configuration.getAwsLambdaClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
             throw new IllegalArgumentException("accessKey/secretKey or awsLambdaClient must be specified");
         }
 
-        LambdaEndpoint endpoint = new LambdaEndpoint(uri, this, configuration);
         return endpoint;
     }
     
@@ -86,36 +77,36 @@ public class LambdaComponent extends DefaultComponent {
     }
 
     public String getAccessKey() {
-        return configuration.getAccessKey();
+        return accessKey;
     }
 
     /**
      * Amazon AWS Access Key
      */
     public void setAccessKey(String accessKey) {
-        configuration.setAccessKey(accessKey);
+        this.accessKey = accessKey;
     }
 
     public String getSecretKey() {
-        return configuration.getSecretKey();
+        return secretKey;
     }
 
     /**
      * Amazon AWS Secret Key
      */
     public void setSecretKey(String secretKey) {
-        configuration.setSecretKey(secretKey);
+        this.secretKey = secretKey;
     }
 
     public String getRegion() {
-        return configuration.getRegion();
+        return region;
     }
 
     /**
      * Amazon AWS Region
      */
     public void setRegion(String region) {
-        configuration.setRegion(region);
+        this.region = region;
     }
     
     private void checkAndSetRegistryClient(LambdaConfiguration configuration) {
diff --git a/components/camel-aws-lambda/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentClientRegistryTest.java b/components/camel-aws-lambda/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentClientRegistryTest.java
index 1fb30be..573aa3b 100644
--- a/components/camel-aws-lambda/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentClientRegistryTest.java
+++ b/components/camel-aws-lambda/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentClientRegistryTest.java
@@ -30,7 +30,7 @@ public class LambdaComponentClientRegistryTest extends CamelTestSupport {
 
         AWSLambdaClient awsLambdaClient = mock(AWSLambdaClient.class);
         context.getRegistry().bind("awsLambdaClient", awsLambdaClient);
-        LambdaComponent component = new LambdaComponent(context);
+        LambdaComponent component = context.getComponent("aws-lambda", LambdaComponent.class);
         LambdaEndpoint endpoint = (LambdaEndpoint) component.createEndpoint(
                 "aws-lambda://myFunction?operation=getFunction&awsLambdaClient=#awsLambdaClient&accessKey=xxx&secretKey=yyy");
 
@@ -40,7 +40,7 @@ public class LambdaComponentClientRegistryTest extends CamelTestSupport {
     @Test(expected = PropertyBindingException.class)
     public void createEndpointWithMinimalKMSClientMisconfiguration() throws Exception {
 
-        LambdaComponent component = new LambdaComponent(context);
+        LambdaComponent component = context.getComponent("aws-lambda", LambdaComponent.class);
         LambdaEndpoint endpoint = (LambdaEndpoint) component.createEndpoint(
                 "aws-lambda://myFunction?operation=getFunction&awsLambdaClient=#awsLambdaClient&accessKey=xxx&secretKey=yyy");
     }
diff --git a/components/camel-aws-lambda/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentConfigurationTest.java b/components/camel-aws-lambda/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentConfigurationTest.java
index 0c0112b..bf7fec8 100644
--- a/components/camel-aws-lambda/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentConfigurationTest.java
+++ b/components/camel-aws-lambda/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentConfigurationTest.java
@@ -30,7 +30,7 @@ public class LambdaComponentConfigurationTest extends CamelTestSupport {
     public void createEndpointWithMinimalConfiguration() throws Exception {
         AWSLambdaClient awsLambdaClient = mock(AWSLambdaClient.class);
         context.getRegistry().bind("awsLambdaClient", awsLambdaClient);
-        LambdaComponent component = new LambdaComponent(context);
+        LambdaComponent component = context.getComponent("aws-lambda", LambdaComponent.class);
         LambdaEndpoint endpoint = (LambdaEndpoint) component.createEndpoint(
             "aws-lambda://myFunction?operation=getFunction&awsLambdaClient=#awsLambdaClient&accessKey=xxx&secretKey=yyy");
 
@@ -41,25 +41,25 @@ public class LambdaComponentConfigurationTest extends CamelTestSupport {
 
     @Test(expected = IllegalArgumentException.class)
     public void createEndpointWithoutOperation() throws Exception {
-        LambdaComponent component = new LambdaComponent(context);
+        LambdaComponent component = context.getComponent("aws-lambda", LambdaComponent.class);
         component.createEndpoint("aws-lambda://myFunction");
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void createEndpointWithoutAmazonLambdaClientConfiguration() throws Exception {
-        LambdaComponent component = new LambdaComponent(context);
+        LambdaComponent component = context.getComponent("aws-lambda", LambdaComponent.class);
         component.createEndpoint("aws-lambda://myFunction?operation=getFunction");
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void createEndpointWithoutAccessKeyConfiguration() throws Exception {
-        LambdaComponent component = new LambdaComponent(context);
+        LambdaComponent component = context.getComponent("aws-lambda", LambdaComponent.class);
         component.createEndpoint("aws-lambda://myFunction?operation=getFunction&secretKey=yyy");
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void createEndpointWithoutSecretKeyConfiguration() throws Exception {
-        LambdaComponent component = new LambdaComponent(context);
+        LambdaComponent component = context.getComponent("aws-lambda", LambdaComponent.class);
         component.createEndpoint("aws-lambda://myFunction?operation=getFunction&accessKey=xxx");
     }
 
@@ -67,13 +67,13 @@ public class LambdaComponentConfigurationTest extends CamelTestSupport {
     public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception {
         AWSLambdaClient awsLambdaClient = mock(AWSLambdaClient.class);
         context.getRegistry().bind("awsLambdaClient", awsLambdaClient);
-        LambdaComponent component = new LambdaComponent(context);
+        LambdaComponent component = context.getComponent("aws-lambda", LambdaComponent.class);
         component.createEndpoint("aws-lambda://myFunction?operation=getFunction&awsLambdaClient=#awsLambdaClient");
     }
     
     @Test
     public void createEndpointWithComponentElements() throws Exception {
-        LambdaComponent component = new LambdaComponent(context);
+        LambdaComponent component = context.getComponent("aws-lambda", LambdaComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         LambdaEndpoint endpoint = (LambdaEndpoint)component.createEndpoint("aws-lambda://myFunction");
@@ -85,7 +85,7 @@ public class LambdaComponentConfigurationTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithComponentAndEndpointElements() throws Exception {
-        LambdaComponent component = new LambdaComponent(context);
+        LambdaComponent component = context.getComponent("aws-lambda", LambdaComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         component.setRegion(Regions.US_WEST_1.toString());
@@ -99,7 +99,7 @@ public class LambdaComponentConfigurationTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithComponentEndpointElementsAndProxy() throws Exception {
-        LambdaComponent component = new LambdaComponent(context);
+        LambdaComponent component = context.getComponent("aws-lambda", LambdaComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         component.setRegion(Regions.US_WEST_1.toString());