renamed modules org.springframework.integration.* -> spring-integration-*

@Ignore'd SimpleTcpNetOutboundGatewayTests#testOutboundClose() to avoid failure; this failure is correlated to the module name change, but hard to understand how it would be caused by it
This commit is contained in:
Chris Beams
2010-05-25 13:21:25 +00:00
parent b97b2fb090
commit c08a7a657e
1484 changed files with 18 additions and 23 deletions

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2002-2008 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.mail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.util.concurrent.ConcurrentLinkedQueue;
import javax.mail.internet.MimeMessage;
import org.easymock.classextension.EasyMock;
import org.junit.Test;
/**
* @author Jonas Partner
* @author Mark Fisher
*/
public class MailReceivingMessageSourceTests {
@Test
public void testPolling() {
StubMailReceiver mailReceiver = new StubMailReceiver();
MimeMessage message1 = EasyMock.createMock(MimeMessage.class);
MimeMessage message2 = EasyMock.createMock(MimeMessage.class);
MimeMessage message3 = EasyMock.createMock(MimeMessage.class);
MimeMessage message4 = EasyMock.createMock(MimeMessage.class);
mailReceiver.messages.add(new javax.mail.Message[] { message1 });
mailReceiver.messages.add(new javax.mail.Message[] { message2, message3 });
mailReceiver.messages.add(new javax.mail.Message[] { message4 });
MailReceivingMessageSource source = new MailReceivingMessageSource(mailReceiver);
assertEquals("Wrong message for number 1", message1, source.receive().getPayload());
assertEquals("Wrong message for number 2", message2, source.receive().getPayload());
assertEquals("Wrong message for number 3", message3, source.receive().getPayload());
assertEquals("Wrong message for number 4", message4, source.receive().getPayload());
assertNull("Expected null after exhausting all messages", source.receive());
}
private static class StubMailReceiver implements MailReceiver {
private final ConcurrentLinkedQueue<javax.mail.Message[]> messages = new ConcurrentLinkedQueue<javax.mail.Message[]>();
public javax.mail.Message[] receive() {
return messages.poll();
}
public boolean isRunning() {
return false;
}
public void start() {
}
public void stop() {
}
}
}

View File

@@ -0,0 +1,102 @@
/*
* Copyright 2002-2010 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.mail;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.DataInputStream;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.internet.MimeMessage;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.message.MessageMappingException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Marius Bogoevici
*/
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/org/springframework/integration/mail/mailSendingMessageHandlerContextTests.xml"})
public class MailSendingMessageHandlerContextTests {
@Autowired
private MailSendingMessageHandler handler;
@Autowired
private StubJavaMailSender mailSender;
@Before
public void reset() {
this.mailSender.reset();
}
@Test
public void stringMesssagesWithConfiguration() {
this.handler.handleMessage(MailTestsHelper.createIntegrationMessage());
SimpleMailMessage mailMessage = MailTestsHelper.createSimpleMailMessage();
assertEquals("no mime message should have been sent",
0, this.mailSender.getSentMimeMessages().size());
assertEquals("only one simple message must be sent",
1, this.mailSender.getSentSimpleMailMessages().size());
assertEquals("message content different from expected",
mailMessage, this.mailSender.getSentSimpleMailMessages().get(0));
}
@Test
public void byteArrayMessage() throws Exception {
byte[] payload = {1, 2, 3};
org.springframework.integration.core.Message<?> message =
MessageBuilder.withPayload(payload)
.setHeader(MailHeaders.ATTACHMENT_FILENAME, "attachment.txt")
.setHeader(MailHeaders.TO, MailTestsHelper.TO)
.build();
this.handler.handleMessage(message);
assertEquals("no mime message should have been sent",
1, this.mailSender.getSentMimeMessages().size());
assertEquals("only one simple message must be sent",
0, this.mailSender.getSentSimpleMailMessages().size());
byte[] buffer = new byte[1024];
MimeMessage mimeMessage = this.mailSender.getSentMimeMessages().get(0);
assertTrue("message must be multipart", mimeMessage.getContent() instanceof Multipart);
int size = new DataInputStream(((Multipart) mimeMessage.getContent()).getBodyPart(0).getInputStream()).read(buffer);
assertEquals("buffer size does not match", payload.length, size);
byte[] messageContent = new byte[size];
System.arraycopy(buffer, 0, messageContent, 0, payload.length);
assertArrayEquals("buffer content does not match", payload, messageContent);
assertEquals(mimeMessage.getRecipients(Message.RecipientType.TO).length, MailTestsHelper.TO.length);
}
@Test(expected = MessageMappingException.class)
public void byteArrayMessageWithoutAttachmentFileName() throws Exception {
byte[] payload = {1, 2, 3};
this.handler.handleMessage(new GenericMessage<byte[]>(payload));
}
}

View File

@@ -0,0 +1,123 @@
/*
* Copyright 2002-2008 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.mail;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.DataInputStream;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.mail.SimpleMailMessage;
/**
* @author Marius Bogoevici
* @author Oleg Zhurakousky
*/
public class MailSendingMessageHandlerTests {
private MailSendingMessageHandler handler;
private StubJavaMailSender mailSender;
@Before
public void setUp() throws Exception {
this.mailSender = new StubJavaMailSender(new MimeMessage((Session) null));
this.handler = new MailSendingMessageHandler(this.mailSender);
}
@After
public void reset() {
this.mailSender.reset();
}
@Test
public void textMessage() {
this.handler.handleMessage(MailTestsHelper.createIntegrationMessage());
SimpleMailMessage mailMessage = MailTestsHelper.createSimpleMailMessage();
assertEquals("no mime message should have been sent",
0, mailSender.getSentMimeMessages().size());
assertEquals("only one simple message must be sent",
1, mailSender.getSentSimpleMailMessages().size());
assertEquals("message content different from expected",
mailMessage, mailSender.getSentSimpleMailMessages().get(0));
}
@Test
public void byteArrayMessage() throws Exception {
byte[] payload = {1, 2, 3};
org.springframework.integration.core.Message<byte[]> message =
MessageBuilder.withPayload(payload)
.setHeader(MailHeaders.ATTACHMENT_FILENAME, "attachment.txt")
.setHeader(MailHeaders.TO, MailTestsHelper.TO)
.build();
this.handler.handleMessage(message);
byte[] buffer = new byte[1024];
MimeMessage mimeMessage = this.mailSender.getSentMimeMessages().get(0);
assertTrue("message must be multipart", mimeMessage.getContent() instanceof Multipart);
int size = new DataInputStream(((Multipart) mimeMessage.getContent()).getBodyPart(0).getInputStream()).read(buffer);
assertEquals("buffer size does not match", payload.length, size);
byte[] messageContent = new byte[size];
System.arraycopy(buffer, 0, messageContent, 0, payload.length);
assertArrayEquals("buffer content does not match", payload, messageContent);
assertEquals(mimeMessage.getRecipients(Message.RecipientType.TO).length, MailTestsHelper.TO.length);
}
@Test
public void mailHeaders() {
this.handler.handleMessage(MailTestsHelper.createIntegrationMessage());
SimpleMailMessage mailMessage = MailTestsHelper.createSimpleMailMessage();
assertEquals("no mime message should have been sent",
0, mailSender.getSentMimeMessages().size());
assertEquals("only one simple message must be sent",
1, mailSender.getSentSimpleMailMessages().size());
assertEquals("message content different from expected",
mailMessage, mailSender.getSentSimpleMailMessages().get(0));
}
@Test
public void simpleMailMessage() {
SimpleMailMessage mailMessage = MailTestsHelper.createSimpleMailMessage();
String[] toHeaders = mailMessage.getTo();
this.handler.handleMessage(MessageBuilder.withPayload(mailMessage).build());
assertEquals("only one simple message must be sent",
1, mailSender.getSentSimpleMailMessages().size());
SimpleMailMessage sentMessage = mailSender.getSentSimpleMailMessages().get(0);
assertTrue(sentMessage.getTo().equals(toHeaders));
}
@Test
public void simpleMailMessageOverrideWithHeaders() {
SimpleMailMessage mailMessage = MailTestsHelper.createSimpleMailMessage();
String[] toHeaders = mailMessage.getTo();
this.handler.handleMessage(MessageBuilder.withPayload(mailMessage).setHeader(MailHeaders.TO, new String[]{"foo@bar.bam"}).build());
assertEquals("only one simple message must be sent",
1, mailSender.getSentSimpleMailMessages().size());
SimpleMailMessage sentMessage = mailSender.getSentSimpleMailMessages().get(0);
assertTrue(sentMessage.getTo()[0].equals("foo@bar.bam"));
}
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright 2002-2008 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.mail;
import org.springframework.integration.core.Message;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.mail.SimpleMailMessage;
/**
* @author Marius Bogoevici
*/
public class MailTestsHelper {
public static final String SUBJECT = "Some subject";
public static final String MESSAGE_TEXT = "Some text";
public static final String[] TO = new String[] {
"toRecipient1@springframework.org", "toRecipient2@springframework.org" };
public static final String[] CC = new String[] {
"ccRecipient1@springframework.org", "ccRecipient2@springframework.org" };
public static final String[] BCC = new String[] {
"bccRecipient1@springframework.org", "bccRecipient2@springframework.org" };
public static final String FROM = "from@springframework.org";
public static final String REPLY_TO = "replyTo@springframework.org";
public static SimpleMailMessage createSimpleMailMessage() {
SimpleMailMessage message = new SimpleMailMessage();
message.setBcc(BCC);
message.setCc(CC);
message.setTo(TO);
message.setSubject(SUBJECT);
message.setReplyTo(REPLY_TO);
message.setFrom(FROM);
message.setText(MESSAGE_TEXT);
return message;
}
public static Message<String> createIntegrationMessage() {
return MessageBuilder.withPayload(MailTestsHelper.MESSAGE_TEXT)
.setHeader(MailHeaders.SUBJECT, MailTestsHelper.SUBJECT)
.setHeader(MailHeaders.TO, MailTestsHelper.TO)
.setHeader(MailHeaders.CC, MailTestsHelper.CC)
.setHeader(MailHeaders.BCC, MailTestsHelper.BCC)
.setHeader(MailHeaders.FROM, MailTestsHelper.FROM)
.setHeader(MailHeaders.REPLY_TO, MailTestsHelper.REPLY_TO)
.build();
}
}

View File

@@ -0,0 +1,93 @@
/*
* Copyright 2002-2007 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.mail;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.mail.internet.MimeMessage;
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessagePreparator;
/**
* @author Marius Bogoevici
*/
public class StubJavaMailSender implements JavaMailSender {
private MimeMessage uniqueMessage;
private final List<MimeMessage> sentMimeMessages = new ArrayList<MimeMessage>();
private final List<SimpleMailMessage> sentSimpleMailMessages = new ArrayList<SimpleMailMessage>();
public StubJavaMailSender(MimeMessage uniqueMessage) {
this.uniqueMessage = uniqueMessage;
}
public List<MimeMessage> getSentMimeMessages() {
return this.sentMimeMessages;
}
public List<SimpleMailMessage> getSentSimpleMailMessages() {
return this.sentSimpleMailMessages;
}
public MimeMessage createMimeMessage() {
return this.uniqueMessage;
}
public MimeMessage createMimeMessage(InputStream contentStream) throws MailException {
return this.uniqueMessage;
}
public void send(MimeMessage mimeMessage) throws MailException {
this.sentMimeMessages.add(mimeMessage);
}
public void send(MimeMessage[] mimeMessages) throws MailException {
this.sentMimeMessages.addAll(Arrays.asList(mimeMessages));
}
public void send(MimeMessagePreparator mimeMessagePreparator) throws MailException {
throw new UnsupportedOperationException("MimeMessagePreparator not supported");
}
public void send(MimeMessagePreparator[] mimeMessagePreparators) throws MailException {
throw new UnsupportedOperationException("MimeMessagePreparator not supported");
}
public void send(SimpleMailMessage simpleMessage) throws MailException {
this.sentSimpleMailMessages.add(simpleMessage);
}
public void send(SimpleMailMessage[] simpleMessages) throws MailException {
this.sentSimpleMailMessages.addAll(Arrays.asList(simpleMessages));
}
public void reset() {
this.sentMimeMessages.clear();
this.sentSimpleMailMessages.clear();
}
}

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mail="http://www.springframework.org/schema/integration/mail"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration/mail
http://www.springframework.org/schema/integration/mail/spring-integration-mail-1.0.xsd">
<mail:outbound-channel-adapter id="adapter" mail-sender="mailSender" auto-startup="false"/>
<bean id="mailSender" class="org.springframework.integration.mail.StubJavaMailSender">
<constructor-arg>
<bean class="javax.mail.internet.MimeMessage">
<constructor-arg type="javax.mail.Session"><null/></constructor-arg>
</bean>
</constructor-arg>
</bean>
</beans>

View File

@@ -0,0 +1,72 @@
/*
* Copyright 2002-2009 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.mail.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.channel.MessagePublishingErrorHandler;
import org.springframework.integration.channel.NullChannel;
import org.springframework.integration.channel.PublishSubscribeChannel;
import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @since 1.0.3
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class DefaultConfigurationTests {
@Autowired
private ApplicationContext context;
@Test
public void verifyErrorChannel() {
Object errorChannel = context.getBean("errorChannel");
assertNotNull(errorChannel);
assertEquals(PublishSubscribeChannel.class, errorChannel.getClass());
}
@Test
public void verifyNullChannel() {
Object nullChannel = context.getBean("nullChannel");
assertNotNull(nullChannel);
assertEquals(NullChannel.class, nullChannel.getClass());
}
@Test
public void verifyTaskScheduler() {
Object taskScheduler = context.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME);
assertEquals(ThreadPoolTaskScheduler.class, taskScheduler.getClass());
Object errorHandler = new DirectFieldAccessor(taskScheduler).getPropertyValue("errorHandler");
assertEquals(MessagePublishingErrorHandler.class, errorHandler.getClass());
Object defaultErrorChannel = new DirectFieldAccessor(errorHandler).getPropertyValue("defaultErrorChannel");
assertEquals(context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME), defaultErrorChannel);
}
}

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2002-2008 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.mail.config;
/**
* @author Mark Fisher
*/
public class Exclaimer {
public String exclaim(String input) {
return input.toUpperCase() + "!!!";
}
}

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mail="http://www.springframework.org/schema/integration/mail"
xmlns:integration="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/mail
http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd">
<integration:channel id="channel"/>
<mail:imap-idle-channel-adapter id="simpleAdapter"
store-uri="imap:foo"
channel="channel"
auto-startup="false"
should-delete-messages="true"/>
<mail:imap-idle-channel-adapter id="customAdapter"
store-uri="imap:foo"
channel="channel"
auto-startup="false"
java-mail-properties="props"
should-delete-messages="false"
task-executor="executor"/>
<util:properties id="props">
<prop key="foo">bar</prop>
</util:properties>
<task:executor id="executor" pool-size="5"/>
</beans>

View File

@@ -0,0 +1,88 @@
/*
* Copyright 2002-2009 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.mail.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import java.util.Properties;
import javax.mail.URLName;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.mail.ImapIdleChannelAdapter;
import org.springframework.integration.mail.ImapMailReceiver;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class ImapIdleChannelAdapterParserTests {
@Autowired
private ApplicationContext context;
@Test
public void simpleAdapter() {
Object adapter = context.getBean("simpleAdapter");
assertEquals(ImapIdleChannelAdapter.class, adapter.getClass());
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
Object channel = context.getBean("channel");
assertSame(channel, adapterAccessor.getPropertyValue("outputChannel"));
assertNull(adapterAccessor.getPropertyValue("taskExecutor"));
assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup"));
Object receiver = adapterAccessor.getPropertyValue("mailReceiver");
assertEquals(ImapMailReceiver.class, receiver.getClass());
DirectFieldAccessor receiverAccessor = new DirectFieldAccessor(receiver);
Object url = receiverAccessor.getPropertyValue("url");
assertEquals(new URLName("imap:foo"), url);
Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
assertEquals(0, properties.size());
assertEquals(Boolean.TRUE, receiverAccessor.getPropertyValue("shouldDeleteMessages"));
}
@Test
public void customAdapter() {
Object adapter = context.getBean("customAdapter");
assertEquals(ImapIdleChannelAdapter.class, adapter.getClass());
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
Object channel = context.getBean("channel");
Object executor = context.getBean("executor");
assertSame(channel, adapterAccessor.getPropertyValue("outputChannel"));
assertSame(executor, adapterAccessor.getPropertyValue("taskExecutor"));
assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup"));
Object receiver = adapterAccessor.getPropertyValue("mailReceiver");
assertEquals(ImapMailReceiver.class, receiver.getClass());
DirectFieldAccessor receiverAccessor = new DirectFieldAccessor(receiver);
Object url = receiverAccessor.getPropertyValue("url");
assertEquals(new URLName("imap:foo"), url);
Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
assertEquals("bar", properties.getProperty("foo"));
assertEquals(Boolean.FALSE, receiverAccessor.getPropertyValue("shouldDeleteMessages"));
}
}

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration/mail"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/mail
http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd">
<header-enricher input-channel="literalValuesInput">
<to value="test.to"/>
<cc value="test.cc"/>
<bcc value="test.bcc"/>
<from value="test.from"/>
<reply-to value="test.reply-to"/>
<subject value="test.subject"/>
</header-enricher>
<header-enricher input-channel="expressionsInput">
<to expression="payload + '.to'"/>
<cc expression="payload + '.cc'"/>
<bcc expression="payload + '.bcc'"/>
<from expression="payload + '.from'"/>
<reply-to expression="payload + '.reply-to'"/>
<subject expression="payload + '.subject'"/>
</header-enricher>
</beans:beans>

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2002-2009 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.mail.config;
import static org.junit.Assert.assertEquals;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.channel.MessageChannelTemplate;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.mail.MailHeaders;
import org.springframework.integration.message.StringMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class MailHeaderEnricherTests {
@Autowired @Qualifier("literalValuesInput")
private MessageChannel literalValuesInput;
@Autowired @Qualifier("expressionsInput")
private MessageChannel expressionsInput;
@Test
public void literalValues() {
MessageChannelTemplate template = new MessageChannelTemplate(literalValuesInput);
Message<?> result = template.sendAndReceive(new StringMessage("test"));
Map<String, Object> headers = result.getHeaders();
assertEquals("test.to", headers.get(MailHeaders.TO));
assertEquals("test.cc", headers.get(MailHeaders.CC));
assertEquals("test.bcc", headers.get(MailHeaders.BCC));
assertEquals("test.from", headers.get(MailHeaders.FROM));
assertEquals("test.reply-to", headers.get(MailHeaders.REPLY_TO));
assertEquals("test.subject", headers.get(MailHeaders.SUBJECT));
}
@Test
public void expressions() {
MessageChannelTemplate template = new MessageChannelTemplate(expressionsInput);
Message<?> result = template.sendAndReceive(new StringMessage("foo"));
Map<String, Object> headers = result.getHeaders();
assertEquals("foo.to", headers.get(MailHeaders.TO));
assertEquals("foo.cc", headers.get(MailHeaders.CC));
assertEquals("foo.bcc", headers.get(MailHeaders.BCC));
assertEquals("foo.from", headers.get(MailHeaders.FROM));
assertEquals("foo.reply-to", headers.get(MailHeaders.REPLY_TO));
assertEquals("foo.subject", headers.get(MailHeaders.SUBJECT));
}
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright 2002-2008 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.mail.config;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.mail.MailSendingMessageHandler;
import org.springframework.mail.MailSender;
/**
* @author Mark Fisher
*/
public class MailOutboundChannelAdapterParserTests {
@Test
public void adapterWithMailSenderReference() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"mailOutboundChannelAdapterParserTests.xml", this.getClass());
Object adapter = context.getBean("adapterWithMailSenderReference.adapter");
MailSendingMessageHandler handler = (MailSendingMessageHandler)
new DirectFieldAccessor(adapter).getPropertyValue("handler");
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(handler);
MailSender mailSender = (MailSender) fieldAccessor.getPropertyValue("mailSender");
assertNotNull(mailSender);
}
@Test
public void adapterWithHostProperty() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"mailOutboundChannelAdapterParserTests.xml", this.getClass());
Object adapter = context.getBean("adapterWithHostProperty.adapter");
MailSendingMessageHandler handler = (MailSendingMessageHandler)
new DirectFieldAccessor(adapter).getPropertyValue("handler");
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(handler);
MailSender mailSender = (MailSender) fieldAccessor.getPropertyValue("mailSender");
assertNotNull(mailSender);
}
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright 2002-2008 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.mail.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import javax.mail.internet.MimeMessage;
import org.easymock.classextension.EasyMock;
import org.junit.Test;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.BeanFactoryChannelResolver;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.message.GenericMessage;
/**
* @author Mark Fisher
*/
public class MailToStringTransformerParserTests {
@Test
public void topLevelTransformer() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"mailToStringTransformerParserTests.xml", this.getClass());
MessageChannel input = new BeanFactoryChannelResolver(context).resolveChannelName("input");
PollableChannel output = (PollableChannel) new BeanFactoryChannelResolver(context).resolveChannelName("output");
MimeMessage mimeMessage = EasyMock.createNiceMock(MimeMessage.class);
EasyMock.expect(mimeMessage.getContent()).andReturn("hello");
EasyMock.replay(mimeMessage);
input.send(new GenericMessage<javax.mail.Message>(mimeMessage));
Message<?> result = output.receive(0);
assertNotNull(result);
assertEquals("hello", result.getPayload());
EasyMock.verify(mimeMessage);
}
@Test
public void transformerWithinChain() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"mailToStringTransformerWithinChain.xml", this.getClass());
MessageChannel input = new BeanFactoryChannelResolver(context).resolveChannelName("input");
PollableChannel output = (PollableChannel) new BeanFactoryChannelResolver(context).resolveChannelName("output");
MimeMessage mimeMessage = EasyMock.createNiceMock(MimeMessage.class);
EasyMock.expect(mimeMessage.getContent()).andReturn("foo");
EasyMock.replay(mimeMessage);
input.send(new GenericMessage<javax.mail.Message>(mimeMessage));
Message<?> result = output.receive(0);
assertNotNull(result);
assertEquals("FOO!!!", result.getPayload());
EasyMock.verify(mimeMessage);
}
@Test(expected = BeanDefinitionStoreException.class)
public void topLevelTransformerMissingInput() {
try {
new ClassPathXmlApplicationContext("mailToStringTransformerWithoutInputChannel.xml", this.getClass());
}
catch (BeanDefinitionStoreException e) {
assertTrue(e.getMessage().contains("input-channel"));
throw e;
}
}
}

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mail="http://www.springframework.org/schema/integration/mail"
xmlns:integration="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/mail
http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd">
<integration:channel id="channel"/>
<mail:inbound-channel-adapter id="imapAdapter"
store-uri="imap:foo" java-mail-properties="props" channel="channel" auto-startup="false"/>
<mail:inbound-channel-adapter id="pop3Adapter"
store-uri="pop3:bar" java-mail-properties="props" channel="channel" auto-startup="false"/>
<util:properties id="props">
<prop key="foo">bar</prop>
</util:properties>
<integration:poller default="true">
<integration:interval-trigger interval="60" time-unit="SECONDS"/>
</integration:poller>
</beans>

View File

@@ -0,0 +1,88 @@
/*
* Copyright 2002-2009 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.mail.config;
import static org.junit.Assert.assertEquals;
import java.util.Properties;
import javax.mail.URLName;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.mail.ImapMailReceiver;
import org.springframework.integration.mail.MailReceivingMessageSource;
import org.springframework.integration.mail.Pop3MailReceiver;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Jonas Partner
* @author Mark Fisher
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class PollingMailSourceParserTests {
@Autowired
private ApplicationContext context;
@Test
public void imapAdapter() {
Object adapter = context.getBean("imapAdapter");
assertEquals(SourcePollingChannelAdapter.class, adapter.getClass());
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup"));
Object channel = context.getBean("channel");
assertEquals(channel, adapterAccessor.getPropertyValue("outputChannel"));
Object source = adapterAccessor.getPropertyValue("source");
assertEquals(MailReceivingMessageSource.class, source.getClass());
Object receiver = new DirectFieldAccessor(source).getPropertyValue("mailReceiver");
assertEquals(ImapMailReceiver.class, receiver.getClass());
DirectFieldAccessor receiverAccessor = new DirectFieldAccessor(receiver);
Object url = receiverAccessor.getPropertyValue("url");
assertEquals(new URLName("imap:foo"), url);
Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
assertEquals("bar", properties.getProperty("foo"));
}
@Test
public void pop3Adapter() {
Object adapter = context.getBean("pop3Adapter");
assertEquals(SourcePollingChannelAdapter.class, adapter.getClass());
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup"));
Object channel = context.getBean("channel");
assertEquals(channel, adapterAccessor.getPropertyValue("outputChannel"));
Object source = adapterAccessor.getPropertyValue("source");
assertEquals(MailReceivingMessageSource.class, source.getClass());
Object receiver = new DirectFieldAccessor(source).getPropertyValue("mailReceiver");
assertEquals(Pop3MailReceiver.class, receiver.getClass());
DirectFieldAccessor receiverAccessor = new DirectFieldAccessor(receiver);
Object url = receiverAccessor.getPropertyValue("url");
assertEquals(new URLName("pop3:bar"), url);
Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
assertEquals("bar", properties.getProperty("foo"));
}
}

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mail="http://www.springframework.org/schema/integration/mail"
xmlns:integration="http://wwww.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/mail
http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd">
<mail:outbound-channel-adapter id="adapterWithMailSenderReference"
mail-sender="mailSender"/>
<mail:outbound-channel-adapter id="adapterWithHostProperty"
host="somehost" username="someuser" password="somepassword"/>
<bean id="mailSender" class="org.springframework.integration.mail.StubJavaMailSender">
<constructor-arg>
<bean class="javax.mail.internet.MimeMessage">
<constructor-arg type="javax.mail.Session"><null/></constructor-arg>
</bean>
</constructor-arg>
</bean>
</beans>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration/mail"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:integration="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/mail
http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd">
<integration:channel id="input"/>
<integration:channel id="output">
<integration:queue capacity="1"/>
</integration:channel>
<mail-to-string-transformer input-channel="input" output-channel="output"/>
</beans:beans>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration/mail"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:integration="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/mail
http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd">
<integration:channel id="input"/>
<integration:channel id="output">
<integration:queue capacity="1"/>
</integration:channel>
<integration:chain id="chain" input-channel="input" output-channel="output">
<mail-to-string-transformer/>
<integration:service-activator ref="exclaimer"/>
</integration:chain>
<beans:bean id="exclaimer" class="org.springframework.integration.mail.config.Exclaimer"/>
</beans:beans>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration/mail"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:integration="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/mail
http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd">
<integration:channel id="output">
<integration:queue capacity="1"/>
</integration:channel>
<mail-to-string-transformer output-channel="output"/>
</beans:beans>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="javaMailSender" class="org.springframework.integration.mail.StubJavaMailSender">
<constructor-arg>
<bean class="javax.mail.internet.MimeMessage">
<constructor-arg type="javax.mail.Session"><null/></constructor-arg>
</bean>
</constructor-arg>
</bean>
<bean id="mailSendingMessageConsumer" class="org.springframework.integration.mail.MailSendingMessageHandler">
<constructor-arg ref="javaMailSender"/>
</bean>
</beans>