use of org.springframework.ws.client.WebServiceIOException in project spring-integration by spring-projects.
the class UriVariableTests method testInt2720JmsUriVariables.
@Test
public void testInt2720JmsUriVariables() throws JMSException, IOException {
final String destinationName = "SPRING.INTEGRATION.QUEUE";
Queue queue = Mockito.mock(Queue.class);
// Need for 'QueueSession#createQueue()'
Mockito.when(queue.getQueueName()).thenReturn(destinationName);
Session session = Mockito.mock(Session.class);
Mockito.when(session.createQueue(Mockito.anyString())).thenReturn(queue);
Mockito.when(session.createBytesMessage()).thenReturn(Mockito.mock(BytesMessage.class));
MessageProducer producer = Mockito.mock(MessageProducer.class);
Mockito.when(session.createProducer(queue)).thenReturn(producer);
// For this test it's enough to not go ahead. Invoked in the 'JmsSenderConnection#onSendAfterWrite' on the
// 'WebServiceTemplate#sendRequest' after invocation of our 'TestClientInterceptor'
Mockito.when(session.createTemporaryQueue()).thenThrow(new WebServiceIOException("intentional"));
Connection connection = Mockito.mock(Connection.class);
Mockito.when(connection.createSession(Mockito.anyBoolean(), Mockito.anyInt())).thenReturn(session);
Mockito.when(this.jmsConnectionFactory.createConnection()).thenReturn(connection);
Message<?> message = MessageBuilder.withPayload("<spring/>").setHeader("jmsQueue", destinationName).setHeader("deliveryMode", "NON_PERSISTENT").setHeader("jms_priority", "5").build();
try {
this.inputJms.send(message);
} catch (MessageHandlingException e) {
// expected
Class<?> causeType = e.getCause().getClass();
// offline
assertTrue(WebServiceIOException.class.equals(causeType));
}
URI uri = URI.create("jms:SPRING.INTEGRATION.QUEUE?deliveryMode=NON_PERSISTENT&priority=5");
Mockito.verify(this.jmsMessageSender).createConnection(uri);
Mockito.verify(session).createQueue(destinationName);
assertEquals("jms:" + destinationName, this.interceptor.getLastUri().toString());
Mockito.verify(producer).setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Mockito.verify(producer).setPriority(5);
}
use of org.springframework.ws.client.WebServiceIOException in project spring-integration by spring-projects.
the class UriVariableTests method testHttpUriVariables.
@Test
@SuppressWarnings("unchecked")
public void testHttpUriVariables() {
WebServiceTemplate webServiceTemplate = TestUtils.getPropertyValue(this.httpOutboundGateway, "webServiceTemplate", WebServiceTemplate.class);
webServiceTemplate = Mockito.spy(webServiceTemplate);
final AtomicReference<String> uri = new AtomicReference<>();
doAnswer(invocation -> {
uri.set(invocation.getArgument(0));
throw new WebServiceIOException("intentional");
}).when(webServiceTemplate).sendAndReceive(Mockito.anyString(), Mockito.any(WebServiceMessageCallback.class), (WebServiceMessageExtractor<Object>) Mockito.any(WebServiceMessageExtractor.class));
new DirectFieldAccessor(this.httpOutboundGateway).setPropertyValue("webServiceTemplate", webServiceTemplate);
Message<?> message = MessageBuilder.withPayload("<spring/>").setHeader("x", "integration").setHeader("param", "test1 & test2").build();
try {
this.inputHttp.send(message);
} catch (MessageHandlingException e) {
// expected
// offline
assertThat(e.getCause(), Matchers.is(Matchers.instanceOf(WebServiceIOException.class)));
}
assertEquals("http://localhost/spring-integration?param=test1%20&%20test2", uri.get());
}
use of org.springframework.ws.client.WebServiceIOException in project spring-integration by spring-projects.
the class UriVariableTests method testInt2720XmppUriVariables.
@Test
public void testInt2720XmppUriVariables() throws Exception {
willThrow(new WebServiceIOException("intentional")).given(this.xmppConnection).sendStanza(Mockito.any(Stanza.class));
Message<?> message = MessageBuilder.withPayload("<spring/>").setHeader("to", "user").build();
try {
this.inputXmpp.send(message);
} catch (MessageHandlingException e) {
// expected
Class<?> causeType = e.getCause().getClass();
// offline
assertTrue(WebServiceIOException.class.equals(causeType));
}
ArgumentCaptor<Stanza> argument = ArgumentCaptor.forClass(Stanza.class);
Mockito.verify(this.xmppConnection).sendStanza(argument.capture());
assertEquals("user@jabber.org", argument.getValue().getTo().toString());
assertEquals("xmpp:user@jabber.org", this.interceptor.getLastUri().toString());
}
Aggregations