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
The following commit(s) were added to refs/heads/master by this push: new fc30420 CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-ec2 fc30420 is described below commit fc304201bec5bba3e97405cee47ed252a6c17892 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Wed Dec 11 11:49:48 2019 +0100 CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-ec2 --- .../camel/component/aws/ec2/EC2Component.java | 32 ++++++++-------------- .../aws/ec2/EC2ComponentClientRegistryTest.java | 4 +-- .../aws/ec2/EC2ComponentConfigurationTest.java | 20 +++++++------- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/components/camel-aws-ec2/src/main/java/org/apache/camel/component/aws/ec2/EC2Component.java b/components/camel-aws-ec2/src/main/java/org/apache/camel/component/aws/ec2/EC2Component.java index b5c060d..f57d97f 100644 --- a/components/camel-aws-ec2/src/main/java/org/apache/camel/component/aws/ec2/EC2Component.java +++ b/components/camel-aws-ec2/src/main/java/org/apache/camel/component/aws/ec2/EC2Component.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; /** * For working with Amazon's Elastic Compute Cloud (EC2). @@ -49,30 +48,23 @@ public class EC2Component extends DefaultComponent { public EC2Component(CamelContext context) { super(context); - this.configuration = new EC2Configuration(); registerExtension(new EC2ComponentVerifierExtension()); } @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { - EC2Configuration configuration = this.configuration.copy(); - setProperties(configuration, parameters); - if (ObjectHelper.isEmpty(configuration.getAccessKey())) { - setAccessKey(accessKey); - } - if (ObjectHelper.isEmpty(configuration.getSecretKey())) { - setSecretKey(secretKey); - } - if (ObjectHelper.isEmpty(configuration.getRegion())) { - setRegion(region); - } + EC2Configuration configuration = this.configuration != null ? this.configuration.copy() : new EC2Configuration(); + EC2Endpoint endpoint = new EC2Endpoint(uri, this, configuration); + endpoint.getConfiguration().setAccessKey(accessKey); + endpoint.getConfiguration().setSecretKey(secretKey); + endpoint.getConfiguration().setRegion(region); + setProperties(endpoint, parameters); checkAndSetRegistryClient(configuration); if (configuration.getAmazonEc2Client() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("amazonEC2Client or accessKey and secretKey must be specified"); } - EC2Endpoint endpoint = new EC2Endpoint(uri, this, configuration); return endpoint; } @@ -91,33 +83,33 @@ public class EC2Component extends DefaultComponent { * The region in which EC2 client needs to work */ public String getRegion() { - return configuration.getRegion(); + return region; } public void setRegion(String region) { - configuration.setRegion(region); + this.region = region; } 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; } private void checkAndSetRegistryClient(EC2Configuration configuration) { diff --git a/components/camel-aws-ec2/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentClientRegistryTest.java b/components/camel-aws-ec2/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentClientRegistryTest.java index 39686f8..57fee6f 100644 --- a/components/camel-aws-ec2/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentClientRegistryTest.java +++ b/components/camel-aws-ec2/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentClientRegistryTest.java @@ -26,7 +26,7 @@ public class EC2ComponentClientRegistryTest extends CamelTestSupport { AmazonEC2ClientMock clientMock = new AmazonEC2ClientMock(); context.getRegistry().bind("amazonEc2Client", clientMock); - EC2Component component = new EC2Component(context); + EC2Component component = context.getComponent("aws-ec2", EC2Component.class); EC2Endpoint endpoint = (EC2Endpoint)component.createEndpoint("aws-ec2://TestDomain"); assertNotNull(endpoint.getConfiguration().getAmazonEc2Client()); @@ -35,7 +35,7 @@ public class EC2ComponentClientRegistryTest extends CamelTestSupport { @Test(expected = IllegalArgumentException.class) public void createEndpointWithMinimalEC2ClientMisconfiguration() throws Exception { - EC2Component component = new EC2Component(context); + EC2Component component = context.getComponent("aws-ec2", EC2Component.class); EC2Endpoint endpoint = (EC2Endpoint)component.createEndpoint("aws-ec2://TestDomain"); } } diff --git a/components/camel-aws-ec2/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentConfigurationTest.java b/components/camel-aws-ec2/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentConfigurationTest.java index cdffaa7..2eaf17e 100644 --- a/components/camel-aws-ec2/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentConfigurationTest.java +++ b/components/camel-aws-ec2/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentConfigurationTest.java @@ -30,7 +30,7 @@ public class EC2ComponentConfigurationTest extends CamelTestSupport { public void createEndpointWithMinimalConfiguration() throws Exception { AmazonEC2Client amazonEc2Client = mock(AmazonEC2Client.class); context.getRegistry().bind("amazonEc2Client", amazonEc2Client); - EC2Component component = new EC2Component(context); + EC2Component component = context.getComponent("aws-ec2", EC2Component.class); EC2Endpoint endpoint = (EC2Endpoint)component.createEndpoint("aws-ec2://TestDomain?amazonEc2Client=#amazonEc2Client&accessKey=xxx&secretKey=yyy"); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); @@ -40,7 +40,7 @@ public class EC2ComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithOnlyAccessKeyAndSecretKey() throws Exception { - EC2Component component = new EC2Component(context); + EC2Component component = context.getComponent("aws-ec2", EC2Component.class); EC2Endpoint endpoint = (EC2Endpoint)component.createEndpoint("aws-ec2://TestDomain?accessKey=xxx&secretKey=yyy"); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); @@ -50,25 +50,25 @@ public class EC2ComponentConfigurationTest extends CamelTestSupport { @Test(expected = IllegalArgumentException.class) public void createEndpointWithoutDomainName() throws Exception { - EC2Component component = new EC2Component(context); + EC2Component component = context.getComponent("aws-ec2", EC2Component.class); component.createEndpoint("aws-ec2:// "); } @Test(expected = IllegalArgumentException.class) public void createEndpointWithoutAmazonSDBClientConfiguration() throws Exception { - EC2Component component = new EC2Component(context); + EC2Component component = context.getComponent("aws-ec2", EC2Component.class); component.createEndpoint("aws-ec2://TestDomain"); } @Test(expected = IllegalArgumentException.class) public void createEndpointWithoutAccessKeyConfiguration() throws Exception { - EC2Component component = new EC2Component(context); + EC2Component component = context.getComponent("aws-ec2", EC2Component.class); component.createEndpoint("aws-ec2://TestDomain?secretKey=yyy"); } @Test(expected = IllegalArgumentException.class) public void createEndpointWithoutSecretKeyConfiguration() throws Exception { - EC2Component component = new EC2Component(context); + EC2Component component = context.getComponent("aws-ec2", EC2Component.class); component.createEndpoint("aws-ec2://TestDomain?accessKey=xxx"); } @@ -76,13 +76,13 @@ public class EC2ComponentConfigurationTest extends CamelTestSupport { public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception { AmazonEC2Client amazonEc2Client = mock(AmazonEC2Client.class); context.getRegistry().bind("amazonEc2Client", amazonEc2Client); - EC2Component component = new EC2Component(context); + EC2Component component = context.getComponent("aws-ec2", EC2Component.class); component.createEndpoint("aws-ec2://TestDomain?amazonEc2Client=#amazonEc2Client"); } @Test public void createEndpointWithComponentElements() throws Exception { - EC2Component component = new EC2Component(context); + EC2Component component = context.getComponent("aws-ec2", EC2Component.class); component.setAccessKey("XXX"); component.setSecretKey("YYY"); EC2Endpoint endpoint = (EC2Endpoint)component.createEndpoint("aws-ec2://testDomain"); @@ -93,7 +93,7 @@ public class EC2ComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithComponentAndEndpointElements() throws Exception { - EC2Component component = new EC2Component(context); + EC2Component component = context.getComponent("aws-ec2", EC2Component.class); component.setAccessKey("XXX"); component.setSecretKey("YYY"); component.setRegion(Regions.US_WEST_1.toString()); @@ -106,7 +106,7 @@ public class EC2ComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithComponentEndpointElementsAndProxy() throws Exception { - EC2Component component = new EC2Component(context); + EC2Component component = context.getComponent("aws-ec2", EC2Component.class); component.setAccessKey("XXX"); component.setSecretKey("YYY"); component.setRegion(Regions.US_WEST_1.toString());