From 1755dfd676aaf4a9d1ed7c68196648d54c06de30 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 10 Dec 2008 17:59:08 +0000 Subject: [PATCH] Mail transformers may now be used within a 'chain' (INT-498). --- .../config/spring-integration-mail-1.0.xsd | 4 +- .../integration/mail/config/Exclaimer.java | 28 +++++++ .../MailToStringTransformerParserTests.java | 84 +++++++++++++++++++ .../mailToStringTransformerParserTests.xml | 21 +++++ .../mailToStringTransformerWithinChain.xml | 26 ++++++ ...ToStringTransformerWithoutInputChannel.xml | 19 +++++ 6 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/Exclaimer.java create mode 100644 org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/MailToStringTransformerParserTests.java create mode 100644 org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailToStringTransformerParserTests.xml create mode 100644 org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailToStringTransformerWithinChain.xml create mode 100644 org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailToStringTransformerWithoutInputChannel.xml 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 4b45ffa1c8..295eeefefd 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 @@ -108,8 +108,8 @@ - - + + \ No newline at end of file diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/Exclaimer.java b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/Exclaimer.java new file mode 100644 index 0000000000..26f385c9d7 --- /dev/null +++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/Exclaimer.java @@ -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() + "!!!"; + } + +} diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/MailToStringTransformerParserTests.java b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/MailToStringTransformerParserTests.java new file mode 100644 index 0000000000..6c98b168f4 --- /dev/null +++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/MailToStringTransformerParserTests.java @@ -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(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(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; + } + } + +} diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailToStringTransformerParserTests.xml b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailToStringTransformerParserTests.xml new file mode 100644 index 0000000000..a99d56e945 --- /dev/null +++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailToStringTransformerParserTests.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailToStringTransformerWithinChain.xml b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailToStringTransformerWithinChain.xml new file mode 100644 index 0000000000..b1c4752176 --- /dev/null +++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailToStringTransformerWithinChain.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailToStringTransformerWithoutInputChannel.xml b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailToStringTransformerWithoutInputChannel.xml new file mode 100644 index 0000000000..acb0450a7c --- /dev/null +++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/mailToStringTransformerWithoutInputChannel.xml @@ -0,0 +1,19 @@ + + + + + + + + + +