From 1aff8abeeed56356dd16a83a0e25f94e3ab69058 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Thu, 25 Sep 2008 20:36:00 +0000 Subject: [PATCH] Removed MailHeaderGenerator. The MailSendingMessageConsumer handles the mapping of header values, but those values should be provided by a Transformer initially. --- .../mail/AbstractMailHeaderGenerator.java | 126 ------------------ .../mail/DefaultMailHeaderGenerator.java | 77 ----------- .../integration/mail/MailHeaderGenerator.java | 39 ------ .../mail/MailSendingMessageConsumer.java | 93 ++++++++----- .../mail/StaticMailHeaderGenerator.java | 90 ------------- .../config/spring-integration-mail-1.0.xsd | 1 - ...ailSendingMessageConsumerContextTests.java | 8 +- .../mail/MailSendingMessageConsumerTests.java | 31 +---- .../integration/mail/MailTestsHelper.java | 15 ++- ...MailOutboundChannelAdapterParserTests.java | 24 ---- .../mailOutboundChannelAdapterParserTests.xml | 9 +- ...mailSendingMessageConsumerContextTests.xml | 23 +--- 12 files changed, 89 insertions(+), 447 deletions(-) delete mode 100644 org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/AbstractMailHeaderGenerator.java delete mode 100644 org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/DefaultMailHeaderGenerator.java delete mode 100644 org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/MailHeaderGenerator.java delete mode 100644 org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/StaticMailHeaderGenerator.java diff --git a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/AbstractMailHeaderGenerator.java b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/AbstractMailHeaderGenerator.java deleted file mode 100644 index 342a364ba3..0000000000 --- a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/AbstractMailHeaderGenerator.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.integration.message.Message; -import org.springframework.mail.MailMessage; - -/** - * Base implementation for {@link MailHeaderGenerator MailHeaderGenerators}. - * This class is abstract. Subclasses must implement the corresponding template - * methods to retrieve the values for the mail message's subject, recipients, - * and from/reply-to addresses based on the integration {@link Message}. - * - * @author Marius Bogoevici - * @author Mark Fisher - */ -public abstract class AbstractMailHeaderGenerator implements MailHeaderGenerator { - - private final Log logger = LogFactory.getLog(this.getClass()); - - - /** - * Retrieve the subject of an e-mail message from an integration message. - * - * @param message the integration {@link Message} - * @return the e-mail message subject - */ - protected abstract String getSubject(Message message); - - /** - * Retrieve the recipients list from an integration message. - * - * @param message the integration {@link Message} - * @return recipients list (TO) - */ - protected abstract String[] getTo(Message message); - - /** - * Retrieve the CC recipients list from an integration message. - * - * @param message the integration {@link Message} - * @return CC recipients list (e-mail addresses) - */ - protected abstract String[] getCc(Message message); - - /** - * Retrieve the BCC recipients list from an integration message. - * - * @param message the integration {@link Message} - * @return BCC recipients list (e-mail addresses) - */ - protected abstract String[] getBcc(Message message); - - /** - * Retrieve the From: e-mail address from an integration message. - * - * @param message the integration {@link Message} - * @return the From: e-mail address - */ - protected abstract String getFrom(Message message); - - /** - * Retrieve the Reply To: e-mail address from an integration message. - * - * @param message the integration {@link Message} - * @return the ReplyTo: e-mail address - */ - protected abstract String getReplyTo(Message message); - - /** - * Populate the mail message using the results of the template methods. - */ - public final void populateMailMessageHeader(MailMessage mailMessage, Message message) { - final String subject = getSubject(message); - final String[] to = getTo(message); - final String[] cc = getCc(message); - final String[] bcc = getBcc(message); - final String from = getFrom(message); - final String replyTo = getReplyTo(message); - if (subject != null) { - mailMessage.setSubject(subject); - } - else if (logger.isWarnEnabled()) { - logger.warn("no 'SUBJECT' property available for mail message"); - } - if (to != null) { - mailMessage.setTo(to); - } - else if (logger.isWarnEnabled()) { - logger.warn("no 'TO' property available for mail message"); - } - if (cc != null) { - mailMessage.setCc(cc); - } - if (bcc != null) { - mailMessage.setBcc(bcc); - } - if (from != null) { - mailMessage.setFrom(from); - } - else if (logger.isWarnEnabled()) { - logger.warn("no 'FROM' property available for mail message"); - } - if (replyTo != null) { - mailMessage.setReplyTo(replyTo); - } - } - -} diff --git a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/DefaultMailHeaderGenerator.java b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/DefaultMailHeaderGenerator.java deleted file mode 100644 index 880d72c676..0000000000 --- a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/DefaultMailHeaderGenerator.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.message.Message; - -/** - * The default implementation of {@link MailHeaderGenerator}. Configures the - * {@link org.springframework.mail.MailMessage} properties based on attributes - * provided with known attribute keys as defined in {@link MailHeaders}. - * - * @author Mark Fisher - */ -public class DefaultMailHeaderGenerator extends AbstractMailHeaderGenerator { - - @Override - protected String getSubject(Message message) { - return this.retrieveAsString(message, MailHeaders.SUBJECT); - } - - @Override - protected String[] getTo(Message message) { - return this.retrieveAsStringArray(message, MailHeaders.TO); - } - - @Override - protected String[] getCc(Message message) { - return this.retrieveAsStringArray(message, MailHeaders.CC); - } - - @Override - protected String[] getBcc(Message message) { - return this.retrieveAsStringArray(message, MailHeaders.BCC); - } - - @Override - protected String getFrom(Message message) { - return this.retrieveAsString(message, MailHeaders.FROM); - } - - @Override - protected String getReplyTo(Message message) { - return this.retrieveAsString(message, MailHeaders.REPLY_TO); - } - - - private String retrieveAsString(Message message, String key) { - Object value = message.getHeaders().get(key); - return (value instanceof String) ? (String) value : null; - } - - private String[] retrieveAsStringArray(Message message, String key) { - Object value = message.getHeaders().get(key); - if (value instanceof String[]) { - return (String[]) value; - } - if (value instanceof String) { - return new String[] { (String) value }; - } - return null; - } - -} diff --git a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/MailHeaderGenerator.java b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/MailHeaderGenerator.java deleted file mode 100644 index e3a584a15d..0000000000 --- a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/MailHeaderGenerator.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.message.Message; -import org.springframework.mail.MailMessage; - -/** - * Strategy interface for generating header information for an e-mail message - * from the content of the integration message. Minimal configuration should - * include the recipients list, the subject, from/reply-to, etc. However, this - * strategy allows the implementation of more complex business logic, when these - * parameters are depending on the integration message itself. - * - * @author Marius Bogoevici - */ -public interface MailHeaderGenerator { - - /** - * Populate the e-mail message header based on the content of the - * integration message. - */ - void populateMailMessageHeader(MailMessage mailMessage, Message message); - -} diff --git a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/MailSendingMessageConsumer.java b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/MailSendingMessageConsumer.java index cdad645eed..c89b809be6 100644 --- a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/MailSendingMessageConsumer.java +++ b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/MailSendingMessageConsumer.java @@ -23,6 +23,7 @@ import org.springframework.core.io.ByteArrayResource; import org.springframework.integration.adapter.MessageMappingException; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageConsumer; +import org.springframework.integration.message.MessageHeaders; import org.springframework.mail.MailMessage; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; @@ -35,9 +36,10 @@ import org.springframework.util.Assert; * *

If the Message is an instance of {@link MailMessage}, it will be passed * as-is. If the Message payload is a byte array, it will be passed as an - * attachment, and the {@link MailHeaders#ATTACHMENT_FILENAME} header is - * required. For any other payload type, a {@link SimpleMailMessage} will be - * created with the payload's toString() value as the Mail text. + * attachment, and in that case, the {@link MailHeaders#ATTACHMENT_FILENAME} + * header is required. For any other payload type, a {@link SimpleMailMessage} + * will be created with the payload's toString() value as the Mail + * text. * * @see MailHeaders * @@ -48,8 +50,6 @@ public class MailSendingMessageConsumer implements MessageConsumer { private final JavaMailSender mailSender; - private volatile MailHeaderGenerator mailHeaderGenerator = new DefaultMailHeaderGenerator(); - /** * Create a MailSendingMessageConsumer. @@ -63,34 +63,8 @@ public class MailSendingMessageConsumer implements MessageConsumer { } - public void setHeaderGenerator(MailHeaderGenerator mailHeaderGenerator) { - Assert.notNull(mailHeaderGenerator, "'mailHeaderGenerator' must not be null"); - this.mailHeaderGenerator = mailHeaderGenerator; - } - public final void onMessage(Message message) { MailMessage mailMessage = this.convertMessageToMailMessage(message); - this.mailHeaderGenerator.populateMailMessageHeader(mailMessage, message); - this.sendMailMessage(mailMessage); - } - - @SuppressWarnings("unchecked") - private MailMessage convertMessageToMailMessage(Message message) { - MailMessage mailMessage = null; - if (message.getPayload() instanceof MailMessage) { - mailMessage = (MailMessage) message.getPayload(); - } - else if (message.getPayload() instanceof byte[]) { - mailMessage = this.createMailMessageFromByteArrayMessage((Message) message); - } - else { - mailMessage = new SimpleMailMessage(); - mailMessage.setText(message.getPayload().toString()); - } - return mailMessage; - } - - private void sendMailMessage(MailMessage mailMessage) { if (mailMessage instanceof SimpleMailMessage) { this.mailSender.send((SimpleMailMessage) mailMessage); } @@ -103,6 +77,23 @@ public class MailSendingMessageConsumer implements MessageConsumer { } } + @SuppressWarnings("unchecked") + private MailMessage convertMessageToMailMessage(Message message) { + if (message.getPayload() instanceof MailMessage) { + return (MailMessage) message.getPayload(); + } + MailMessage mailMessage = null; + if (message.getPayload() instanceof byte[]) { + mailMessage = this.createMailMessageFromByteArrayMessage((Message) message); + } + else { + mailMessage = new SimpleMailMessage(); + mailMessage.setText(message.getPayload().toString()); + } + this.configureHeaderValues(mailMessage, message.getHeaders()); + return mailMessage; + } + private MailMessage createMailMessageFromByteArrayMessage(Message message) { String attachmentFileName = message.getHeaders().get(MailHeaders.ATTACHMENT_FILENAME, String.class); if (attachmentFileName == null) { @@ -123,4 +114,44 @@ public class MailSendingMessageConsumer implements MessageConsumer { } } + private void configureHeaderValues(MailMessage mailMessage, MessageHeaders headers) { + String subject = headers.get(MailHeaders.SUBJECT, String.class); + if (subject != null) { + mailMessage.setSubject(subject); + } + String[] to = this.retrieveAsStringArray(headers, MailHeaders.TO); + if (to != null) { + mailMessage.setTo(to); + } + String[] cc = this.retrieveAsStringArray(headers, MailHeaders.CC); + if (cc != null) { + mailMessage.setCc(cc); + } + String[] bcc = this.retrieveAsStringArray(headers, MailHeaders.BCC); + if (bcc != null) { + mailMessage.setBcc(bcc); + } + String from = headers.get(MailHeaders.FROM, String.class); + if (from != null) { + mailMessage.setFrom(from); + } + String replyTo = headers.get(MailHeaders.REPLY_TO, String.class); + if (replyTo != null) { + mailMessage.setReplyTo(replyTo); + } + } + + private String[] retrieveAsStringArray(MessageHeaders headers, String key) { + Object value = headers.get(key); + if (value != null) { + if (value instanceof String[]) { + return (String[]) value; + } + if (value instanceof String) { + return new String[] { (String) value }; + } + } + return null; + } + } diff --git a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/StaticMailHeaderGenerator.java b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/StaticMailHeaderGenerator.java deleted file mode 100644 index 3902dde8bf..0000000000 --- a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/StaticMailHeaderGenerator.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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 org.springframework.integration.message.Message; - -/** - * Mail header generator implementation that populates a mail message header - * from statically configured properties. - * - * @author Marius Bogoevici - */ -public class StaticMailHeaderGenerator extends AbstractMailHeaderGenerator { - - private String subject; - - private String[] to; - - private String[] cc; - - private String[] bcc; - - private String from; - - private String replyTo; - - - public void setSubject(String subject) { - this.subject = subject; - } - - protected String getSubject(Message message) { - return this.subject; - } - - public void setTo(String[] to) { - this.to = to; - } - - protected String[] getTo(Message message) { - return this.to; - } - - public void setCc(String[] cc) { - this.cc = cc; - } - - protected String[] getCc(Message message) { - return this.cc; - } - - public void setBcc(String[] bcc) { - this.bcc = bcc; - } - - protected String[] getBcc(Message message) { - return this.bcc; - } - - public void setFrom(String from) { - this.from = from; - } - - protected String getFrom(Message message) { - return this.from; - } - - public void setReplyTo(String replyTo) { - this.replyTo = replyTo; - } - - protected String getReplyTo(Message message) { - return this.replyTo; - } - -} diff --git a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/spring-integration-mail-1.0.xsd b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/spring-integration-mail-1.0.xsd index a3979f5033..8fd57381f3 100644 --- a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/spring-integration-mail-1.0.xsd +++ b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/spring-integration-mail-1.0.xsd @@ -25,7 +25,6 @@ - diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/MailSendingMessageConsumerContextTests.java b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/MailSendingMessageConsumerContextTests.java index 65e4498540..65e22257b4 100644 --- a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/MailSendingMessageConsumerContextTests.java +++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/MailSendingMessageConsumerContextTests.java @@ -34,7 +34,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.adapter.MessageMappingException; import org.springframework.integration.message.GenericMessage; import org.springframework.integration.message.MessageBuilder; -import org.springframework.integration.message.StringMessage; import org.springframework.mail.SimpleMailMessage; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -60,14 +59,14 @@ public class MailSendingMessageConsumerContextTests { @Test public void stringMesssagesWithConfiguration() { - this.consumer.onMessage(new StringMessage(MailTestsHelper.MESSAGE_TEXT)); - SimpleMailMessage message = MailTestsHelper.createSimpleMailMessage(); + this.consumer.onMessage(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", - message, this.mailSender.getSentSimpleMailMessages().get(0)); + mailMessage, this.mailSender.getSentSimpleMailMessages().get(0)); } @Test @@ -76,6 +75,7 @@ public class MailSendingMessageConsumerContextTests { org.springframework.integration.message.Message message = MessageBuilder.withPayload(payload) .setHeader(MailHeaders.ATTACHMENT_FILENAME, "attachment.txt") + .setHeader(MailHeaders.TO, MailTestsHelper.TO) .build(); this.consumer.onMessage(message); assertEquals("no mime message should have been sent", diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/MailSendingMessageConsumerTests.java b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/MailSendingMessageConsumerTests.java index 26d5212f2e..1907d6a52a 100644 --- a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/MailSendingMessageConsumerTests.java +++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/MailSendingMessageConsumerTests.java @@ -32,7 +32,6 @@ import org.junit.Before; import org.junit.Test; import org.springframework.integration.message.MessageBuilder; -import org.springframework.integration.message.StringMessage; import org.springframework.mail.SimpleMailMessage; /** @@ -44,19 +43,10 @@ public class MailSendingMessageConsumerTests { private StubJavaMailSender mailSender; - private StaticMailHeaderGenerator staticMailHeaderGenerator; - @Before public void setUp() throws Exception { this.mailSender = new StubJavaMailSender(new MimeMessage((Session) null)); - this.staticMailHeaderGenerator = new StaticMailHeaderGenerator(); - this.staticMailHeaderGenerator.setBcc(MailTestsHelper.BCC); - this.staticMailHeaderGenerator.setCc(MailTestsHelper.CC); - this.staticMailHeaderGenerator.setFrom(MailTestsHelper.FROM); - this.staticMailHeaderGenerator.setReplyTo(MailTestsHelper.REPLY_TO); - this.staticMailHeaderGenerator.setSubject(MailTestsHelper.SUBJECT); - this.staticMailHeaderGenerator.setTo(MailTestsHelper.TO); this.consumer = new MailSendingMessageConsumer(this.mailSender); } @@ -68,24 +58,23 @@ public class MailSendingMessageConsumerTests { @Test public void textMessage() { - this.consumer.setHeaderGenerator(this.staticMailHeaderGenerator); - this.consumer.onMessage(new StringMessage(MailTestsHelper.MESSAGE_TEXT)); - SimpleMailMessage message = MailTestsHelper.createSimpleMailMessage(); + this.consumer.onMessage(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", - message, mailSender.getSentSimpleMailMessages().get(0)); + mailMessage, mailSender.getSentSimpleMailMessages().get(0)); } @Test public void byteArrayMessage() throws Exception { - this.consumer.setHeaderGenerator(this.staticMailHeaderGenerator); byte[] payload = {1, 2, 3}; org.springframework.integration.message.Message message = MessageBuilder.withPayload(payload) .setHeader(MailHeaders.ATTACHMENT_FILENAME, "attachment.txt") + .setHeader(MailHeaders.TO, MailTestsHelper.TO) .build(); this.consumer.onMessage(message); byte[] buffer = new byte[1024]; @@ -100,16 +89,8 @@ public class MailSendingMessageConsumerTests { } @Test - public void defaultMailHeaderGenerator() { - org.springframework.integration.message.Message message = - 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(); - this.consumer.onMessage(message); + public void mailHeaders() { + this.consumer.onMessage(MailTestsHelper.createIntegrationMessage()); SimpleMailMessage mailMessage = MailTestsHelper.createSimpleMailMessage(); assertEquals("no mime message should have been sent", 0, mailSender.getSentMimeMessages().size()); diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/MailTestsHelper.java b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/MailTestsHelper.java index 001ef519b5..a212c99b0c 100644 --- a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/MailTestsHelper.java +++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/MailTestsHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * 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. @@ -16,6 +16,8 @@ package org.springframework.integration.mail; +import org.springframework.integration.message.Message; +import org.springframework.integration.message.MessageBuilder; import org.springframework.mail.SimpleMailMessage; /** @@ -53,4 +55,15 @@ public class MailTestsHelper { return message; } + public static Message 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(); + } + } diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/MailOutboundChannelAdapterParserTests.java b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/MailOutboundChannelAdapterParserTests.java index 62e8bbf959..e4305bb4a1 100644 --- a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/MailOutboundChannelAdapterParserTests.java +++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/MailOutboundChannelAdapterParserTests.java @@ -16,7 +16,6 @@ package org.springframework.integration.mail.config; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.junit.Test; @@ -24,10 +23,7 @@ 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.MailHeaderGenerator; import org.springframework.integration.mail.MailSendingMessageConsumer; -import org.springframework.integration.message.Message; -import org.springframework.mail.MailMessage; import org.springframework.mail.MailSender; /** @@ -59,24 +55,4 @@ public class MailOutboundChannelAdapterParserTests { assertNotNull(mailSender); } - @Test - public void adapterWithHeaderGeneratorReference() { - ApplicationContext context = new ClassPathXmlApplicationContext( - "mailOutboundChannelAdapterParserTests.xml", this.getClass()); - Object adapter = context.getBean("adapterWithHeaderGeneratorReference.adapter"); - MailSendingMessageConsumer consumer = (MailSendingMessageConsumer) - new DirectFieldAccessor(adapter).getPropertyValue("consumer"); - DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(consumer); - MailHeaderGenerator headerGenerator = (MailHeaderGenerator) - fieldAccessor.getPropertyValue("mailHeaderGenerator"); - assertEquals(TestHeaderGenerator.class, headerGenerator.getClass()); - } - - - public static class TestHeaderGenerator implements MailHeaderGenerator { - - public void populateMailMessageHeader(MailMessage mailMessage, Message message) { - } - } - } diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailOutboundChannelAdapterParserTests.xml b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailOutboundChannelAdapterParserTests.xml index e19ee8afa8..e891b930f7 100644 --- a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailOutboundChannelAdapterParserTests.xml +++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailOutboundChannelAdapterParserTests.xml @@ -7,15 +7,12 @@ http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail-1.0.xsd"> - + - - @@ -24,6 +21,4 @@ - - \ No newline at end of file diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/mailSendingMessageConsumerContextTests.xml b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/mailSendingMessageConsumerContextTests.xml index 5cf0c3aa71..413766aa4a 100644 --- a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/mailSendingMessageConsumerContextTests.xml +++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/mailSendingMessageConsumerContextTests.xml @@ -17,27 +17,6 @@ - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file