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 16:00:56 UTC
[camel] branch master updated: CAMEL-14284: Configuring endpoint
should set properties on endpoint and not configuration object - aws-ses
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 <an...@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://from@example.com?amazonSESClient=#amazonSESClient&accessKey=xxx&secretKey=yyy");
assertEquals("from@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://from@example.com?accessKey=xxx&secretKey=yyy");
assertEquals("from@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://from@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("to1@example.com");
+ to.add("to2@example.com");
+ List<String> replyAddress = new ArrayList<String>();
+ replyAddress.add("replyTo1@example.com");
+ replyAddress.add("replyTo2@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://from@example.com?amazonSESClient=#amazonSESClient&accessKey=xxx"
- + "&secretKey=yyy&to=to1@example.com,to2@example.com&subject=Subject"
- + "&returnPath=bounce@example.com&replyToAddresses=replyTo1@example.com,replyTo2@example.com");
+ + "&secretKey=yyy&to=#toList&subject=Subject"
+ + "&returnPath=bounce@example.com&replyToAddresses=#replyToList");
assertEquals("from@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://from@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://from@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://from@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://from@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://from@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("from@example.com", sendEmailRequest.getSource());
- assertEquals(2, getTo(sendEmailRequest).size());
- assertTrue(getTo(sendEmailRequest).contains("to1@example.com"));
- assertTrue(getTo(sendEmailRequest).contains("to2@example.com"));
assertEquals("bounce@example.com", sendEmailRequest.getReturnPath());
- assertEquals(2, sendEmailRequest.getReplyToAddresses().size());
- assertTrue(sendEmailRequest.getReplyToAddresses().contains("replyTo1@example.com"));
- assertTrue(sendEmailRequest.getReplyToAddresses().contains("replyTo2@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("from@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("to1@example.com", "to2@example.com");
+
+ @BindToRegistry("replyToList")
+ private List<String> replyToList = Arrays.asList("replyTo1@example.com", "replyTo2@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://from@example.com"
- + "?to=to1@example.com,to2@example.com"
+ + "?to=#toList"
+ "&subject=Subject"
+ "&returnPath=bounce@example.com"
- + "&replyToAddresses=replyTo1@example.com,replyTo2@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://from@example.com?amazonSESClient=#amazonSESClient&to=to1@example.com,to2@example.com&subject=Subject&returnPath=bounce@example.com&replyToAddresses=replyTo1@example.com,replyTo2@example.com"/>
+ <to uri="aws-ses://from@example.com?amazonSESClient=#amazonSESClient&returnPath=bounce@example.com"/>
</route>
</camelContext>