INT-1257, changed convinience method to MessageHistory.containsComponent(string), added/modified tests in XML, WS, JMS to validate MessageHistory

This commit is contained in:
Oleg Zhurakousky
2010-09-21 17:21:50 -04:00
parent f8b501e4f9
commit 0d387756b3
14 changed files with 142 additions and 27 deletions

View File

@@ -16,9 +16,14 @@
package org.springframework.integration.ws.config;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.transform.Source;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.WebServiceMessageFactory;
@@ -28,7 +33,10 @@ import org.springframework.ws.WebServiceMessageFactory;
public class StubMessageFactory implements WebServiceMessageFactory {
public WebServiceMessage createWebServiceMessage() {
return null;
WebServiceMessage message = mock(WebServiceMessage.class);
Source source = mock(Source.class);
when(message.getPayloadSource()).thenReturn(source);
return message;
}
public WebServiceMessage createWebServiceMessage(InputStream inputStream) throws IOException {

View File

@@ -11,15 +11,25 @@
http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<si:message-history/>
<ws:inbound-gateway id="simple" request-channel="requests" />
<ws:inbound-gateway id="simple" request-channel="requestsVerySimple" />
<ws:inbound-gateway id="extractsPayload" request-channel="requests" extract-payload="false"/>
<si:channel id="requestsVerySimple"></si:channel>
<ws:inbound-gateway id="marshalling" request-channel="requests"
<ws:inbound-gateway id="extractsPayload" request-channel="requestsSimple" extract-payload="false"/>
<ws:inbound-gateway id="marshalling" request-channel="requestsMarshalling"
marshaller="marshaller" unmarshaller="marshaller" />
<si:channel id="requests" />
<si:channel id="requestsMarshalling">
<si:queue/>
</si:channel>
<si:channel id="requestsSimple">
<si:queue/>
</si:channel>
<bean id="marshaller" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.springframework.oxm.AbstractMarshaller" />

View File

@@ -15,25 +15,39 @@
*/
package org.springframework.integration.ws.config;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import javax.xml.transform.Source;
import org.junit.Test;
import org.junit.runner.RunWith;
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.core.PollableChannel;
import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.ws.MarshallingWebServiceInboundGateway;
import org.springframework.integration.ws.SimpleWebServiceInboundGateway;
import org.springframework.oxm.AbstractMarshaller;
import org.springframework.oxm.Unmarshaller;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.ws.context.DefaultMessageContext;
import org.springframework.ws.context.MessageContext;
/**
*
* @author Iwein Fuld
* @author Oleg Zhurakousky
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@@ -41,8 +55,16 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class WebServiceInboundGatewayParserTests {
@Autowired
@Qualifier("requests")
MessageChannel requestChannel;
@Qualifier("requestsMarshalling")
PollableChannel requestsMarshalling;
@Autowired
@Qualifier("requestsSimple")
PollableChannel requestsSimple;
@Autowired
@Qualifier("requestsVerySimple")
MessageChannel requestsVerySimple;
@Test
public void configOk() throws Exception {
@@ -59,7 +81,7 @@ public class WebServiceInboundGatewayParserTests {
DirectFieldAccessor accessor = new DirectFieldAccessor(simpleGateway);
assertThat(
(MessageChannel) accessor.getPropertyValue("requestChannel"),
is(requestChannel));
is(requestsVerySimple));
}
//extractPayload = false
@@ -78,6 +100,7 @@ public class WebServiceInboundGatewayParserTests {
//marshalling
@Autowired
MarshallingWebServiceInboundGateway marshallingGateway;
@Autowired
AbstractMarshaller marshaller;
@@ -90,4 +113,23 @@ public class WebServiceInboundGatewayParserTests {
is(marshaller));
assertTrue("messaging gateway is not running", marshallingGateway.isRunning());
}
@Test
public void testMessageHistoryWithMarshallingGateway() throws Exception {
MessageContext context = new DefaultMessageContext(new StubMessageFactory());
Unmarshaller unmarshaller = mock(Unmarshaller.class);
when(unmarshaller.unmarshal((Source)Mockito.any())).thenReturn("hello");
marshallingGateway.setUnmarshaller(unmarshaller);
marshallingGateway.invoke(context);
Message<?> message = requestsMarshalling.receive(100);
MessageHistory history = MessageHistory.read(message);
assertTrue(history.containsComponent("marshalling"));
}
@Test
public void testMessageHistoryWithSimpleGateway() throws Exception {
MessageContext context = new DefaultMessageContext(new StubMessageFactory());
payloadExtractingGateway.invoke(context);
Message<?> message = requestsSimple.receive(100);
MessageHistory history = MessageHistory.read(message);
assertTrue(history.containsComponent("extractsPayload"));
}
}