INTEXT-6: Add AWS core and SES adapter
For reference see: https://jira.springsource.org/browse/INTEXT-6
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.aws.common;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.aws.core.AbstractAWSClientFactory;
|
||||
|
||||
import com.amazonaws.auth.AWSCredentials;
|
||||
import com.amazonaws.services.sqs.AmazonSQSClient;
|
||||
|
||||
/**
|
||||
* The test class for {@link AbstractAmazonWSClientFactory}
|
||||
*
|
||||
* @author Amol Nayak
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
*/
|
||||
public class AWSClientFactoryTest {
|
||||
|
||||
AbstractAWSClientFactory<AmazonSQSClient> factory = new AbstractAWSClientFactory<AmazonSQSClient>() {
|
||||
|
||||
@Override
|
||||
protected AmazonSQSClient getClientImplementation() {
|
||||
return new AmazonSQSClient((AWSCredentials)null);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Test
|
||||
public void getRegionSpecificEndpoints() {
|
||||
//TODO: Use Spring integration test to inspect and assert the variables within
|
||||
AmazonSQSClient usEastClient = factory.getClient("https://queue.amazonaws.com/123456789012/MyTestQueue");
|
||||
Assert.assertNotNull(usEastClient);
|
||||
Assert.assertEquals(factory.getClientMap().size(),1);
|
||||
AmazonSQSClient usEastClient1 = factory.getClient("https://queue.amazonaws.com/123456789012/MyTestQueue1");
|
||||
Assert.assertNotNull(usEastClient1);
|
||||
Assert.assertEquals(usEastClient,usEastClient1);
|
||||
Assert.assertEquals(factory.getClientMap().size(),1);
|
||||
AmazonSQSClient apacClient1 = factory.getClient("https://ap-southeast-1.queue.amazonaws.com/123456789012/MyApacTestQueue");
|
||||
Assert.assertNotNull(apacClient1);
|
||||
Assert.assertEquals(factory.getClientMap().size(),2);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.aws.common;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Class extended by some of the test cases which are not spring based to get access to the properties
|
||||
* and other common functionality
|
||||
*
|
||||
* @author Amol Nayak
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
*/
|
||||
public abstract class BaseTestCase {
|
||||
|
||||
protected static String propsLocation = "testprops.properties";
|
||||
protected static Properties props;
|
||||
static {
|
||||
props = new Properties();
|
||||
try {
|
||||
props.load(ClassLoader.getSystemClassLoader().getResourceAsStream(propsLocation));
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected static String getProperty(String key) {
|
||||
if(props != null)
|
||||
return props.getProperty(key);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.aws.config.xml;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.aws.core.AWSCredentials;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
|
||||
/**
|
||||
* The Abstract test class for the AWS outbound adapter parsers
|
||||
*
|
||||
* @author Amol Nayak
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractAWSOutboundChannelAdapterParserTests<T extends MessageHandler> {
|
||||
|
||||
protected static ClassPathXmlApplicationContext ctx;
|
||||
private static boolean isInitialized;
|
||||
|
||||
/**
|
||||
* The bean name expected to be present in the context which would be used when the
|
||||
* element is defined with the propertiesFile attribute
|
||||
*/
|
||||
private final String CREDENTIALS_TEST_ONE = "credentialsTestOne";
|
||||
|
||||
/**
|
||||
* The bean name expected to be present in the context which would be used when the
|
||||
* element is defined with the accessKey and the secretKey definition
|
||||
*/
|
||||
private final String CREDENTIALS_TEST_TWO = "credentialsTestTwo";
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
if(!isInitialized) {
|
||||
String contextLocation = getConfigFilePath();
|
||||
Assert.assertNotNull("Non null path value expected", contextLocation);
|
||||
ctx = new ClassPathXmlApplicationContext(contextLocation);
|
||||
Assert.assertTrue("Bean with id " + CREDENTIALS_TEST_ONE
|
||||
+ " expected to be present in the context for credentials test",
|
||||
ctx.containsBean(CREDENTIALS_TEST_ONE));
|
||||
Assert.assertTrue("Bean with id " + CREDENTIALS_TEST_TWO
|
||||
+ " expected to be present in the context for credentials test",
|
||||
ctx.containsBean(CREDENTIALS_TEST_TWO));
|
||||
isInitialized = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void destroy() {
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Message handler implementation for the given bean id
|
||||
* @param beanId
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T getMessageHandlerForBeanDefinition(String beanId) {
|
||||
AbstractEndpoint endpoint = (AbstractEndpoint)ctx.getBean(beanId);
|
||||
return (T)TestUtils.getPropertyValue(endpoint, "handler");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the config file path that would be used to create the {@link ApplicationContext} instance
|
||||
* sub class should implement this method to return a value of the config to be used to create the
|
||||
* context
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getConfigFilePath();
|
||||
|
||||
/**
|
||||
* The subclass should return the {@link AmazonWSCredentials} instance that is being used
|
||||
* to configure the adapters
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract AWSCredentials getCredentials();
|
||||
|
||||
/**
|
||||
* The test class for the AWS Credentials test that used property files
|
||||
*/
|
||||
@Test
|
||||
public final void awsCredentialsTestWithPropFiles() {
|
||||
MessageHandler handler = getMessageHandlerForBeanDefinition(CREDENTIALS_TEST_ONE);
|
||||
AWSCredentials credentials = getCredentials();
|
||||
String accessKey = credentials.getAccessKey();
|
||||
String secretKey = credentials.getSecretKey();
|
||||
AWSCredentials configuredCredentials =
|
||||
TestUtils.getPropertyValue(handler, "credentials",AWSCredentials.class);
|
||||
Assert.assertEquals(accessKey, configuredCredentials.getAccessKey());
|
||||
Assert.assertEquals(secretKey, configuredCredentials.getSecretKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* The test class for the AWS Credentials test that used accessKey and secretKey elements
|
||||
*/
|
||||
@Test
|
||||
public final void awsCredentialsTestWithoutPropFiles() {
|
||||
MessageHandler handler = getMessageHandlerForBeanDefinition(CREDENTIALS_TEST_TWO);
|
||||
AWSCredentials credentials = getCredentials();
|
||||
String accessKey = credentials.getAccessKey();
|
||||
String secretKey = credentials.getSecretKey();
|
||||
AWSCredentials configuredCredentials =
|
||||
TestUtils.getPropertyValue(handler, "credentials",AWSCredentials.class);
|
||||
Assert.assertEquals(accessKey, configuredCredentials.getAccessKey());
|
||||
Assert.assertEquals(secretKey, configuredCredentials.getSecretKey());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.aws.core;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
|
||||
import com.amazonaws.AmazonWebServiceClient;
|
||||
|
||||
/**
|
||||
* The abstract test class for Amazon WebService client factory tests
|
||||
* @author Amol Nayak
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractAWSClientFactoryTests<T extends AmazonWebServiceClient> {
|
||||
|
||||
protected AbstractAWSClientFactory<T> factory;
|
||||
|
||||
@Before
|
||||
public final void setup() {
|
||||
factory = getFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* The subclass is responsible for returning the appropriate factory implementation
|
||||
* @return
|
||||
*/
|
||||
protected abstract AbstractAWSClientFactory<T> getFactory();
|
||||
|
||||
/**
|
||||
* Gets the endpoint for the service in US-EAST-1 region
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getUSEast1Endpoint();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the endpoint for the service in US-EAST-1 region
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getEUWest1Endpoint();
|
||||
|
||||
/**
|
||||
* Gets the Suffix for the endpoint URL which is service specific
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getSuffix();
|
||||
|
||||
/**
|
||||
* The test case for giving a US east endpoint without protocol
|
||||
*/
|
||||
@Test
|
||||
public void withUSEast1EndpointWithoutProtocol() {
|
||||
String usEast1 = getUSEast1Endpoint();
|
||||
factory.clear();
|
||||
T client = factory.getClient(usEast1 + getSuffix());
|
||||
Map<String, T> map = factory.getClientMap();
|
||||
Assert.assertNotNull(map);
|
||||
Assert.assertEquals(1, map.size());
|
||||
Assert.assertTrue("Expected one key with value https://" + usEast1, map.containsKey("https://" + usEast1));
|
||||
URI endpoint = TestUtils.getPropertyValue(client, "endpoint", URI.class);
|
||||
Assert.assertNotNull(endpoint);
|
||||
Assert.assertEquals(usEast1,endpoint.getHost());
|
||||
Assert.assertEquals("https",endpoint.getScheme());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the factory by providing an endpoint in US east with protocol as http
|
||||
*/
|
||||
@Test
|
||||
public void withUSEast1EndpointWithProtocol() {
|
||||
String usEast1 = getUSEast1Endpoint();
|
||||
factory.clear();
|
||||
T client = factory.getClient("http://" + usEast1 + getSuffix());
|
||||
Map<String, T> map = factory.getClientMap();
|
||||
Assert.assertNotNull(map);
|
||||
Assert.assertEquals(1, map.size());
|
||||
Assert.assertTrue("Expected one key with value http://" + usEast1, map.containsKey("http://" + usEast1));
|
||||
URI endpoint = TestUtils.getPropertyValue(client, "endpoint", URI.class);
|
||||
Assert.assertNotNull(endpoint);
|
||||
Assert.assertEquals(usEast1,endpoint.getHost());
|
||||
Assert.assertEquals("http",endpoint.getScheme());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calls the getClient multiple times to get the same client instance on each invocation
|
||||
*/
|
||||
@Test
|
||||
public void withMultipleCallsToSameEndpoint() {
|
||||
String usEast1 = getUSEast1Endpoint();
|
||||
factory.clear();
|
||||
T client = factory.getClient("https://" + usEast1 + getSuffix());
|
||||
Map<String, T> map = factory.getClientMap();
|
||||
Assert.assertNotNull(map);
|
||||
Assert.assertEquals(1, map.size());
|
||||
Assert.assertTrue("Expected one key with value http://" + usEast1, map.containsKey("https://" + usEast1));
|
||||
//default to https
|
||||
T client1 = factory.getClient(usEast1 + getSuffix());
|
||||
map = factory.getClientMap();
|
||||
Assert.assertEquals(1, map.size());
|
||||
Assert.assertTrue("Expected one key with value http://" + usEast1, map.containsKey("https://" + usEast1));
|
||||
Assert.assertTrue("Expecting to get the same instance of the client, but was not", client == client1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*Calls to different endpoints on the same client, expected to return a client with
|
||||
*appropriate endpoint URI set
|
||||
*/
|
||||
@Test
|
||||
public void withMultipleCallsToDifferentEndpoints() {
|
||||
String usEast1 = getUSEast1Endpoint();
|
||||
String euWest1 = getEUWest1Endpoint();
|
||||
factory.clear();
|
||||
T client = factory.getClient(usEast1 + getSuffix());
|
||||
Map<String, T> map = factory.getClientMap();
|
||||
Assert.assertNotNull(map);
|
||||
Assert.assertEquals(1, map.size());
|
||||
Assert.assertTrue("Expected one key with value https://" + usEast1, map.containsKey("https://" + usEast1));
|
||||
URI endpoint = TestUtils.getPropertyValue(client, "endpoint", URI.class);
|
||||
Assert.assertNotNull(endpoint);
|
||||
Assert.assertEquals(usEast1,endpoint.getHost());
|
||||
Assert.assertEquals("https",endpoint.getScheme());
|
||||
client = factory.getClient(euWest1 + getSuffix());
|
||||
map = factory.getClientMap();
|
||||
Assert.assertNotNull(map);
|
||||
Assert.assertEquals(2, map.size());
|
||||
Assert.assertTrue("Expected one key with value https://" + euWest1, map.containsKey("https://" + euWest1));
|
||||
endpoint = TestUtils.getPropertyValue(client, "endpoint", URI.class);
|
||||
Assert.assertNotNull(endpoint);
|
||||
Assert.assertEquals(euWest1,endpoint.getHost());
|
||||
Assert.assertEquals("https",endpoint.getScheme());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.aws.ses;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.integration.mail.MailHeaders.BCC;
|
||||
import static org.springframework.integration.mail.MailHeaders.CC;
|
||||
import static org.springframework.integration.mail.MailHeaders.FROM;
|
||||
import static org.springframework.integration.mail.MailHeaders.SUBJECT;
|
||||
import static org.springframework.integration.mail.MailHeaders.TO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
|
||||
|
||||
/**
|
||||
* The test class for {@link AmazonSESMessageHandler}
|
||||
*
|
||||
* @author Amol Nayak
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
*/
|
||||
public class AmazonSESMessageHandlerTests {
|
||||
|
||||
private static final List<SimpleMailMessage> messages = new ArrayList<SimpleMailMessage>();
|
||||
private static final List<MimeMessage> mimeMessages = new ArrayList<MimeMessage>();
|
||||
private static AmazonSESMessageHandler handler;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupAmazonSESMailSender() {
|
||||
JavaMailSender sender = mock(JavaMailSender.class);
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
Object[] args = invocation.getArguments();
|
||||
if(args != null) {
|
||||
messages.add((SimpleMailMessage)args[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}).when(sender).send(any(SimpleMailMessage.class));
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
Object[] args = invocation.getArguments();
|
||||
if(args != null) {
|
||||
messages.addAll(Arrays.asList((SimpleMailMessage[])args));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}).when(sender).send(any(SimpleMailMessage[].class));
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
Object[] args = invocation.getArguments();
|
||||
if(args != null) {
|
||||
mimeMessages.addAll(Arrays.asList((MimeMessage[])args));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}).when(sender).send(any(MimeMessage[].class));
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
Object[] args = invocation.getArguments();
|
||||
if(args != null) {
|
||||
mimeMessages.add((MimeMessage)args[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}).when(sender).send(any(MimeMessage.class));
|
||||
handler = new AmazonSESMessageHandler(sender);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
messages.clear();
|
||||
mimeMessages.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
*Test case for sending a message with subject line of unexpected type
|
||||
*{@link AmazonSESSimpleMailMessage}
|
||||
*
|
||||
*/
|
||||
@Test(expected=MessageHandlingException.class)
|
||||
public void withIncorrectSubjectClass() {
|
||||
Message<?> testMessage = MessageBuilder
|
||||
.withPayload("Test")
|
||||
.setHeader(SUBJECT, Arrays.asList("Some Header"))
|
||||
.build();
|
||||
handler.handleMessage(testMessage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test case where the message text used of incorrect type
|
||||
*
|
||||
*/
|
||||
@Test(expected=MessageHandlingException.class)
|
||||
public void withIncorrectMessageTextClass() {
|
||||
Message<?> testMessage = MessageBuilder
|
||||
.withPayload(Arrays.asList("Content"))
|
||||
.build();
|
||||
handler.handleMessage(testMessage);
|
||||
}
|
||||
|
||||
//Test case to check if from id exists or not cant work now as MailSendingMessageHandler
|
||||
//doesn't check if from is present or not
|
||||
|
||||
/**
|
||||
* With all the details
|
||||
*/
|
||||
@Test
|
||||
public void withAllTheDetails() {
|
||||
clear();
|
||||
Message<?> testMessage = MessageBuilder
|
||||
.withPayload("Test Content")
|
||||
.setHeader(TO, "to@to.com")
|
||||
.setHeader(BCC, "bcc@bcc.com")
|
||||
.setHeader(CC, "cc@cc.com")
|
||||
.setHeader(SUBJECT, "Test Subject")
|
||||
.setHeader(FROM, "from@from.com")
|
||||
.build();
|
||||
handler.handleMessage(testMessage);
|
||||
SimpleMailMessage message = messages.get(0);
|
||||
String[] to = message.getTo();
|
||||
Assert.assertNotNull(to);
|
||||
Assert.assertEquals(1,to.length);
|
||||
Assert.assertEquals("to@to.com", to[0]);
|
||||
|
||||
String[] cc = message.getCc();
|
||||
Assert.assertNotNull(cc);
|
||||
Assert.assertEquals(1,cc.length);
|
||||
Assert.assertEquals("cc@cc.com", cc[0]);
|
||||
|
||||
String[] bcc = message.getBcc();
|
||||
Assert.assertNotNull(bcc);
|
||||
Assert.assertEquals(1,bcc.length);
|
||||
Assert.assertEquals("bcc@bcc.com", bcc[0]);
|
||||
|
||||
Assert.assertEquals("from@from.com",message.getFrom());
|
||||
Assert.assertEquals("Test Subject",message.getSubject());
|
||||
Assert.assertEquals("Test Content", message.getText());
|
||||
}
|
||||
|
||||
//Might need to uncomment this test later when we start allowing null in TO email id of
|
||||
//spring-int-mail
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// @Test
|
||||
// public void withAllMultipleToBccAndCC() {
|
||||
// clear();
|
||||
// Message<?> testMessage = MessageBuilder
|
||||
// .withPayload("Test Content")
|
||||
// .setHeader(TO,
|
||||
// Arrays.asList("to1@to.com","to2@to.com"))
|
||||
// .setHeader(BCC,
|
||||
// Arrays.asList("bcc1@bcc.com","bcc2@bcc.com"))
|
||||
// .setHeader(CC,
|
||||
// Arrays.asList("cc1@cc.com","cc2@cc.com"))
|
||||
// .setHeader(SUBJECT, "Test Subject")
|
||||
// .setHeader(FROM, "from@from.com")
|
||||
// .build();
|
||||
// handler.handleMessage(testMessage);
|
||||
// SimpleMailMessage message = messages.get(0);
|
||||
// String[] to = message.getTo();
|
||||
// Assert.assertNotNull(to);
|
||||
// Assert.assertEquals(2,to.length);
|
||||
// Assert.assertEquals("to1@to.com", to[0]);
|
||||
// Assert.assertEquals("to2@to.com", to[1]);
|
||||
//
|
||||
// String[] cc = message.getCc();
|
||||
// Assert.assertNotNull(cc);
|
||||
// Assert.assertEquals(2,cc.length);
|
||||
// Assert.assertEquals("cc1@cc.com", cc[0]);
|
||||
// Assert.assertEquals("cc2@cc.com", cc[1]);
|
||||
//
|
||||
// String[] bcc = message.getBcc();
|
||||
// Assert.assertEquals(2,bcc.length);
|
||||
// Assert.assertEquals("bcc1@bcc.com", bcc[0]);
|
||||
// Assert.assertEquals("bcc2@bcc.com", bcc[1]);
|
||||
//
|
||||
// Assert.assertEquals("from@from.com",message.getFrom());
|
||||
//
|
||||
// Assert.assertEquals("Test Subject",message.getSubject());
|
||||
// Assert.assertEquals("Test Content", message.getText());
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.aws.ses.config.xml;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.aws.core.AWSCredentials;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
|
||||
/**
|
||||
* The test class for the AmazonSESOutboundAdapterParser
|
||||
*
|
||||
* @author Amol Nayak
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
*/
|
||||
public class AmazonSESOutboundAdapterParserTests {
|
||||
|
||||
|
||||
/**
|
||||
* Tests the creation of context with a valid definition by specifying the credentials
|
||||
* in a properties file
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void propFileValidOutboundAdapter() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:ses-propfile-valid-test.xml");
|
||||
EventDrivenConsumer consumer = ctx.getBean("validDefinition",EventDrivenConsumer.class);
|
||||
assertValidDefinition(consumer);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the creation of context with a valid definition by specifying the credentials
|
||||
* as individual attributes of the xml
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void propsValidOutboundAdapter() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:ses-props-valid-test.xml");
|
||||
EventDrivenConsumer consumer = ctx.getBean("validDefinition",EventDrivenConsumer.class);
|
||||
assertValidDefinition(consumer);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the creation of context with a valid definition by specifying the credentials
|
||||
* as individual attributes of the xml
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void refValidOutboundAdapter() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:ses-cred-ref-valid-test.xml");
|
||||
EventDrivenConsumer consumer = ctx.getBean("validDefinition",EventDrivenConsumer.class);
|
||||
assertValidDefinition(consumer);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
private void assertValidDefinition(EventDrivenConsumer consumer) {
|
||||
Assert.assertNotNull("Expected a non null EventDrivenConsumer", consumer);
|
||||
MessageHandler handler = TestUtils.getPropertyValue(consumer, "handler", MessageHandler.class);
|
||||
Assert.assertNotNull("Expected a non null messagehandler", handler);
|
||||
AWSCredentials credentials = TestUtils.getPropertyValue(handler, "mailSender.credentials", AWSCredentials.class);
|
||||
Assert.assertNotNull("Expected a non null instance of credentials", credentials);
|
||||
Assert.assertEquals("dummy", credentials.getAccessKey());
|
||||
Assert.assertEquals("dummy", credentials.getSecretKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* A Test case that tests by specifying both the aws credentials properties file
|
||||
* and the individual properties to set the credentials
|
||||
*/
|
||||
@Test(expected=BeanDefinitionParsingException.class)
|
||||
public void invalidDefinitionWithBothPropsAndPropFile() {
|
||||
new ClassPathXmlApplicationContext("classpath:ses-both-awscred-props-property.xml");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.aws.ses.core;
|
||||
|
||||
import javax.mail.Session;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.aws.core.PropertiesAWSCredentials;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* The test class for the {@link DefaultAmazonSESMailSender} class.
|
||||
*
|
||||
* NOTE: You will have to modify the to and from email's yourselves
|
||||
* as you can send to verified emails only as part of the free tier
|
||||
* in which you may be running the test.
|
||||
* To run this test you need to have your AWSAccess key and Secret key in the
|
||||
* file awscredentials.properties in the classpath. This file is not present in the
|
||||
* repository and you need to add one yourselves to src/test/resources folder and have
|
||||
* two properties accessKey and secretKey in it containing the access and the secret key
|
||||
*
|
||||
* @author Amol Nayak
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
*/
|
||||
public class DefaultAmazonSESMailSenderAWSTests {
|
||||
|
||||
private static final String TO_EMAIL_ID = "amolnayak311@gmail.com";
|
||||
private static DefaultAmazonSESMailSender sender;
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static final void setupSender() throws Exception {
|
||||
PropertiesAWSCredentials credentials =
|
||||
new PropertiesAWSCredentials("classpath:awscredentials.properties");
|
||||
credentials.afterPropertiesSet();
|
||||
sender = new DefaultAmazonSESMailSender(credentials);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a mail using {@link AmazonSESSimpleMailMessage}
|
||||
*/
|
||||
@Test
|
||||
public void sendSimpleMailMessage() {
|
||||
SimpleMailMessage message = new SimpleMailMessage();
|
||||
message.setFrom(TO_EMAIL_ID);
|
||||
message.setText("Some Test body content");
|
||||
message.setSubject("Test subject message");
|
||||
message.setTo(new String[]{TO_EMAIL_ID});
|
||||
sender.send(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send a mail using {@link AmazonSESSimpleMailMessage}
|
||||
*/
|
||||
@Test
|
||||
public void sendSimpleMailMessageArray() {
|
||||
SimpleMailMessage[] messages = new SimpleMailMessage[2];
|
||||
SimpleMailMessage message = new SimpleMailMessage();
|
||||
message.setFrom(TO_EMAIL_ID);
|
||||
message.setText("Some Test body content one");
|
||||
message.setSubject("Test subject message one");
|
||||
message.setTo(new String[]{TO_EMAIL_ID});
|
||||
messages[0] = message;
|
||||
message = new SimpleMailMessage();
|
||||
message.setFrom(TO_EMAIL_ID);
|
||||
message.setText("Some Test body content two");
|
||||
message.setSubject("Test subject message two");
|
||||
message.setTo(new String[]{TO_EMAIL_ID});
|
||||
messages[1] = message;
|
||||
sender.send(messages);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The test case for sending a {@link MimeMessage}
|
||||
*/
|
||||
@Test
|
||||
public void sendMimeMessage() throws Exception {
|
||||
Session session = sender.getSession();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(new MimeMessage(session));
|
||||
helper.setText("Some HTML Text", true);
|
||||
helper.setTo(TO_EMAIL_ID);
|
||||
helper.setFrom(TO_EMAIL_ID);
|
||||
helper.setSubject("Some HTML Message's Subject Line");
|
||||
MimeMessage message = helper.getMimeMessage();
|
||||
sender.send(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* The test case for sending a {@link MimeMessage}
|
||||
*/
|
||||
@Test
|
||||
public void sendMimeMessageArray() throws Exception {
|
||||
Session session = sender.getSession();
|
||||
MimeMessage[] messages = new MimeMessage[2];
|
||||
MimeMessageHelper helper = new MimeMessageHelper(new MimeMessage(session));
|
||||
helper.setText("Some HTML Text One", true);
|
||||
helper.setTo(TO_EMAIL_ID);
|
||||
helper.setFrom(TO_EMAIL_ID);
|
||||
helper.setSubject("Some HTML Message's Subject Line One");
|
||||
MimeMessage message = helper.getMimeMessage();
|
||||
messages[0] = message;
|
||||
helper = new MimeMessageHelper(new MimeMessage(session));
|
||||
helper.setText("Some HTML Text Two", true);
|
||||
helper.setTo(TO_EMAIL_ID);
|
||||
helper.setFrom(TO_EMAIL_ID);
|
||||
helper.setSubject("Some HTML Message's Subject Line Two");
|
||||
message = helper.getMimeMessage();
|
||||
messages[1] = message;
|
||||
sender.send(messages);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user