From a355f7ea095b91c64782968f026e076fe2c754a5 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 14 Aug 2013 13:16:40 +0300 Subject: [PATCH] INT-3109: make UriVariableTests work offline JIRA: https://jira.springsource.org/browse/INT-3109 --- .../ws/config/UriVariableTests-context.xml | 5 +- .../ws/config/UriVariableTests.java | 47 +++++++++++++++---- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests-context.xml b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests-context.xml index 8ca7a40357..09516ce8b1 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests-context.xml +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests-context.xml @@ -10,9 +10,8 @@ - + diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests.java index 01735eaf9a..99c132053b 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests.java @@ -17,12 +17,13 @@ package org.springframework.integration.ws.config; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; - +import java.util.concurrent.atomic.AtomicReference; import javax.jms.BytesMessage; import javax.jms.Connection; import javax.jms.ConnectionFactory; @@ -32,26 +33,34 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; +import org.hamcrest.Matchers; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.packet.Packet; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.Message; import org.springframework.integration.MessageChannel; import org.springframework.integration.MessageHandlingException; +import org.springframework.integration.core.MessageHandler; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.test.util.TestUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.ws.client.WebServiceClientException; import org.springframework.ws.client.WebServiceIOException; -import org.springframework.ws.client.WebServiceTransportException; +import org.springframework.ws.client.core.WebServiceMessageCallback; +import org.springframework.ws.client.core.WebServiceMessageExtractor; +import org.springframework.ws.client.core.WebServiceTemplate; import org.springframework.ws.client.support.interceptor.ClientInterceptor; import org.springframework.ws.context.MessageContext; -import org.springframework.ws.soap.SoapMessageCreationException; import org.springframework.ws.transport.WebServiceConnection; import org.springframework.ws.transport.WebServiceMessageSender; import org.springframework.ws.transport.context.TransportContext; @@ -67,6 +76,10 @@ import org.springframework.ws.transport.mail.MailSenderConnection; @ContextConfiguration public class UriVariableTests { + @Autowired + @Qualifier("httpOutboundGateway.handler") + private MessageHandler httpOutboundGateway; + @Autowired private TestClientInterceptor interceptor; @@ -95,7 +108,24 @@ public class UriVariableTests { private Int2720EmailTestClientInterceptor emailInterceptor; @Test + @SuppressWarnings("unchecked") public void testHttpUriVariables() { + WebServiceTemplate webServiceTemplate = TestUtils.getPropertyValue(this.httpOutboundGateway, "webServiceTemplate", WebServiceTemplate.class); + webServiceTemplate = Mockito.spy(webServiceTemplate); + final AtomicReference uri = new AtomicReference(); + Mockito.doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + uri.set((String) invocation.getArguments()[0]); + throw new WebServiceIOException("intentional"); + } + }).when(webServiceTemplate) + .sendAndReceive(Mockito.anyString(), + Mockito.any(WebServiceMessageCallback.class), + (WebServiceMessageExtractor) Mockito.any(WebServiceMessageExtractor.class)); + + new DirectFieldAccessor(this.httpOutboundGateway).setPropertyValue("webServiceTemplate", webServiceTemplate); + Message message = MessageBuilder.withPayload("") .setHeader("x", "integration") .setHeader("param", "test1 & test2") @@ -105,11 +135,9 @@ public class UriVariableTests { } catch (MessageHandlingException e) { // expected - Class causeType = e.getCause().getClass(); - assertTrue(WebServiceIOException.class.equals(causeType) // offline - || SoapMessageCreationException.class.equals(causeType)); + assertThat(e.getCause(), Matchers.is(Matchers.instanceOf(WebServiceIOException.class))); // offline } - assertEquals("http://test.org/spring-integration?param=test1%20%26%20test2", this.interceptor.getLastUri().toString()); + assertEquals("http://localhost/spring-integration?param=test1%20%26%20test2", uri.get()); } @Test @@ -170,7 +198,7 @@ public class UriVariableTests { catch (MessageHandlingException e) { // expected Class causeType = e.getCause().getClass(); - assertTrue(WebServiceTransportException.class.equals(causeType)); // offline + assertTrue(WebServiceIOException.class.equals(causeType)); // offline } WebServiceConnection webServiceConnection = this.emailInterceptor.getLastWebServiceConnection(); assertEquals(testEmailTo, TestUtils.getPropertyValue(webServiceConnection, "to").toString()); @@ -252,7 +280,8 @@ public class UriVariableTests { throw new IllegalStateException("expected MailSenderConnection in the TransportContext"); } - return super.handleRequest(messageContext); + super.handleRequest(messageContext); + throw new WebServiceIOException("intentional"); } }