From 5bc41bc60bacd72de31a57dec0de0a09d15fe050 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 7 Jun 2012 15:03:39 +0300 Subject: [PATCH] INT-1029: Support for outbound-gateways in chain XSD refactoring: remove use="required" from 'request-channel' attribute of all 'outbound-gateways' Tests for all 'outbound-gateways' inside the --- .../config/spring-integration-amqp-2.2.xsd | 2 +- ...AmqpOutboundGatewayParserTests-context.xml | 29 ++++-- .../AmqpOutboundGatewayParserTests.java | 91 +++++++++++++++---- .../config/spring-integration-file-2.2.xsd | 80 ++++++++-------- ...utboundGatewayIntegrationTests-context.xml | 8 +- .../FileOutboundGatewayIntegrationTests.java | 23 ++++- .../ftp/config/spring-integration-ftp-2.2.xsd | 13 ++- ...> FtpOutboundInsideChainTests-context.xml} | 17 +++- ...andlerTests.java => FtpOutboundTests.java} | 53 +++++++++-- .../config/spring-integration-http-2.2.xsd | 29 ++++-- ... HttpOutboundWithinChainTests-context.xml} | 14 ++- ...tpRequestExecutingMessageHandlerTests.java | 23 ++++- .../ip/config/spring-integration-ip-2.2.xsd | 2 +- .../TcpConfigOutboundGatewayTests-context.xml | 30 ++++-- .../ip/tcp/TcpConfigOutboundGatewayTests.java | 50 +++++++--- ...hannelAdapterWithinChainTests-context.xml} | 0 .../ip/tcp/TcpSendingMessageHandlerTests.java | 2 +- .../config/spring-integration-jdbc-2.2.xsd | 5 +- ...yWithNamespaceIntegrationTests-context.xml | 28 ++++-- ...dGatewayWithNamespaceIntegrationTests.java | 47 +++++++++- .../JdbcOutboundGatewayParserTests.java | 28 ++++-- ...dlingMapPayloadJdbcOutboundGatewayTest.xml | 13 ++- .../jmx/config/spring-integration-jmx-2.2.xsd | 4 +- ...onInvokingOutboundGatewayTests-context.xml | 11 ++- ...OperationInvokingOutboundGatewayTests.java | 19 +++- .../config/xml/spring-integration-jpa-2.2.xsd | 2 +- .../JpaOutboundGatewayTests-context.xml | 24 ++++- .../jpa/outbound/JpaOutboundGatewayTests.java | 38 ++++++-- .../jpa/outbound/StudentService.java | 3 + .../rmi/config/spring-integration-rmi-2.2.xsd | 29 ++++-- .../config/RmiOutboundGatewayParserTests.java | 25 ++++- .../config/rmiOutboundGatewayParserTests.xml | 38 ++++++-- .../config/spring-integration-sftp-2.2.xsd | 3 +- ... SftpOutboundInsideChainTests-context.xml} | 15 ++- ...ndlerTests.java => SftpOutboundTests.java} | 65 ++++++++++--- .../SimpleWebServiceOutboundGatewayTests.java | 57 +++++++++++- ...utboundGatewayInsideChainTests-context.xml | 25 +++++ 37 files changed, 731 insertions(+), 214 deletions(-) rename spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/{FtpOutboundChannelAdapterInsideChainTests-context.xml => FtpOutboundInsideChainTests-context.xml} (74%) rename spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/{FtpSendingMessageHandlerTests.java => FtpOutboundTests.java} (76%) rename spring-integration-http/src/test/java/org/springframework/integration/http/outbound/{HttpOutboundChannelAdapterWithinChainTests-context.xml => HttpOutboundWithinChainTests-context.xml} (71%) rename spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/{TcpOutboundChannelAdapterWithinTests-context.xml => TcpOutboundChannelAdapterWithinChainTests-context.xml} (100%) rename spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/{SftpOutboundChannelAdapterInsideChainTests-context.xml => SftpOutboundInsideChainTests-context.xml} (65%) rename spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/{SftpSendingMessageHandlerTests.java => SftpOutboundTests.java} (76%) create mode 100644 spring-integration-ws/src/test/java/org/springframework/integration/ws/WebServiceOutboundGatewayInsideChainTests-context.xml diff --git a/spring-integration-amqp/src/main/resources/org/springframework/integration/amqp/config/spring-integration-amqp-2.2.xsd b/spring-integration-amqp/src/main/resources/org/springframework/integration/amqp/config/spring-integration-amqp-2.2.xsd index 44ba3adeec..13db8c0d1e 100644 --- a/spring-integration-amqp/src/main/resources/org/springframework/integration/amqp/config/spring-integration-amqp-2.2.xsd +++ b/spring-integration-amqp/src/main/resources/org/springframework/integration/amqp/config/spring-integration-amqp-2.2.xsd @@ -135,7 +135,7 @@ - + Message Channel to which Messages should be sent in order to have them converted and published to an AMQP Exchange. diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests-context.xml b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests-context.xml index df3572f9a6..74cf4dcdba 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests-context.xml +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests-context.xml @@ -13,44 +13,45 @@ reply-channel="fromRabbit" exchange-name="si.test.exchange" routing-key="si.test.binding" - amqp-template="amqpTemplate" + amqp-template="amqpTemplate" order="5" return-channel="returnChannel"/> - + - + - + + - + - + - + @@ -59,4 +60,12 @@ + + + + diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests.java index d35901fa1d..1e76f3c754 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * 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. @@ -16,6 +16,7 @@ package org.springframework.integration.amqp.config; import java.lang.reflect.Field; +import java.util.List; import org.junit.Test; import org.mockito.Mockito; @@ -44,6 +45,7 @@ import static org.junit.Assert.assertTrue; /** * @author Oleg Zhurakousky * @author Gary Russell + * @author Artem Bilan * @since 2.1 * */ @@ -61,20 +63,20 @@ public class AmqpOutboundGatewayParserTests { MessageChannel returnChannel = context.getBean("returnChannel", MessageChannel.class); assertSame(returnChannel, TestUtils.getPropertyValue(gateway, "returnChannel")); } - + @SuppressWarnings("rawtypes") @Test public void withHeaderMapperCustomRequestResponse() { ApplicationContext context = new ClassPathXmlApplicationContext("AmqpOutboundGatewayParserTests-context.xml", this.getClass()); Object eventDrivernConsumer = context.getBean("withHeaderMapperCustomRequestResponse"); - + AmqpOutboundEndpoint endpoint = TestUtils.getPropertyValue(eventDrivernConsumer, "handler", AmqpOutboundEndpoint.class); - + Field amqpTemplateField = ReflectionUtils.findField(AmqpOutboundEndpoint.class, "amqpTemplate"); amqpTemplateField.setAccessible(true); RabbitTemplate amqpTemplate = TestUtils.getPropertyValue(endpoint, "amqpTemplate", RabbitTemplate.class); amqpTemplate = Mockito.spy(amqpTemplate); - + Mockito.doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); @@ -95,9 +97,9 @@ public class AmqpOutboundGatewayParserTests { MessageChannel requestChannel = context.getBean("toRabbit", MessageChannel.class); Message message = MessageBuilder.withPayload("hello").setHeader("foo", "foo").build(); requestChannel.send(message); - + Mockito.verify(amqpTemplate, Mockito.times(1)).sendAndReceive(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(org.springframework.amqp.core.Message.class)); - + // verify reply QueueChannel queueChannel = context.getBean("fromRabbit", QueueChannel.class); Message replyMessage = queueChannel.receive(0); @@ -108,20 +110,20 @@ public class AmqpOutboundGatewayParserTests { assertNull(replyMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE)); assertNull(replyMessage.getHeaders().get(AmqpHeaders.APP_ID)); } - + @SuppressWarnings("rawtypes") @Test public void withHeaderMapperCustomAndStandardResponse() { ApplicationContext context = new ClassPathXmlApplicationContext("AmqpOutboundGatewayParserTests-context.xml", this.getClass()); Object eventDrivernConsumer = context.getBean("withHeaderMapperCustomAndStandardResponse"); - + AmqpOutboundEndpoint endpoint = TestUtils.getPropertyValue(eventDrivernConsumer, "handler", AmqpOutboundEndpoint.class); - + Field amqpTemplateField = ReflectionUtils.findField(AmqpOutboundEndpoint.class, "amqpTemplate"); amqpTemplateField.setAccessible(true); RabbitTemplate amqpTemplate = TestUtils.getPropertyValue(endpoint, "amqpTemplate", RabbitTemplate.class); amqpTemplate = Mockito.spy(amqpTemplate); - + Mockito.doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); @@ -142,9 +144,9 @@ public class AmqpOutboundGatewayParserTests { MessageChannel requestChannel = context.getBean("toRabbit", MessageChannel.class); Message message = MessageBuilder.withPayload("hello").setHeader("foo", "foo").build(); requestChannel.send(message); - + Mockito.verify(amqpTemplate, Mockito.times(1)).sendAndReceive(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(org.springframework.amqp.core.Message.class)); - + // verify reply QueueChannel queueChannel = context.getBean("fromRabbit", QueueChannel.class); Message replyMessage = queueChannel.receive(0); @@ -155,20 +157,20 @@ public class AmqpOutboundGatewayParserTests { assertNotNull(replyMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE)); assertNotNull(replyMessage.getHeaders().get(AmqpHeaders.APP_ID)); } - + @SuppressWarnings("rawtypes") @Test public void withHeaderMapperNothingToMap() { ApplicationContext context = new ClassPathXmlApplicationContext("AmqpOutboundGatewayParserTests-context.xml", this.getClass()); Object eventDrivernConsumer = context.getBean("withHeaderMapperNothingToMap"); - + AmqpOutboundEndpoint endpoint = TestUtils.getPropertyValue(eventDrivernConsumer, "handler", AmqpOutboundEndpoint.class); - + Field amqpTemplateField = ReflectionUtils.findField(AmqpOutboundEndpoint.class, "amqpTemplate"); amqpTemplateField.setAccessible(true); RabbitTemplate amqpTemplate = TestUtils.getPropertyValue(endpoint, "amqpTemplate", RabbitTemplate.class); amqpTemplate = Mockito.spy(amqpTemplate); - + Mockito.doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); @@ -189,9 +191,9 @@ public class AmqpOutboundGatewayParserTests { MessageChannel requestChannel = context.getBean("toRabbit", MessageChannel.class); Message message = MessageBuilder.withPayload("hello").setHeader("foo", "foo").build(); requestChannel.send(message); - + Mockito.verify(amqpTemplate, Mockito.times(1)).sendAndReceive(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(org.springframework.amqp.core.Message.class)); - + // verify reply QueueChannel queueChannel = context.getBean("fromRabbit", QueueChannel.class); Message replyMessage = queueChannel.receive(0); @@ -202,4 +204,55 @@ public class AmqpOutboundGatewayParserTests { assertNull(replyMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE)); assertNull(replyMessage.getHeaders().get(AmqpHeaders.APP_ID)); } + + @Test //INT-1029 + public void amqpOutboundGatewayWithinChain() { + ApplicationContext context = new ClassPathXmlApplicationContext("AmqpOutboundGatewayParserTests-context.xml", this.getClass()); + Object eventDrivernConsumer = context.getBean("chainWithRabbitOutboundGateway"); + + List chainHandlers = TestUtils.getPropertyValue(eventDrivernConsumer, "handler.handlers", List.class); + + AmqpOutboundEndpoint endpoint = (AmqpOutboundEndpoint) chainHandlers.get(0); + + Field amqpTemplateField = ReflectionUtils.findField(AmqpOutboundEndpoint.class, "amqpTemplate"); + amqpTemplateField.setAccessible(true); + RabbitTemplate amqpTemplate = TestUtils.getPropertyValue(endpoint, "amqpTemplate", RabbitTemplate.class); + amqpTemplate = Mockito.spy(amqpTemplate); + + Mockito.doAnswer(new Answer() { + public Object answer(InvocationOnMock invocation) { + Object[] args = invocation.getArguments(); + org.springframework.amqp.core.Message amqpRequestMessage = (org.springframework.amqp.core.Message) args[2]; + MessageProperties properties = amqpRequestMessage.getMessageProperties(); + assertNull(properties.getHeaders().get("foo")); + // mock reply AMQP message + MessageProperties amqpProperties = new MessageProperties(); + amqpProperties.setAppId("test.appId"); + amqpProperties.setHeader("foobar", "foobar"); + amqpProperties.setHeader("bar", "bar"); + return new org.springframework.amqp.core.Message("hello".getBytes(), amqpProperties); + }}) + .when(amqpTemplate).sendAndReceive(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(org.springframework.amqp.core.Message.class)); + ReflectionUtils.setField(amqpTemplateField, endpoint, amqpTemplate); + + + MessageChannel requestChannel = context.getBean("toRabbit", MessageChannel.class); + Message message = MessageBuilder.withPayload("hello").setHeader("foo", "foo").build(); + requestChannel.send(message); + + Mockito.verify(amqpTemplate, Mockito.times(1)).sendAndReceive(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(org.springframework.amqp.core.Message.class)); + + // verify reply + QueueChannel queueChannel = context.getBean("fromRabbit", QueueChannel.class); + Message replyMessage = queueChannel.receive(0); + assertEquals("hello", new String((byte[]) replyMessage.getPayload())); + assertNull(replyMessage.getHeaders().get("bar")); + assertEquals("foo", replyMessage.getHeaders().get("foo")); // copied from request Message + assertNull(replyMessage.getHeaders().get("foobar")); + assertNull(replyMessage.getHeaders().get(AmqpHeaders.DELIVERY_MODE)); + assertNull(replyMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE)); + assertNull(replyMessage.getHeaders().get(AmqpHeaders.APP_ID)); + + } + } diff --git a/spring-integration-file/src/main/resources/org/springframework/integration/file/config/spring-integration-file-2.2.xsd b/spring-integration-file/src/main/resources/org/springframework/integration/file/config/spring-integration-file-2.2.xsd index 7fc0e6f3ef..1c854e6d60 100644 --- a/spring-integration-file/src/main/resources/org/springframework/integration/file/config/spring-integration-file-2.2.xsd +++ b/spring-integration-file/src/main/resources/org/springframework/integration/file/config/spring-integration-file-2.2.xsd @@ -47,7 +47,7 @@ element. Therefore, if the "channel" attribute is not provided, then the "id" attribute is required. ]]> @@ -74,7 +74,7 @@ - + @@ -87,11 +87,11 @@ + ]]> @@ -144,7 +144,7 @@ Only files matching this regular expression will be picked up by this adapter. Lifecycle attribute signaling if this component should be started during Application Context startup. - + @@ -174,7 +174,7 @@ Only files matching this regular expression will be picked up by this adapter. Configures an outbound Channel Adapter that writes Message payloads to a File. - + @@ -199,11 +199,11 @@ Only files matching this regular expression will be picked up by this adapter. Configures an outbound Gateway that writes request Message payloads to a File and then generates a reply Message containing the newly written File as its payload. - + - + The channel through which outgoing messages will arrive. @@ -216,7 +216,7 @@ Only files matching this regular expression will be picked up by this adapter. - @@ -244,15 +244,15 @@ Only files matching this regular expression will be picked up by this adapter. - + - - + @@ -263,7 +263,7 @@ Only files matching this regular expression will be picked up by this adapter. - Allows you to provide a SpEL expression which will compute the file name of + Allows you to provide a SpEL expression which will compute the file name of the target file (e.g., assuming payload is java.io.File "payload.name + '.transferred'"); @@ -306,18 +306,18 @@ Only files matching this regular expression will be picked up by this adapter. - - + + - - - + + @@ -332,11 +332,11 @@ Only files matching this regular expression will be picked up by this adapter. - - + @@ -348,7 +348,7 @@ Only files matching this regular expression will be picked up by this adapter. Creates a Transformer that converts a File payload to an array of bytes. - + @@ -366,7 +366,7 @@ Only files matching this regular expression will be picked up by this adapter. - + @@ -377,10 +377,10 @@ Only files matching this regular expression will be picked up by this adapter. - - + @@ -391,27 +391,27 @@ Only files matching this regular expression will be picked up by this adapter. - - + - + - - + - + @@ -425,8 +425,8 @@ Only files matching this regular expression will be picked up by this adapter. - diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundGatewayIntegrationTests-context.xml b/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundGatewayIntegrationTests-context.xml index ba6d8f44f9..4529aa36ca 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundGatewayIntegrationTests-context.xml +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundGatewayIntegrationTests-context.xml @@ -27,11 +27,15 @@ directory="${java.io.tmpdir}/anyDir" /> + + + + diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundGatewayIntegrationTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundGatewayIntegrationTests.java index 2e61f449f3..a601c2e178 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundGatewayIntegrationTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundGatewayIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * 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. @@ -47,13 +47,12 @@ import org.springframework.util.FileCopyUtils; /** * @author Alex Peters * @author Mark Fisher + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) public class FileOutboundGatewayIntegrationTests { - FileWritingMessageHandler handler; - @Qualifier("copyInput") @Autowired MessageChannel copyInputChannel; @@ -62,6 +61,10 @@ public class FileOutboundGatewayIntegrationTests { @Autowired MessageChannel moveInputChannel; + @Qualifier("moveInput") + @Autowired + MessageChannel fileOutboundGatewayInsideChain; + @Qualifier("output") @Autowired QueueChannel outputChannel; @@ -145,4 +148,18 @@ public class FileOutboundGatewayIntegrationTests { assertThat(payloadFile.exists(), is(true)); } + @Test //INT-1029 + public void moveInsideTheChain() throws Exception { + fileOutboundGatewayInsideChain.send(message); + List> result = outputChannel.clear(); + assertThat(result.size(), is(1)); + Message resultMessage = result.get(0); + File payloadFile = (File) resultMessage.getPayload(); + assertThat(payloadFile, is(not(sourceFile))); + assertThat(resultMessage.getHeaders().get(FileHeaders.ORIGINAL_FILE, File.class), + is(sourceFile)); + assertThat(sourceFile.exists(), is(false)); + assertThat(payloadFile.exists(), is(true)); + } + } diff --git a/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.2.xsd b/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.2.xsd index 1b2d14cabf..233c830b83 100644 --- a/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.2.xsd +++ b/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.2.xsd @@ -115,7 +115,7 @@ @@ -264,8 +264,7 @@ - + @@ -403,8 +402,8 @@ - Identifies channel attached to this adapter. Depending on the type of the adapter - this channel could be the receiving channel (e.g., outbound-channel-adapter) or channel where + Identifies channel attached to this adapter. Depending on the type of the adapter + this channel could be the receiving channel (e.g., outbound-channel-adapter) or channel where messages will be sent to by this adapter (e.g., inbound-channel-adapter). @@ -419,7 +418,7 @@ - + - + diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpOutboundChannelAdapterInsideChainTests-context.xml b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpOutboundInsideChainTests-context.xml similarity index 74% rename from spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpOutboundChannelAdapterInsideChainTests-context.xml rename to spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpOutboundInsideChainTests-context.xml index 95e2cc9aa5..7601282d67 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpOutboundChannelAdapterInsideChainTests-context.xml +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpOutboundInsideChainTests-context.xml @@ -1,13 +1,10 @@ + class="org.springframework.integration.ftp.outbound.FtpOutboundTests$TestFtpSessionFactory"> + + + + + + + + + + diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpSendingMessageHandlerTests.java b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpOutboundTests.java similarity index 76% rename from spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpSendingMessageHandlerTests.java rename to spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpOutboundTests.java index 4845782a53..35fbfd4738 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpSendingMessageHandlerTests.java +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpOutboundTests.java @@ -16,6 +16,7 @@ package org.springframework.integration.ftp.outbound; +import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.mockito.Mockito.mock; @@ -24,6 +25,8 @@ import static org.mockito.Mockito.when; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; +import java.io.OutputStream; +import java.util.*; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; @@ -37,21 +40,24 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.expression.common.LiteralExpression; import org.springframework.integration.Message; import org.springframework.integration.MessageChannel; +import org.springframework.integration.core.PollableChannel; import org.springframework.integration.file.FileNameGenerator; +import org.springframework.integration.file.remote.FileInfo; import org.springframework.integration.file.remote.handler.FileTransferringMessageHandler; import org.springframework.integration.ftp.session.AbstractFtpSessionFactory; import org.springframework.integration.message.GenericMessage; +import org.springframework.integration.support.MessageBuilder; import org.springframework.util.FileCopyUtils; /** * @author Oleg Zhurakousky * @author Artem Bilan */ -public class FtpSendingMessageHandlerTests { - +public class FtpOutboundTests { + private static FTPClient ftpClient; private TestFtpSessionFactory sessionFactory; - + @Before public void prepare(){ ftpClient = mock(FTPClient.class); @@ -71,7 +77,7 @@ public class FtpSendingMessageHandlerTests { assertFalse(file.exists()); FileTransferringMessageHandler handler = new FileTransferringMessageHandler(sessionFactory); handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir")); - handler.setFileNameGenerator(new FileNameGenerator() { + handler.setFileNameGenerator(new FileNameGenerator() { public String generateFileName(Message message) { return "handlerContent.test"; } @@ -90,7 +96,7 @@ public class FtpSendingMessageHandlerTests { assertFalse(file.exists()); FileTransferringMessageHandler handler = new FileTransferringMessageHandler(sessionFactory); handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir")); - handler.setFileNameGenerator(new FileNameGenerator() { + handler.setFileNameGenerator(new FileNameGenerator() { public String generateFileName(Message message) { return "handlerContent.test"; } @@ -99,7 +105,7 @@ public class FtpSendingMessageHandlerTests { handler.handleMessage(new GenericMessage("hello".getBytes())); assertTrue(file.exists()); } - + @Test public void testHandleFileMessage() throws Exception { File targetDir = new File("remote-target-dir"); @@ -135,7 +141,7 @@ public class FtpSendingMessageHandlerTests { File destFile = new File(targetDir, srcFile.getName()); destFile.deleteOnExit(); - ApplicationContext context = new ClassPathXmlApplicationContext("FtpOutboundChannelAdapterInsideChainTests-context.xml", getClass()); + ApplicationContext context = new ClassPathXmlApplicationContext("FtpOutboundInsideChainTests-context.xml", getClass()); MessageChannel channel = context.getBean("outboundChainChannel", MessageChannel.class); @@ -143,6 +149,28 @@ public class FtpSendingMessageHandlerTests { assertTrue("destination file was not created", destFile.exists()); } + @Test //INT-2275 + public void testFtpOutboundGatewayInsideChain() throws Exception { + ApplicationContext context = new ClassPathXmlApplicationContext("FtpOutboundInsideChainTests-context.xml", getClass()); + + MessageChannel channel = context.getBean("ftpOutboundGatewayInsideChain", MessageChannel.class); + + channel.send(MessageBuilder.withPayload("remote-test-dir").build()); + + PollableChannel output = context.getBean("output", PollableChannel.class); + + Message result = output.receive(); + Object payload = result.getPayload(); + assertTrue(payload instanceof List); + @SuppressWarnings("unchecked") + List remoteFiles = (List) payload; + assertEquals(3, remoteFiles.size()); + List files = Arrays.asList(new File("remote-test-dir").list()); + for (FileInfo remoteFile : remoteFiles) { + assertTrue(files.contains(remoteFile.getFilename())); + } + } + public static class TestFtpSessionFactory extends AbstractFtpSessionFactory { @@ -170,6 +198,17 @@ public class FtpSendingMessageHandlerTests { return true; } }); + String[] files = new File("remote-test-dir").list(); + Collection ftpFiles = new ArrayList(); + for (String fileName : files) { + FTPFile file = new FTPFile(); + file.setName(fileName); + file.setType(FTPFile.FILE_TYPE); + file.setTimestamp(Calendar.getInstance()); + ftpFiles.add(file); + when(ftpClient.retrieveFile(Mockito.eq("remote-test-dir/" + fileName) , Mockito.any(OutputStream.class))).thenReturn(true); + } + when(ftpClient.listFiles("remote-test-dir/")).thenReturn(ftpFiles.toArray(new FTPFile[]{})); return ftpClient; } catch (Exception e) { throw new RuntimeException("Failed to create mock client", e); diff --git a/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.2.xsd b/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.2.xsd index f4aaa00564..ab42e738ee 100644 --- a/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.2.xsd +++ b/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.2.xsd @@ -163,6 +163,15 @@ The String "HTTP_REQUEST_HEADERS" will match against any of the standard HTTP Re + + + + + + + + + @@ -491,6 +500,15 @@ The String "HTTP_REQUEST_HEADERS" will match against any of the standard HTTP Re + + + + + + + + + @@ -714,15 +732,6 @@ The String "HTTP_REQUEST_HEADERS" will match against any of the standard HTTP Re - - - - - - - - - @@ -734,4 +743,4 @@ The String "HTTP_REQUEST_HEADERS" will match against any of the standard HTTP Re - \ No newline at end of file + diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpOutboundChannelAdapterWithinChainTests-context.xml b/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpOutboundWithinChainTests-context.xml similarity index 71% rename from spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpOutboundChannelAdapterWithinChainTests-context.xml rename to spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpOutboundWithinChainTests-context.xml index 1ad869df32..d77d40fdc2 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpOutboundChannelAdapterWithinChainTests-context.xml +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpOutboundWithinChainTests-context.xml @@ -4,11 +4,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:si="http://www.springframework.org/schema/integration" - xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd - 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/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> @@ -16,4 +14,14 @@ + + + + + + + + diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java index 52e5793013..45ed14907c 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java @@ -21,6 +21,10 @@ import static junit.framework.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; @@ -30,6 +34,10 @@ import java.util.concurrent.atomic.AtomicReference; import javax.xml.transform.Source; +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; +import org.junit.Assert; import org.junit.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.context.ApplicationContext; @@ -43,6 +51,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.integration.Message; import org.springframework.integration.MessageChannel; import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.core.PollableChannel; import org.springframework.integration.support.MessageBuilder; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestClientException; @@ -648,12 +657,24 @@ public class HttpRequestExecutingMessageHandlerTests { @Test //INT-2275 public void testOutboundChannelAdapterWithinChain() { - ApplicationContext ctx = new ClassPathXmlApplicationContext("HttpOutboundChannelAdapterWithinChainTests-context.xml", this.getClass()); + ApplicationContext ctx = new ClassPathXmlApplicationContext("HttpOutboundWithinChainTests-context.xml", this.getClass()); MessageChannel channel = ctx.getBean("httpOutboundChannelAdapterWithinChain", MessageChannel.class); channel.send(MessageBuilder.withPayload("test").build()); // It's just enough if it was sent successfully from chain without any failures } + @Test //INT-1029 + public void testHttpOutboundGatewayWithinChain() throws IOException { + ApplicationContext ctx = new ClassPathXmlApplicationContext("HttpOutboundWithinChainTests-context.xml", this.getClass()); + MessageChannel channel = ctx.getBean("httpOutboundGatewayWithinChain", MessageChannel.class); + channel.send(MessageBuilder.withPayload("test").build()); + + PollableChannel output = ctx.getBean("replyChannel", PollableChannel.class); + Message receive = output.receive(); + assertEquals(HttpStatus.OK, receive.getPayload()); + + } + @Test public void testUriExpression() { MockRestTemplate restTemplate = new MockRestTemplate(); diff --git a/spring-integration-ip/src/main/resources/org/springframework/integration/ip/config/spring-integration-ip-2.2.xsd b/spring-integration-ip/src/main/resources/org/springframework/integration/ip/config/spring-integration-ip-2.2.xsd index 874947ba37..a31a2bd95b 100644 --- a/spring-integration-ip/src/main/resources/org/springframework/integration/ip/config/spring-integration-ip-2.2.xsd +++ b/spring-integration-ip/src/main/resources/org/springframework/integration/ip/config/spring-integration-ip-2.2.xsd @@ -311,7 +311,7 @@ task executors such as a WorkManagerTaskExecutor. - + diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpConfigOutboundGatewayTests-context.xml b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpConfigOutboundGatewayTests-context.xml index a9965a1868..922ba69642 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpConfigOutboundGatewayTests-context.xml +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpConfigOutboundGatewayTests-context.xml @@ -3,29 +3,47 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration" xmlns:ip="http://www.springframework.org/schema/integration/ip" - xsi:schemaLocation="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/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd - http://www.springframework.org/schema/integration + http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd"> - - - + + + + + + + + + - + diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpConfigOutboundGatewayTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpConfigOutboundGatewayTests.java index 329a12213b..d1a9450ff2 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpConfigOutboundGatewayTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpConfigOutboundGatewayTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * 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. @@ -25,9 +25,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.integration.Message; +import org.springframework.integration.MessageChannel; import org.springframework.integration.core.PollableChannel; import org.springframework.integration.core.SubscribableChannel; import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory; +import org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory; import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory; import org.springframework.integration.support.MessageBuilder; import org.springframework.test.context.ContextConfiguration; @@ -35,6 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Gary Russell + * @author Artem Bilan * @since 2.0 */ @ContextConfiguration @@ -45,50 +48,50 @@ public class TcpConfigOutboundGatewayTests { @Autowired AbstractApplicationContext ctx; - + @Autowired @Qualifier(value="crLfServer") AbstractServerConnectionFactory crLfServer; - + @Autowired @Qualifier(value="stxEtxServer") AbstractServerConnectionFactory stxEtxServer; - + @Autowired @Qualifier(value="lengthHeaderServer") AbstractServerConnectionFactory lengthHeaderServer; - + @Autowired @Qualifier(value="javaSerialServer") AbstractServerConnectionFactory javaSerialServer; - + @Autowired @Qualifier(value="crLfClient") AbstractClientConnectionFactory crLfClient; - + @Autowired @Qualifier(value="stxEtxClient") AbstractClientConnectionFactory stxEtxClient; - + @Autowired @Qualifier(value="lengthHeaderClient") AbstractClientConnectionFactory lengthHeaderClient; - + @Autowired @Qualifier(value="javaSerialClient") AbstractClientConnectionFactory javaSerialClient; - + @Autowired @Qualifier(value="gatewayCrLf") TcpInboundGateway gatewayCrLf; - + // @Autowired // @Qualifier("gatewayCrLf") // private TcpInboundGateway inboundGatewayCrLf; - + @Autowired @Qualifier("gatewayStxEtx") private TcpInboundGateway inboundGatewayStxEtx; - + @Autowired @Qualifier("gatewayLength") private TcpInboundGateway inboundGatewayLength; @@ -109,6 +112,12 @@ public class TcpConfigOutboundGatewayTests { @Qualifier("requestChannelNio") SubscribableChannel requestChannelNio; + @Autowired + AbstractClientConnectionFactory crLfClient2; + + @Autowired + MessageChannel tcpOutboundGatewayInsideChain; + @Test public void testOutboundCrLf() throws Exception { testOutboundUsingConfig(); @@ -127,7 +136,7 @@ public class TcpConfigOutboundGatewayTests { throw new Exception("Gateway failed to listen"); } } - + } @Test @@ -166,6 +175,17 @@ public class TcpConfigOutboundGatewayTests { assertEquals("echo:test", new String(bytes)); } + @Test //INT-1029 + public void testOutboundInsideChain() throws Exception { +// TODO Lifecycle#start() isn't invoked within chain... + crLfClient2.start(); + + tcpOutboundGatewayInsideChain.send(MessageBuilder.withPayload("test").build()); + byte[] bytes = (byte[]) replyChannel.receive().getPayload(); + assertEquals("echo:test", new String(bytes).trim()); + } + + private void testOutboundUsingConfig() { Message message = MessageBuilder.withPayload("test").build(); requestChannel.send(message); @@ -186,7 +206,7 @@ public class TcpConfigOutboundGatewayTests { staticContext = ctx; } } - + @AfterClass public static void shutDown() { staticContext.close(); diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpOutboundChannelAdapterWithinTests-context.xml b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpOutboundChannelAdapterWithinChainTests-context.xml similarity index 100% rename from spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpOutboundChannelAdapterWithinTests-context.xml rename to spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpOutboundChannelAdapterWithinChainTests-context.xml diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandlerTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandlerTests.java index 55c2b4c395..508a692fcb 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandlerTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandlerTests.java @@ -1064,7 +1064,7 @@ public class TcpSendingMessageHandlerTests { @Test public void testOutboundChannelAdapterWithinChain() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext( - "TcpOutboundChannelAdapterWithinTests-context.xml", this.getClass()); + "TcpOutboundChannelAdapterWithinChainTests-context.xml", this.getClass()); AbstractConnectionFactory ccf = ctx.getBean("ccf", AbstractConnectionFactory.class); // TODO Lifecycle#start() isn't invoked within chain... ccf.start(); diff --git a/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.2.xsd b/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.2.xsd index 28a04ee98a..1217053ebb 100644 --- a/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.2.xsd +++ b/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.2.xsd @@ -401,7 +401,7 @@ - + The receiving Message Channel of this endpoint. @@ -865,8 +865,7 @@ - + The receiving Message Channel of this endpoint. diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundGatewayWithNamespaceIntegrationTests-context.xml b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundGatewayWithNamespaceIntegrationTests-context.xml index 79e004e653..e973c1e097 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundGatewayWithNamespaceIntegrationTests-context.xml +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundGatewayWithNamespaceIntegrationTests-context.xml @@ -2,17 +2,10 @@ + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> @@ -37,6 +30,7 @@ + @@ -44,4 +38,20 @@ + + + + + + + + + + + + + diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundGatewayWithNamespaceIntegrationTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundGatewayWithNamespaceIntegrationTests.java index 502d237620..5ea654876c 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundGatewayWithNamespaceIntegrationTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundGatewayWithNamespaceIntegrationTests.java @@ -33,21 +33,28 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.integration.Message; +import org.springframework.integration.MessageChannel; import org.springframework.integration.annotation.ServiceActivator; +import org.springframework.integration.core.PollableChannel; import org.springframework.integration.jdbc.storedproc.CreateUser; import org.springframework.integration.jdbc.storedproc.User; +import org.springframework.integration.support.MessageBuilder; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import javax.sql.DataSource; + /** * @author Gunnar Hillert + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) public class StoredProcOutboundGatewayWithNamespaceIntegrationTests { @Autowired - private AbstractApplicationContext context; + DataSource dataSource; @Autowired private Consumer consumer; @@ -55,6 +62,12 @@ public class StoredProcOutboundGatewayWithNamespaceIntegrationTests { @Autowired CreateUser createUser; + @Autowired + MessageChannel storedProcOutboundGatewayInsideChain; + + @Autowired + PollableChannel replyChannel; + @Test public void test() throws Exception { @@ -65,10 +78,38 @@ public class StoredProcOutboundGatewayWithNamespaceIntegrationTests { received.add(consumer.poll(2000)); Message> message = received.get(0); - context.stop(); + + assertNotNull(message); + assertNotNull(message.getPayload()); + + Collection allUsers = message.getPayload(); + + assertTrue(allUsers.size() == 1); + + User userFromDb = allUsers.iterator().next(); + + assertEquals("Wrong username", "myUsername", userFromDb.getUsername()); + assertEquals("Wrong password", "myPassword", userFromDb.getPassword()); + assertEquals("Wrong email", "myEmail", userFromDb.getEmail()); + + } + + @Test //INT-1029 + public void testStoredProcOutboundGatewayInsideChain() throws Exception { + + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); + + jdbcTemplate.execute("delete from USERS"); + + Message requestMessage = MessageBuilder.withPayload(new User("myUsername", "myPassword", "myEmail")).build(); + + storedProcOutboundGatewayInsideChain.send(requestMessage); + + @SuppressWarnings("unchecked") + Message> message = (Message>) replyChannel.receive(); + assertNotNull(message); assertNotNull(message.getPayload()); - assertNotNull(message.getPayload() instanceof Collection); Collection allUsers = message.getPayload(); diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcOutboundGatewayParserTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcOutboundGatewayParserTests.java index f46b8ea18e..78f632b0a4 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcOutboundGatewayParserTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcOutboundGatewayParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * 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 @@ -41,6 +41,7 @@ import org.springframework.jdbc.core.JdbcTemplate; * @author Dave Syer * @author Oleg Zhurakousky * @author Gary Russell + * @author Artem Bilan * @since 2.0 * */ @@ -99,7 +100,7 @@ public class JdbcOutboundGatewayParserTests { Map payload = (Map) reply.getPayload(); assertEquals(1, payload.get("updated")); } - + @Test public void testWithPoller() throws Exception{ ApplicationContext ac = new ClassPathXmlApplicationContext("JdbcOutboundGatewayWithPollerTest-context.xml", this.getClass()); @@ -123,21 +124,21 @@ public class JdbcOutboundGatewayParserTests { setUp("JdbcOutboundGatewayWithPollerTest-context.xml", getClass()); PollingConsumer outboundGateway = this.context.getBean("jdbcOutboundGateway", PollingConsumer.class); - + DirectFieldAccessor accessor = new DirectFieldAccessor(outboundGateway); Object source = accessor.getPropertyValue("handler"); accessor = new DirectFieldAccessor(source); source = accessor.getPropertyValue("messagingTemplate"); - + MessagingTemplate messagingTemplate = (MessagingTemplate) source; accessor = new DirectFieldAccessor(messagingTemplate); Long sendTimeout = (Long) accessor.getPropertyValue("sendTimeout"); assertEquals("Wrong sendTimeout", Long.valueOf(444L), sendTimeout); - + } - + @Test public void testDefaultMaxMessagesPerPollIsSet() throws Exception { @@ -172,6 +173,21 @@ public class JdbcOutboundGatewayParserTests { } + @Test //INT-1029 + public void testOutboundGatewayInsideChain() { + ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("handlingMapPayloadJdbcOutboundGatewayTest.xml", getClass()); + MessageChannel channel = context.getBean("jdbcOutboundGatewayInsideChain", MessageChannel.class); + channel.send(MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build()); + + PollableChannel outbound = context.getBean("replyChannel", PollableChannel.class); + Message reply = outbound.receive(); + assertNotNull(reply); + @SuppressWarnings("unchecked") + Map payload = (Map) reply.getPayload(); + assertEquals("bar", payload.get("name")); + } + + @After public void tearDown() { if (context != null) { diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/handlingMapPayloadJdbcOutboundGatewayTest.xml b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/handlingMapPayloadJdbcOutboundGatewayTest.xml index ba4ce248c8..d081186d5e 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/handlingMapPayloadJdbcOutboundGatewayTest.xml +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/handlingMapPayloadJdbcOutboundGatewayTest.xml @@ -1,10 +1,8 @@ + + + + + + + + diff --git a/spring-integration-jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.2.xsd b/spring-integration-jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.2.xsd index cb4e7badad..7f0a939f52 100644 --- a/spring-integration-jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.2.xsd +++ b/spring-integration-jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.2.xsd @@ -42,7 +42,7 @@ - + @@ -199,4 +199,4 @@ - \ No newline at end of file + diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/OperationInvokingOutboundGatewayTests-context.xml b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/OperationInvokingOutboundGatewayTests-context.xml index 18c78634be..f9742c7275 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/OperationInvokingOutboundGatewayTests-context.xml +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/OperationInvokingOutboundGatewayTests-context.xml @@ -17,18 +17,23 @@ - + - + - + + + + + diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/OperationInvokingOutboundGatewayTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/OperationInvokingOutboundGatewayTests.java index 7fe10e5ece..870df02b28 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/OperationInvokingOutboundGatewayTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/OperationInvokingOutboundGatewayTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * 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. @@ -28,12 +28,14 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.MessageChannel; import org.springframework.integration.core.PollableChannel; import org.springframework.integration.message.GenericMessage; +import org.springframework.integration.support.MessageBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Oleg Zhurakousky - * + * @author Artem Bilan + * */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -51,6 +53,9 @@ public class OperationInvokingOutboundGatewayTests { @Qualifier("withNoReplyChannel") private MessageChannel withNoReplyChannel; + @Autowired + private MessageChannel jmxOutboundGatewayInsideChain; + @Autowired private TestBean testBean; @@ -79,4 +84,14 @@ public class OperationInvokingOutboundGatewayTests { assertEquals(3, testBean.messages.size()); } + @Test //INT-1029 + public void testOutboundGatewayInsideChain() throws Exception { + jmxOutboundGatewayInsideChain.send(MessageBuilder.withPayload("1").build()); + assertEquals(1, ((List) withReplyChannelOutput.receive().getPayload()).size()); + jmxOutboundGatewayInsideChain.send(MessageBuilder.withPayload("2").build()); + assertEquals(2, ((List) withReplyChannelOutput.receive().getPayload()).size()); + jmxOutboundGatewayInsideChain.send(MessageBuilder.withPayload("3").build()); + assertEquals(3, ((List) withReplyChannelOutput.receive().getPayload()).size()); + } + } diff --git a/spring-integration-jpa/src/main/resources/org/springframework/integration/jpa/config/xml/spring-integration-jpa-2.2.xsd b/spring-integration-jpa/src/main/resources/org/springframework/integration/jpa/config/xml/spring-integration-jpa-2.2.xsd index 5a46d71e54..cca2925289 100644 --- a/spring-integration-jpa/src/main/resources/org/springframework/integration/jpa/config/xml/spring-integration-jpa-2.2.xsd +++ b/spring-integration-jpa/src/main/resources/org/springframework/integration/jpa/config/xml/spring-integration-jpa-2.2.xsd @@ -290,7 +290,7 @@ - + The receiving Message Channel of this endpoint. diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayTests-context.xml b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayTests-context.xml index 884ff802af..8051d628f3 100644 --- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayTests-context.xml +++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayTests-context.xml @@ -28,16 +28,21 @@ + + + + - + + @@ -192,4 +197,21 @@ + + + + + + + + + + + + diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayTests.java b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayTests.java index 4dfef3a5d7..3d7b6542ac 100644 --- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayTests.java +++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayTests.java @@ -16,12 +16,14 @@ import java.util.List; import junit.framework.Assert; +import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.MessagingException; import org.springframework.integration.jpa.test.JpaTestUtils; import org.springframework.integration.jpa.test.entity.StudentDomain; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -31,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional; /** * * @author Gunnar Hillert + * @author Artem Bilan * @since 2.2 * */ @@ -42,15 +45,22 @@ public class JpaOutboundGatewayTests { @Autowired private StudentService studentService; + @Autowired + JdbcTemplate jdbcTemplate; + + @After + public void cleanUp() { + this.jdbcTemplate.execute("delete from Student where rollNumber > 1003"); + } + + @Test - @DirtiesContext public void getStudent() { final StudentDomain student = studentService.getStudent(1001L); Assert.assertNotNull(student); } @Test - @DirtiesContext @Transactional public void deleteNonExistingStudent() { @@ -67,7 +77,6 @@ public class JpaOutboundGatewayTests { } @Test - @DirtiesContext public void getStudentWithException() { try { studentService.getStudentWithException(1001L); @@ -82,7 +91,6 @@ public class JpaOutboundGatewayTests { } @Test - @DirtiesContext public void getStudentStudentWithPositionalParameters() { StudentDomain student = studentService.getStudentWithParameters("First Two"); @@ -92,7 +100,6 @@ public class JpaOutboundGatewayTests { } @Test - @DirtiesContext public void getAllStudents() { final List students = studentService.getAllStudents(); @@ -102,7 +109,6 @@ public class JpaOutboundGatewayTests { } @Test - @DirtiesContext @Transactional public void persistStudent() { @@ -116,7 +122,6 @@ public class JpaOutboundGatewayTests { } @Test - @DirtiesContext @Transactional public void persistStudentUsingMerge() { @@ -129,4 +134,23 @@ public class JpaOutboundGatewayTests { } + @Test + public void testRetrievingGatewayInsideChain() { + final StudentDomain student = studentService.getStudent2(1001L); + Assert.assertNotNull(student); + } + + @Test + @Transactional + public void testUpdatingGatewayInsideChain() { + + final StudentDomain studentToPersist = JpaTestUtils.getTestStudent(); + Assert.assertNull(studentToPersist.getRollNumber()); + + final StudentDomain persistedStudent = studentService.persistStudent2(studentToPersist); + Assert.assertNotNull(persistedStudent); + Assert.assertNotNull(persistedStudent.getRollNumber()); + + } + } diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/StudentService.java b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/StudentService.java index c51fb08d51..5759f5be3e 100644 --- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/StudentService.java +++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/StudentService.java @@ -35,4 +35,7 @@ public interface StudentService { StudentDomain getStudentWithParameters(String firstName); + StudentDomain getStudent2(Long id); + + StudentDomain persistStudent2(StudentDomain studentToPersist); } diff --git a/spring-integration-rmi/src/main/resources/org/springframework/integration/rmi/config/spring-integration-rmi-2.2.xsd b/spring-integration-rmi/src/main/resources/org/springframework/integration/rmi/config/spring-integration-rmi-2.2.xsd index 1dbeacf1d4..5ed498f799 100644 --- a/spring-integration-rmi/src/main/resources/org/springframework/integration/rmi/config/spring-integration-rmi-2.2.xsd +++ b/spring-integration-rmi/src/main/resources/org/springframework/integration/rmi/config/spring-integration-rmi-2.2.xsd @@ -28,6 +28,15 @@ + + + + + + + + + @@ -57,6 +66,15 @@ + + + + + + + + + @@ -81,15 +99,6 @@ - - - - - - - - - @@ -104,4 +113,4 @@ - \ No newline at end of file + diff --git a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests.java b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests.java index cdf57c23cf..d219fcefea 100644 --- a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests.java +++ b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * 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. @@ -26,14 +26,17 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.Message; import org.springframework.integration.MessageChannel; import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.core.PollableChannel; import org.springframework.integration.message.GenericMessage; import org.springframework.integration.rmi.RmiInboundGateway; import org.springframework.integration.rmi.RmiOutboundGateway; +import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.test.util.TestUtils; /** * @author Mark Fisher * @author Gary Russell + * @author Artem Bilan */ public class RmiOutboundGatewayParserTests { @@ -67,15 +70,27 @@ public class RmiOutboundGatewayParserTests { assertEquals("test", result.getPayload()); } - @Test - public void endpointInvocation() { + @Test //INT-1029 + public void testRmiOutboundGatewayInsideChain() { ApplicationContext context = new ClassPathXmlApplicationContext( "rmiOutboundGatewayParserTests.xml", this.getClass()); - MessageChannel localChannel = (MessageChannel) context.getBean("localChannel"); - localChannel.send(new GenericMessage("test")); + MessageChannel localChannel = context.getBean("rmiOutboundGatewayInsideChain", MessageChannel.class); + localChannel.send(MessageBuilder.withPayload("test").build()); Message result = testChannel.receive(1000); assertNotNull(result); assertEquals("test", result.getPayload()); } + @Test //INT-1029 + public void testRmiRequestReplyWithinChain() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "rmiOutboundGatewayParserTests.xml", this.getClass()); + MessageChannel localChannel = context.getBean("requestReplyRmiWithChainChannel", MessageChannel.class); + localChannel.send(MessageBuilder.withPayload("test").build()); + PollableChannel replyChannel = context.getBean("replyChannel", PollableChannel.class); + Message result = replyChannel.receive(); + assertNotNull(result); + assertEquals("TEST", result.getPayload()); + } + } diff --git a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/rmiOutboundGatewayParserTests.xml b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/rmiOutboundGatewayParserTests.xml index 78bbbe6cb0..1e3c4b80ed 100644 --- a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/rmiOutboundGatewayParserTests.xml +++ b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/rmiOutboundGatewayParserTests.xml @@ -1,9 +1,9 @@ + order="23" + request-channel="localChannel" + remote-channel="testChannel" + host="localhost"/> - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-integration-sftp/src/main/resources/org/springframework/integration/sftp/config/spring-integration-sftp-2.2.xsd b/spring-integration-sftp/src/main/resources/org/springframework/integration/sftp/config/spring-integration-sftp-2.2.xsd index 860834339f..4f19ca2365 100644 --- a/spring-integration-sftp/src/main/resources/org/springframework/integration/sftp/config/spring-integration-sftp-2.2.xsd +++ b/spring-integration-sftp/src/main/resources/org/springframework/integration/sftp/config/spring-integration-sftp-2.2.xsd @@ -268,8 +268,7 @@ - + diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpOutboundChannelAdapterInsideChainTests-context.xml b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpOutboundInsideChainTests-context.xml similarity index 65% rename from spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpOutboundChannelAdapterInsideChainTests-context.xml rename to spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpOutboundInsideChainTests-context.xml index 2a097e15bc..746e121adc 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpOutboundChannelAdapterInsideChainTests-context.xml +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpOutboundInsideChainTests-context.xml @@ -11,14 +11,25 @@ http://www.springframework.org/schema/integration/sftp/spring-integration-sftp.xsd"> - + + + + + + + + + + class="org.springframework.integration.sftp.outbound.SftpOutboundTests$TestSftpSessionFactory"/> diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpSendingMessageHandlerTests.java b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpOutboundTests.java similarity index 76% rename from spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpSendingMessageHandlerTests.java rename to spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpOutboundTests.java index 15d7510883..74b32357ae 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpSendingMessageHandlerTests.java +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpOutboundTests.java @@ -16,15 +16,16 @@ package org.springframework.integration.sftp.outbound; +import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; +import java.io.*; +import java.util.*; +import com.jcraft.jsch.SftpATTRS; import org.junit.Test; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; @@ -33,14 +34,18 @@ import org.mockito.stubbing.Answer; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.expression.common.LiteralExpression; +import org.springframework.integration.Message; import org.springframework.integration.MessageChannel; +import org.springframework.integration.core.PollableChannel; import org.springframework.integration.file.DefaultFileNameGenerator; +import org.springframework.integration.file.remote.FileInfo; import org.springframework.integration.file.remote.handler.FileTransferringMessageHandler; import org.springframework.integration.file.remote.session.Session; import org.springframework.integration.file.remote.session.SessionFactory; import org.springframework.integration.message.GenericMessage; import org.springframework.integration.sftp.session.DefaultSftpSessionFactory; import org.springframework.integration.sftp.session.SftpTestSessionFactory; +import org.springframework.integration.support.MessageBuilder; import org.springframework.util.FileCopyUtils; import com.jcraft.jsch.ChannelSftp; @@ -49,8 +54,8 @@ import com.jcraft.jsch.ChannelSftp.LsEntry; /** * @author Oleg Zhurakousky */ -public class SftpSendingMessageHandlerTests { - +public class SftpOutboundTests { + private static com.jcraft.jsch.Session jschSession = mock(com.jcraft.jsch.Session.class); @Test @@ -91,7 +96,7 @@ public class SftpSendingMessageHandlerTests { handler.handleMessage(new GenericMessage("hello")); assertTrue(new File("remote-target-dir", "foo.txt").exists()); } - + @Test public void testHandleBytesMessage() throws Exception { File file = new File("remote-target-dir", "foo.txt"); @@ -120,16 +125,38 @@ public class SftpSendingMessageHandlerTests { File destFile = new File(targetDir, srcFile.getName()); destFile.deleteOnExit(); - ApplicationContext context = new ClassPathXmlApplicationContext("SftpOutboundChannelAdapterInsideChainTests-context.xml", getClass()); + ApplicationContext context = new ClassPathXmlApplicationContext("SftpOutboundInsideChainTests-context.xml", getClass()); - MessageChannel channel = context.getBean("outboundChainChannel", MessageChannel.class); + MessageChannel channel = context.getBean("outboundChannelAdapterInsideChain", MessageChannel.class); channel.send(new GenericMessage(srcFile)); assertTrue("destination file was not created", destFile.exists()); } + @Test //INT-2275 + public void testFtpOutboundGatewayInsideChain() throws Exception { + ApplicationContext context = new ClassPathXmlApplicationContext("SftpOutboundInsideChainTests-context.xml", getClass()); + + MessageChannel channel = context.getBean("outboundGatewayInsideChain", MessageChannel.class); + + channel.send(MessageBuilder.withPayload("remote-test-dir").build()); + + PollableChannel output = context.getBean("replyChannel", PollableChannel.class); + + Message result = output.receive(); + Object payload = result.getPayload(); + assertTrue(payload instanceof List); + @SuppressWarnings("unchecked") + List remoteFiles = (List) payload; + assertEquals(3, remoteFiles.size()); + List files = Arrays.asList(new File("remote-test-dir").list()); + for (FileInfo remoteFile : remoteFiles) { + assertTrue(files.contains(remoteFile.getFilename())); + } + } + public static class TestSftpSessionFactory extends DefaultSftpSessionFactory { - + @Override public Session getSession() { try { @@ -137,15 +164,15 @@ public class SftpSendingMessageHandlerTests { doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) - throws Throwable { + throws Throwable { File file = new File((String)invocation.getArguments()[1]); assertTrue(file.getName().endsWith(".writing")); FileCopyUtils.copy((InputStream)invocation.getArguments()[0], new FileOutputStream(file)); return null; } - + }).when(channel).put(Mockito.any(InputStream.class), Mockito.anyString()); - + doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) throws Throwable { @@ -155,8 +182,20 @@ public class SftpSendingMessageHandlerTests { file.renameTo(renameToFile); return null; } - + }).when(channel).rename(Mockito.anyString(), Mockito.anyString()); + + String[] files = new File("remote-test-dir").list(); + Vector sftpEntries = new Vector(); + for (String fileName : files) { + LsEntry lsEntry = mock(LsEntry.class); + SftpATTRS attributes = mock(SftpATTRS.class); + when(lsEntry.getAttrs()).thenReturn(attributes); + when(lsEntry.getFilename()).thenReturn(fileName); + sftpEntries.add(lsEntry); + } + when(channel.ls("remote-test-dir/")).thenReturn(sftpEntries); + when(jschSession.openChannel("sftp")).thenReturn(channel); return SftpTestSessionFactory.createSftpSession(jschSession); } catch (Exception e) { diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceOutboundGatewayTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceOutboundGatewayTests.java index c216747f96..579b81df91 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceOutboundGatewayTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceOutboundGatewayTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * 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. @@ -16,29 +16,52 @@ package org.springframework.integration.ws; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - +import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.URI; import java.util.concurrent.atomic.AtomicReference; import javax.xml.transform.TransformerException; +import org.hamcrest.Matchers; import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.Message; +import org.springframework.integration.MessageChannel; +import org.springframework.integration.core.PollableChannel; import org.springframework.integration.support.MessageBuilder; import org.springframework.ws.WebServiceMessage; +import org.springframework.ws.WebServiceMessageFactory; import org.springframework.ws.client.core.WebServiceMessageCallback; import org.springframework.ws.client.support.destination.DestinationProvider; import org.springframework.ws.soap.SoapMessage; +import org.springframework.ws.soap.SoapMessageFactory; +import org.springframework.ws.transport.WebServiceConnection; +import org.springframework.ws.transport.WebServiceMessageSender; +import org.springframework.xml.namespace.QNameUtils; + +import static org.junit.Assert.*; /** * @author Mark Fisher + * @author Artem Bilan * @since 2.0 */ public class SimpleWebServiceOutboundGatewayTests { + private static final String response = "Test Name"; + + private static final String responseSoapMessage = " " + + " " + + response + + " " + + ""; + @Test // INT-1051 public void soapActionAndCustomCallback() { String uri = "http://www.example.org"; @@ -66,6 +89,32 @@ public class SimpleWebServiceOutboundGatewayTests { } + @Test //INT-1029 + public void testWsOutboundGatewayInsideChain() { + ApplicationContext context = new ClassPathXmlApplicationContext("WebServiceOutboundGatewayInsideChainTests-context.xml", this.getClass()); + MessageChannel channel = context.getBean("wsOutboundGatewayInsideChain", MessageChannel.class); + channel.send(MessageBuilder.withPayload("foo").build()); + PollableChannel replyChannel = context.getBean("replyChannel", PollableChannel.class); + Message replyMessage = replyChannel.receive(); + assertThat(replyMessage.getPayload().toString(), Matchers.endsWith(response)); + } + + public static WebServiceMessageSender createMockMessageSender() throws Exception { + WebServiceMessageSender messageSender = Mockito.mock(WebServiceMessageSender.class); + WebServiceConnection wsConnection = Mockito.mock(WebServiceConnection.class); + Mockito.when(messageSender.createConnection(Mockito.any(URI.class))).thenReturn(wsConnection); + Mockito.when(messageSender.supports(Mockito.any(URI.class))).thenReturn(true); + + Mockito.doAnswer(new Answer() { + public Object answer(InvocationOnMock invocation) throws Exception{ + Object[] args = invocation.getArguments(); + WebServiceMessageFactory factory = (WebServiceMessageFactory) args[0]; + return factory.createWebServiceMessage(new ByteArrayInputStream(responseSoapMessage.getBytes())); + }}).when(wsConnection).receive(Mockito.any(WebServiceMessageFactory.class)); + + return messageSender; + } + private static class TestDestinationProvider implements DestinationProvider { private final URI uri; diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/WebServiceOutboundGatewayInsideChainTests-context.xml b/spring-integration-ws/src/test/java/org/springframework/integration/ws/WebServiceOutboundGatewayInsideChainTests-context.xml new file mode 100644 index 0000000000..24767d0edf --- /dev/null +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/WebServiceOutboundGatewayInsideChainTests-context.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + +