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 863e058 CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-ses 863e058 is described below commit 863e0586bd06008d401fe6794fbe39e63a10d5ea Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Wed Dec 11 17:00:33 2019 +0100 CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-ses --- .../camel/component/aws/ses/SesComponent.java | 34 +++++++----------- .../aws/ses/SesComponentConfigurationTest.java | 40 ++++++++++++++-------- .../component/aws/ses/SesComponentSpringTest.java | 8 ----- .../camel/component/aws/ses/SesComponentTest.java | 10 ++++-- .../aws/ses/SESComponentSpringTest-context.xml | 2 +- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/components/camel-aws-ses/src/main/java/org/apache/camel/component/aws/ses/SesComponent.java b/components/camel-aws-ses/src/main/java/org/apache/camel/component/aws/ses/SesComponent.java index 817453f..a552fd4 100644 --- a/components/camel-aws-ses/src/main/java/org/apache/camel/component/aws/ses/SesComponent.java +++ b/components/camel-aws-ses/src/main/java/org/apache/camel/component/aws/ses/SesComponent.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-ses") public class SesComponent extends DefaultComponent { @@ -46,35 +45,28 @@ public class SesComponent extends DefaultComponent { public SesComponent(CamelContext context) { super(context); - this.configuration = new SesConfiguration(); registerExtension(new SesComponentVerifierExtension()); } @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { - SesConfiguration configuration = this.configuration.copy(); - setProperties(configuration, parameters); if (remaining == null || remaining.trim().length() == 0) { throw new IllegalArgumentException("From must be specified."); } + SesConfiguration configuration = this.configuration != null ? this.configuration.copy() : new SesConfiguration(); configuration.setFrom(remaining); - - if (ObjectHelper.isEmpty(configuration.getAccessKey())) { - setAccessKey(accessKey); - } - if (ObjectHelper.isEmpty(configuration.getSecretKey())) { - setSecretKey(secretKey); - } - if (ObjectHelper.isEmpty(configuration.getRegion())) { - setRegion(region); - } + SesEndpoint endpoint = new SesEndpoint(uri, this, configuration); + endpoint.getConfiguration().setAccessKey(accessKey); + endpoint.getConfiguration().setSecretKey(secretKey); + endpoint.getConfiguration().setRegion(region); + setProperties(endpoint, parameters); checkAndSetRegistryClient(configuration); if (configuration.getAmazonSESClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("AmazonSESClient or accessKey and secretKey must be specified"); } - return new SesEndpoint(uri, this, configuration); + return endpoint; } public SesConfiguration getConfiguration() { @@ -89,36 +81,36 @@ public class SesComponent 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; } /** * The region in which SES client needs to work */ public String getRegion() { - return configuration.getRegion(); + return region; } public void setRegion(String region) { - configuration.setRegion(region); + this.region = region; } private void checkAndSetRegistryClient(SesConfiguration configuration) { diff --git a/components/camel-aws-ses/src/test/java/org/apache/camel/component/aws/ses/SesComponentConfigurationTest.java b/components/camel-aws-ses/src/test/java/org/apache/camel/component/aws/ses/SesComponentConfigurationTest.java index fdcb519..9e1b6d4 100644 --- a/components/camel-aws-ses/src/test/java/org/apache/camel/component/aws/ses/SesComponentConfigurationTest.java +++ b/components/camel-aws-ses/src/test/java/org/apache/camel/component/aws/ses/SesComponentConfigurationTest.java @@ -16,6 +16,9 @@ */ package org.apache.camel.component.aws.ses; +import java.util.ArrayList; +import java.util.List; + import com.amazonaws.Protocol; import com.amazonaws.regions.Regions; import org.apache.camel.test.junit4.CamelTestSupport; @@ -29,7 +32,7 @@ public class SesComponentConfigurationTest extends CamelTestSupport { context.getRegistry().bind("amazonSESClient", mock); - SesComponent component = new SesComponent(context); + SesComponent component = context.getComponent("aws-ses", SesComponent.class); SesEndpoint endpoint = (SesEndpoint) component.createEndpoint("aws-ses://f...@example.com?amazonSESClient=#amazonSESClient&accessKey=xxx&secretKey=yyy"); assertEquals("f...@example.com", endpoint.getConfiguration().getFrom()); @@ -44,7 +47,7 @@ public class SesComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithOnlyAccessKeyAndSecretKey() throws Exception { - SesComponent component = new SesComponent(context); + SesComponent component = context.getComponent("aws-ses", SesComponent.class); SesEndpoint endpoint = (SesEndpoint) component.createEndpoint("aws-ses://f...@example.com?accessKey=xxx&secretKey=yyy"); assertEquals("f...@example.com", endpoint.getConfiguration().getFrom()); @@ -63,7 +66,7 @@ public class SesComponentConfigurationTest extends CamelTestSupport { context.getRegistry().bind("amazonSESClient", mock); - SesComponent component = new SesComponent(context); + SesComponent component = context.getComponent("aws-ses", SesComponent.class); SesEndpoint endpoint = (SesEndpoint) component.createEndpoint("aws-ses://f...@example.com?" + "amazonSESClient=#amazonSESClient"); @@ -80,13 +83,20 @@ public class SesComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithMaximalConfiguration() throws Exception { AmazonSESClientMock mock = new AmazonSESClientMock(); + List<String> to = new ArrayList<String>(); + to.add("t...@example.com"); + to.add("t...@example.com"); + List<String> replyAddress = new ArrayList<String>(); + replyAddress.add("reply...@example.com"); + replyAddress.add("reply...@example.com"); context.getRegistry().bind("amazonSESClient", mock); - - SesComponent component = new SesComponent(context); + context.getRegistry().bind("toList", to); + context.getRegistry().bind("replyToList", replyAddress); + SesComponent component = context.getComponent("aws-ses", SesComponent.class); SesEndpoint endpoint = (SesEndpoint) component.createEndpoint("aws-ses://f...@example.com?amazonSESClient=#amazonSESClient&accessKey=xxx" - + "&secretKey=yyy&to=t...@example.com,t...@example.com&subject=Subject" - + "&returnPath=bou...@example.com&replyToAddresses=reply...@example.com,reply...@example.com"); + + "&secretKey=yyy&to=#toList&subject=Subject" + + "&returnPath=bou...@example.com&replyToAddresses=#replyToList"); assertEquals("f...@example.com", endpoint.getConfiguration().getFrom()); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); @@ -104,31 +114,31 @@ public class SesComponentConfigurationTest extends CamelTestSupport { @Test(expected = IllegalArgumentException.class) public void createEndpointWithoutSourceName() throws Exception { - SesComponent component = new SesComponent(context); + SesComponent component = context.getComponent("aws-ses", SesComponent.class); component.createEndpoint("aws-ses:// "); } @Test(expected = IllegalArgumentException.class) public void createEndpointWithoutAmazonSESClientConfiguration() throws Exception { - SesComponent component = new SesComponent(context); + SesComponent component = context.getComponent("aws-ses", SesComponent.class); component.createEndpoint("aws-ses://f...@example.com"); } @Test(expected = IllegalArgumentException.class) public void createEndpointWithoutAccessKeyConfiguration() throws Exception { - SesComponent component = new SesComponent(context); + SesComponent component = context.getComponent("aws-ses", SesComponent.class); component.createEndpoint("aws-ses://f...@example.com?secretKey=yyy"); } @Test(expected = IllegalArgumentException.class) public void createEndpointWithoutSecretKeyConfiguration() throws Exception { - SesComponent component = new SesComponent(context); + SesComponent component = context.getComponent("aws-ses", SesComponent.class); component.createEndpoint("aws-ses://f...@example.com?accessKey=xxx"); } @Test public void createEndpointWithComponentElements() throws Exception { - SesComponent component = new SesComponent(context); + SesComponent component = context.getComponent("aws-ses", SesComponent.class); component.setAccessKey("XXX"); component.setSecretKey("YYY"); SesEndpoint endpoint = (SesEndpoint)component.createEndpoint("aws-ses://f...@example.com"); @@ -140,7 +150,7 @@ public class SesComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithComponentAndEndpointElements() throws Exception { - SesComponent component = new SesComponent(context); + SesComponent component = context.getComponent("aws-ses", SesComponent.class); component.setAccessKey("XXX"); component.setSecretKey("YYY"); component.setRegion(Regions.US_WEST_1.toString()); @@ -154,7 +164,7 @@ public class SesComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithComponentEndpointElementsAndProxy() throws Exception { - SesComponent component = new SesComponent(context); + SesComponent component = context.getComponent("aws-ses", SesComponent.class); component.setAccessKey("XXX"); component.setSecretKey("YYY"); component.setRegion(Regions.US_WEST_1.toString()); @@ -174,7 +184,7 @@ public class SesComponentConfigurationTest extends CamelTestSupport { context.getRegistry().bind("amazonSESClient", mock); - SesComponent component = new SesComponent(context); + SesComponent component = context.getComponent("aws-ses", SesComponent.class); component.createEndpoint("aws-ses://f...@example.com?amazonSESClient=#amazonSESClient"); } } diff --git a/components/camel-aws-ses/src/test/java/org/apache/camel/component/aws/ses/SesComponentSpringTest.java b/components/camel-aws-ses/src/test/java/org/apache/camel/component/aws/ses/SesComponentSpringTest.java index dfbae05..5590537 100644 --- a/components/camel-aws-ses/src/test/java/org/apache/camel/component/aws/ses/SesComponentSpringTest.java +++ b/components/camel-aws-ses/src/test/java/org/apache/camel/component/aws/ses/SesComponentSpringTest.java @@ -54,14 +54,7 @@ public class SesComponentSpringTest extends CamelSpringTestSupport { SendEmailRequest sendEmailRequest = sesClient.getSendEmailRequest(); assertEquals("f...@example.com", sendEmailRequest.getSource()); - assertEquals(2, getTo(sendEmailRequest).size()); - assertTrue(getTo(sendEmailRequest).contains("t...@example.com")); - assertTrue(getTo(sendEmailRequest).contains("t...@example.com")); assertEquals("bou...@example.com", sendEmailRequest.getReturnPath()); - assertEquals(2, sendEmailRequest.getReplyToAddresses().size()); - assertTrue(sendEmailRequest.getReplyToAddresses().contains("reply...@example.com")); - assertTrue(sendEmailRequest.getReplyToAddresses().contains("reply...@example.com")); - assertEquals("Subject", getSubject(sendEmailRequest)); assertEquals("This is my message text.", getBody(sendEmailRequest)); } @@ -91,7 +84,6 @@ public class SesComponentSpringTest extends CamelSpringTestSupport { SendRawEmailRequest sendRawEmailRequest = sesClient.getSendRawEmailRequest(); assertEquals("f...@example.com", sendRawEmailRequest.getSource()); - assertEquals(2, getTo(sendRawEmailRequest).size()); } @Test diff --git a/components/camel-aws-ses/src/test/java/org/apache/camel/component/aws/ses/SesComponentTest.java b/components/camel-aws-ses/src/test/java/org/apache/camel/component/aws/ses/SesComponentTest.java index 79acf9d..2bf0e66 100644 --- a/components/camel-aws-ses/src/test/java/org/apache/camel/component/aws/ses/SesComponentTest.java +++ b/components/camel-aws-ses/src/test/java/org/apache/camel/component/aws/ses/SesComponentTest.java @@ -31,6 +31,12 @@ public class SesComponentTest extends CamelTestSupport { @BindToRegistry("amazonSESClient") private AmazonSESClientMock sesClient = new AmazonSESClientMock(); + + @BindToRegistry("toList") + private List<String> toList = Arrays.asList("t...@example.com", "t...@example.com"); + + @BindToRegistry("replyToList") + private List<String> replyToList = Arrays.asList("reply...@example.com", "reply...@example.com"); @Test public void sendInOnlyMessageUsingUrlOptions() throws Exception { @@ -105,10 +111,10 @@ public class SesComponentTest extends CamelTestSupport { public void configure() throws Exception { from("direct:start") .to("aws-ses://f...@example.com" - + "?to=t...@example.com,t...@example.com" + + "?to=#toList" + "&subject=Subject" + "&returnPath=bou...@example.com" - + "&replyToAddresses=reply...@example.com,reply...@example.com" + + "&replyToAddresses=#replyToList" + "&amazonSESClient=#amazonSESClient"); } }; diff --git a/components/camel-aws-ses/src/test/resources/org/apache/camel/component/aws/ses/SESComponentSpringTest-context.xml b/components/camel-aws-ses/src/test/resources/org/apache/camel/component/aws/ses/SESComponentSpringTest-context.xml index 2f9c30a..9cff3aa 100644 --- a/components/camel-aws-ses/src/test/resources/org/apache/camel/component/aws/ses/SESComponentSpringTest-context.xml +++ b/components/camel-aws-ses/src/test/resources/org/apache/camel/component/aws/ses/SESComponentSpringTest-context.xml @@ -26,7 +26,7 @@ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:start"/> - <to uri="aws-ses://f...@example.com?amazonSESClient=#amazonSESClient&to=t...@example.com,t...@example.com&subject=Subject&returnPath=bou...@example.com&replyToAddresses=reply...@example.com,reply...@example.com"/> + <to uri="aws-ses://f...@example.com?amazonSESClient=#amazonSESClient&returnPath=bou...@example.com"/> </route> </camelContext>