Fixing tests.
This commit is contained in:
@@ -162,7 +162,7 @@ public class WebServiceTemplateTest {
|
||||
|
||||
connectionMock.send(isA(WebServiceMessage.class));
|
||||
expect(connectionMock.hasError()).andReturn(false);
|
||||
expect(connectionMock.hasFault()).andReturn(true).times(2);
|
||||
expect(connectionMock.hasFault()).andReturn(true);
|
||||
expect(connectionMock.receive(messageFactory)).andReturn(response);
|
||||
connectionMock.close();
|
||||
|
||||
@@ -305,7 +305,6 @@ public class WebServiceTemplateTest {
|
||||
connectionMock.send(isA(WebServiceMessage.class));
|
||||
expect(connectionMock.hasError()).andReturn(false);
|
||||
expect(connectionMock.receive(messageFactory)).andReturn(null);
|
||||
expect(connectionMock.hasFault()).andReturn(false);
|
||||
connectionMock.close();
|
||||
|
||||
replay(connectionMock, marshallerMock);
|
||||
@@ -403,7 +402,6 @@ public class WebServiceTemplateTest {
|
||||
expect(connectionMock.hasError()).andReturn(false);
|
||||
expect(connectionMock.receive(messageFactory)).andReturn(new MockWebServiceMessage("<response/>"));
|
||||
expect(connectionMock.hasFault()).andReturn(false);
|
||||
connectionMock.close();
|
||||
|
||||
replay(connectionMock, interceptorMock1, interceptorMock2, requestCallback, extractorMock);
|
||||
|
||||
|
||||
@@ -23,7 +23,10 @@ import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
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;
|
||||
import org.springframework.ws.server.EndpointAdapter;
|
||||
@@ -35,19 +38,22 @@ import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.ws.soap.server.SoapMessageDispatcher;
|
||||
|
||||
public class PayloadRootAnnotationMethodEndpointMappingTest extends AbstractDependencyInjectionSpringContextTests {
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("applicationContext.xml")
|
||||
public class PayloadRootAnnotationMethodEndpointMappingTest {
|
||||
|
||||
@Autowired
|
||||
private PayloadRootAnnotationMethodEndpointMapping mapping;
|
||||
|
||||
@Override
|
||||
protected String getConfigPath() {
|
||||
return "applicationContext.xml";
|
||||
}
|
||||
|
||||
public void setMapping(PayloadRootAnnotationMethodEndpointMapping mapping) {
|
||||
this.mapping = mapping;
|
||||
}
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testRegistration() throws NoSuchMethodException {
|
||||
MethodEndpoint endpoint = mapping.lookupEndpoint("{http://springframework.org/spring-ws}Request");
|
||||
assertNotNull("MethodEndpoint not registered", endpoint);
|
||||
@@ -59,6 +65,7 @@ public class PayloadRootAnnotationMethodEndpointMappingTest extends AbstractDepe
|
||||
mapping.lookupEndpoint("{http://springframework.org/spring-ws}Request2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvoke() throws Exception {
|
||||
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
|
||||
@@ -23,25 +23,24 @@ import javax.xml.soap.MimeHeaders;
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
|
||||
public abstract class AbstractWsAddressingTestCase extends XMLTestCase {
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Before;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public abstract class AbstractWsAddressingTestCase {
|
||||
|
||||
protected MessageFactory messageFactory;
|
||||
|
||||
@Override
|
||||
protected final void setUp() throws Exception {
|
||||
@Before
|
||||
public void createMessageFactory() throws Exception {
|
||||
messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
onSetUp();
|
||||
}
|
||||
|
||||
protected void onSetUp() throws Exception {
|
||||
}
|
||||
|
||||
protected SaajSoapMessage loadSaajMessage(String fileName) throws SOAPException, IOException {
|
||||
MimeHeaders mimeHeaders = new MimeHeaders();
|
||||
@@ -59,6 +58,6 @@ public abstract class AbstractWsAddressingTestCase extends XMLTestCase {
|
||||
protected void assertXMLEqual(String message, SaajSoapMessage expected, SaajSoapMessage result) {
|
||||
Document expectedDocument = expected.getSaajMessage().getSOAPPart();
|
||||
Document resultDocument = result.getSaajMessage().getSOAPPart();
|
||||
assertXMLEqual(message, expectedDocument, resultDocument);
|
||||
org.custommonkey.xmlunit.XMLAssert.assertXMLEqual(message, expectedDocument, resultDocument);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,6 @@ import javax.xml.soap.SOAPElement;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.ws.soap.addressing.AbstractWsAddressingTestCase;
|
||||
import org.springframework.ws.soap.addressing.core.EndpointReference;
|
||||
import org.springframework.ws.soap.addressing.messageid.MessageIdStrategy;
|
||||
@@ -36,74 +34,74 @@ import org.springframework.ws.transport.context.DefaultTransportContext;
|
||||
import org.springframework.ws.transport.context.TransportContext;
|
||||
import org.springframework.ws.transport.context.TransportContextHolder;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public abstract class AbstractActionCallbackTestCase extends AbstractWsAddressingTestCase {
|
||||
|
||||
private ActionCallback callback;
|
||||
|
||||
private MockControl strategyControl;
|
||||
|
||||
private MessageIdStrategy strategyMock;
|
||||
|
||||
private MockControl connectionControl;
|
||||
|
||||
private WebServiceConnection connectionMock;
|
||||
|
||||
@Override
|
||||
protected final void onSetUp() throws Exception {
|
||||
strategyControl = MockControl.createControl(MessageIdStrategy.class);
|
||||
strategyMock = (MessageIdStrategy) strategyControl.getMock();
|
||||
@Before
|
||||
public void createMocks() throws Exception {
|
||||
strategyMock = createMock(MessageIdStrategy.class);
|
||||
|
||||
connectionMock = createMock(WebServiceConnection.class);
|
||||
|
||||
connectionControl = MockControl.createControl(WebServiceConnection.class);
|
||||
connectionMock = (WebServiceConnection) connectionControl.getMock();
|
||||
TransportContext transportContext = new DefaultTransportContext(connectionMock);
|
||||
TransportContextHolder.setTransportContext(transportContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
@After
|
||||
public void clearContext() throws Exception {
|
||||
TransportContextHolder.setTransportContext(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValid() throws Exception {
|
||||
URI action = new URI("http://example.com/fabrikam/mail/Delete");
|
||||
URI to = new URI("mailto:fabrikam@example.com");
|
||||
callback = new ActionCallback(action, getVersion(), to);
|
||||
callback.setMessageIdStrategy(strategyMock);
|
||||
SaajSoapMessage message = createDeleteMessage();
|
||||
strategyControl
|
||||
.expectAndReturn(strategyMock.newMessageId(message), new URI("http://example.com/someuniquestring"));
|
||||
expect(strategyMock.newMessageId(message)).andReturn(new URI("http://example.com/someuniquestring"));
|
||||
callback.setReplyTo(new EndpointReference(new URI("http://example.com/business/client1")));
|
||||
strategyControl.replay();
|
||||
connectionControl.replay();
|
||||
|
||||
replay(strategyMock, connectionMock);
|
||||
|
||||
callback.doWithMessage(message);
|
||||
|
||||
SaajSoapMessage expected = loadSaajMessage(getTestPath() + "/valid.xml");
|
||||
assertXMLEqual("Invalid message", expected, message);
|
||||
strategyControl.verify();
|
||||
connectionControl.verify();
|
||||
|
||||
verify(strategyMock, connectionMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaults() throws Exception {
|
||||
URI action = new URI("http://example.com/fabrikam/mail/Delete");
|
||||
URI connectionUri = new URI("mailto:fabrikam@example.com");
|
||||
callback = new ActionCallback(action, getVersion());
|
||||
callback.setMessageIdStrategy(strategyMock);
|
||||
connectionControl.expectAndReturn(connectionMock.getUri(), connectionUri);
|
||||
connectionControl.replay();
|
||||
expect(connectionMock.getUri()).andReturn(connectionUri);
|
||||
|
||||
SaajSoapMessage message = createDeleteMessage();
|
||||
strategyControl
|
||||
.expectAndReturn(strategyMock.newMessageId(message), new URI("http://example.com/someuniquestring"));
|
||||
expect(strategyMock.newMessageId(message)).andReturn(new URI("http://example.com/someuniquestring"));
|
||||
callback.setReplyTo(new EndpointReference(new URI("http://example.com/business/client1")));
|
||||
strategyControl.replay();
|
||||
|
||||
replay(strategyMock, connectionMock);
|
||||
|
||||
callback.doWithMessage(message);
|
||||
|
||||
SaajSoapMessage expected = loadSaajMessage(getTestPath() + "/valid.xml");
|
||||
assertXMLEqual("Invalid message", expected, message);
|
||||
strategyControl.verify();
|
||||
connectionControl.verify();
|
||||
verify(strategyMock, connectionMock);
|
||||
}
|
||||
|
||||
private SaajSoapMessage createDeleteMessage() throws SOAPException {
|
||||
|
||||
@@ -20,8 +20,6 @@ import java.net.URI;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapHeaderElement;
|
||||
@@ -34,118 +32,144 @@ import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.ws.transport.WebServiceConnection;
|
||||
import org.springframework.ws.transport.WebServiceMessageSender;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public abstract class AbstractAddressingInterceptorTestCase extends AbstractWsAddressingTestCase {
|
||||
|
||||
protected AddressingEndpointInterceptor interceptor;
|
||||
|
||||
protected MockControl strategyControl;
|
||||
|
||||
protected MessageIdStrategy strategyMock;
|
||||
|
||||
@Override
|
||||
protected final void onSetUp() throws Exception {
|
||||
strategyControl = MockControl.createControl(MessageIdStrategy.class);
|
||||
strategyMock = (MessageIdStrategy) strategyControl.getMock();
|
||||
strategyControl.expectAndDefaultReturn(strategyMock.isDuplicate(null), false);
|
||||
@Before
|
||||
public void createMocks() throws Exception {
|
||||
strategyMock = createMock(MessageIdStrategy.class);
|
||||
expect(strategyMock.isDuplicate(isA(URI.class))).andReturn(false).anyTimes();
|
||||
URI replyAction = new URI("urn:replyAction");
|
||||
URI faultAction = new URI("urn:faultAction");
|
||||
interceptor = new AddressingEndpointInterceptor(getVersion(), strategyMock, new WebServiceMessageSender[0],
|
||||
replyAction, faultAction);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnderstands() throws Exception {
|
||||
SaajSoapMessage validRequest = loadSaajMessage(getTestPath() + "/valid.xml");
|
||||
Iterator iterator = validRequest.getSoapHeader().examineAllHeaderElements();
|
||||
strategyControl.replay();
|
||||
Iterator<SoapHeaderElement> iterator = validRequest.getSoapHeader().examineAllHeaderElements();
|
||||
|
||||
replay(strategyMock);
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
SoapHeaderElement headerElement = (SoapHeaderElement) iterator.next();
|
||||
SoapHeaderElement headerElement = iterator.next();
|
||||
assertTrue("Header [" + headerElement.getName() + " not understood",
|
||||
interceptor.understands(headerElement));
|
||||
}
|
||||
strategyControl.verify();
|
||||
|
||||
verify(strategyMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidRequest() throws Exception {
|
||||
SaajSoapMessage valid = loadSaajMessage(getTestPath() + "/valid.xml");
|
||||
MessageContext context = new DefaultMessageContext(valid, new SaajSoapMessageFactory(messageFactory));
|
||||
strategyControl.replay();
|
||||
|
||||
replay(strategyMock);
|
||||
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertTrue("Valid request not handled", result);
|
||||
assertFalse("Message Context has response", context.hasResponse());
|
||||
strategyControl.verify();
|
||||
|
||||
verify(strategyMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoMessageId() throws Exception {
|
||||
SaajSoapMessage valid = loadSaajMessage(getTestPath() + "/request-no-message-id.xml");
|
||||
MessageContext context = new DefaultMessageContext(valid, new SaajSoapMessageFactory(messageFactory));
|
||||
strategyControl.replay();
|
||||
|
||||
replay(strategyMock);
|
||||
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertFalse("Request with no MessageID handled", result);
|
||||
assertTrue("Message Context has no response", context.hasResponse());
|
||||
SaajSoapMessage expectedResponse = loadSaajMessage(getTestPath() + "/response-no-message-id.xml");
|
||||
assertXMLEqual("Invalid response for message with no MessageID", expectedResponse,
|
||||
(SaajSoapMessage) context.getResponse());
|
||||
strategyControl.verify();
|
||||
|
||||
verify(strategyMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoReplyTo() throws Exception {
|
||||
SaajSoapMessage valid = loadSaajMessage(getTestPath() + "/request-no-reply-to.xml");
|
||||
MessageContext context = new DefaultMessageContext(valid, new SaajSoapMessageFactory(messageFactory));
|
||||
URI messageId = new URI("uid:1234");
|
||||
strategyControl.expectAndReturn(strategyMock.newMessageId((SoapMessage) context.getResponse()), messageId);
|
||||
strategyControl.replay();
|
||||
|
||||
expect(strategyMock.newMessageId((SoapMessage) context.getResponse())).andReturn(messageId);
|
||||
replay(strategyMock);
|
||||
|
||||
boolean result = interceptor.handleResponse(context, null);
|
||||
assertTrue("Request with no ReplyTo not handled", result);
|
||||
assertTrue("Message Context has no response", context.hasResponse());
|
||||
SaajSoapMessage expectedResponse = loadSaajMessage(getTestPath() + "/response-anonymous.xml");
|
||||
assertXMLEqual("Invalid response for message with invalid MAP", expectedResponse,
|
||||
(SaajSoapMessage) context.getResponse());
|
||||
strategyControl.verify();
|
||||
|
||||
verify(strategyMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnonymousReplyTo() throws Exception {
|
||||
SaajSoapMessage valid = loadSaajMessage(getTestPath() + "/request-anonymous.xml");
|
||||
MessageContext context = new DefaultMessageContext(valid, new SaajSoapMessageFactory(messageFactory));
|
||||
URI messageId = new URI("uid:1234");
|
||||
strategyControl.expectAndReturn(strategyMock.newMessageId((SoapMessage) context.getResponse()), messageId);
|
||||
strategyControl.replay();
|
||||
|
||||
expect(strategyMock.newMessageId((SoapMessage) context.getResponse())).andReturn(messageId);
|
||||
replay(strategyMock);
|
||||
|
||||
boolean result = interceptor.handleResponse(context, null);
|
||||
assertTrue("Request with anonymous ReplyTo not handled", result);
|
||||
SaajSoapMessage expectedResponse = loadSaajMessage(getTestPath() + "/response-anonymous.xml");
|
||||
assertXMLEqual("Invalid response for message with invalid MAP", expectedResponse,
|
||||
(SaajSoapMessage) context.getResponse());
|
||||
strategyControl.verify();
|
||||
|
||||
verify(strategyMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoneReplyTo() throws Exception {
|
||||
SaajSoapMessage valid = loadSaajMessage(getTestPath() + "/request-none.xml");
|
||||
MessageContext context = new DefaultMessageContext(valid, new SaajSoapMessageFactory(messageFactory));
|
||||
strategyControl.replay();
|
||||
replay(strategyMock);
|
||||
boolean result = interceptor.handleResponse(context, null);
|
||||
assertFalse("None request handled", result);
|
||||
assertFalse("Message context has response", context.hasResponse());
|
||||
strategyControl.verify();
|
||||
verify(strategyMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFaultTo() throws Exception {
|
||||
SaajSoapMessage valid = loadSaajMessage(getTestPath() + "/request-fault-to.xml");
|
||||
MessageContext context = new DefaultMessageContext(valid, new SaajSoapMessageFactory(messageFactory));
|
||||
SaajSoapMessage response = (SaajSoapMessage) context.getResponse();
|
||||
response.getSoapBody().addServerOrReceiverFault("Error", Locale.ENGLISH);
|
||||
URI messageId = new URI("uid:1234");
|
||||
strategyControl.expectAndReturn(strategyMock.newMessageId((SoapMessage) context.getResponse()), messageId);
|
||||
strategyControl.replay();
|
||||
expect(strategyMock.newMessageId((SoapMessage) context.getResponse())).andReturn(messageId);
|
||||
replay(strategyMock);
|
||||
boolean result = interceptor.handleFault(context, null);
|
||||
assertTrue("Request with anonymous FaultTo not handled", result);
|
||||
SaajSoapMessage expectedResponse = loadSaajMessage(getTestPath() + "/response-fault-to.xml");
|
||||
assertXMLEqual("Invalid response for message with invalid MAP", expectedResponse,
|
||||
(SaajSoapMessage) context.getResponse());
|
||||
strategyControl.verify();
|
||||
verify(strategyMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutOfBandReplyTo() throws Exception {
|
||||
MockControl senderControl = MockControl.createControl(WebServiceMessageSender.class);
|
||||
WebServiceMessageSender senderMock = (WebServiceMessageSender) senderControl.getMock();
|
||||
WebServiceMessageSender senderMock = createMock(WebServiceMessageSender.class);
|
||||
|
||||
URI replyAction = new URI("urn:replyAction");
|
||||
URI faultAction = new URI("urn:replyAction");
|
||||
@@ -153,33 +177,28 @@ public abstract class AbstractAddressingInterceptorTestCase extends AbstractWsAd
|
||||
new AddressingEndpointInterceptor(getVersion(), strategyMock, new WebServiceMessageSender[]{senderMock},
|
||||
replyAction, faultAction);
|
||||
|
||||
MockControl connectionControl = MockControl.createControl(WebServiceConnection.class);
|
||||
WebServiceConnection connectionMock = (WebServiceConnection) connectionControl.getMock();
|
||||
WebServiceConnection connectionMock = createMock(WebServiceConnection.class);
|
||||
|
||||
SaajSoapMessage valid = loadSaajMessage(getTestPath() + "/valid.xml");
|
||||
MessageContext context = new DefaultMessageContext(valid, new SaajSoapMessageFactory(messageFactory));
|
||||
SaajSoapMessage response = (SaajSoapMessage) context.getResponse();
|
||||
|
||||
URI messageId = new URI("uid:1234");
|
||||
strategyControl.expectAndReturn(strategyMock.newMessageId((SoapMessage) context.getResponse()), messageId);
|
||||
expect(strategyMock.newMessageId((SoapMessage) context.getResponse())).andReturn(messageId);
|
||||
|
||||
URI uri = new URI("http://example.com/business/client1");
|
||||
senderControl.expectAndReturn(senderMock.supports(uri), true);
|
||||
senderControl.expectAndReturn(senderMock.createConnection(uri), connectionMock);
|
||||
expect(senderMock.supports(uri)).andReturn(true);
|
||||
expect(senderMock.createConnection(uri)).andReturn(connectionMock);
|
||||
connectionMock.send(response);
|
||||
connectionMock.close();
|
||||
|
||||
strategyControl.replay();
|
||||
senderControl.replay();
|
||||
connectionControl.replay();
|
||||
replay(strategyMock, senderMock, connectionMock);
|
||||
|
||||
boolean result = interceptor.handleResponse(context, null);
|
||||
assertFalse("Out of Band request handled", result);
|
||||
assertFalse("Message context has response", context.hasResponse());
|
||||
|
||||
strategyControl.verify();
|
||||
senderControl.verify();
|
||||
connectionControl.verify();
|
||||
verify(strategyMock, senderMock, connectionMock);
|
||||
}
|
||||
|
||||
protected abstract AddressingVersion getVersion();
|
||||
|
||||
@@ -26,6 +26,9 @@ import org.springframework.ws.soap.addressing.version.AddressingVersion;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class AddressingInterceptor10Test extends AbstractAddressingInterceptorTestCase {
|
||||
|
||||
@Override
|
||||
@@ -42,15 +45,15 @@ public class AddressingInterceptor10Test extends AbstractAddressingInterceptorTe
|
||||
SaajSoapMessage valid = loadSaajMessage(getTestPath() + "/request-no-to.xml");
|
||||
MessageContext context = new DefaultMessageContext(valid, new SaajSoapMessageFactory(messageFactory));
|
||||
URI messageId = new URI("uid:1234");
|
||||
strategyControl.expectAndReturn(strategyMock.newMessageId((SoapMessage) context.getResponse()), messageId);
|
||||
strategyControl.replay();
|
||||
expect(strategyMock.newMessageId((SoapMessage) context.getResponse())).andReturn(messageId);
|
||||
replay(strategyMock);
|
||||
boolean result = interceptor.handleResponse(context, null);
|
||||
assertTrue("Request with no To not handled", result);
|
||||
assertTrue("Message Context has no response", context.hasResponse());
|
||||
SaajSoapMessage expectedResponse = loadSaajMessage(getTestPath() + "/response-anonymous.xml");
|
||||
assertXMLEqual("Invalid response for message with invalid MAP", expectedResponse,
|
||||
(SaajSoapMessage) context.getResponse());
|
||||
strategyControl.verify();
|
||||
verify(strategyMock);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,9 +23,6 @@ import javax.xml.soap.MimeHeaders;
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
@@ -37,7 +34,14 @@ import org.springframework.ws.soap.addressing.server.annotation.Address;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
|
||||
public class AnnotationActionMethodEndpointMappingTest extends XMLTestCase {
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class AnnotationActionMethodEndpointMappingTest {
|
||||
|
||||
private StaticApplicationContext applicationContext;
|
||||
|
||||
@@ -45,8 +49,8 @@ public class AnnotationActionMethodEndpointMappingTest extends XMLTestCase {
|
||||
|
||||
private MessageFactory messageFactory;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
applicationContext = new StaticApplicationContext();
|
||||
@@ -54,26 +58,28 @@ public class AnnotationActionMethodEndpointMappingTest extends XMLTestCase {
|
||||
mapping = (AnnotationActionEndpointMapping) applicationContext.getBean("mapping");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoAddress() throws Exception {
|
||||
applicationContext.registerSingleton("endpoint", Endpoint1.class);
|
||||
applicationContext.refresh();
|
||||
MessageContext messageContext = createMessageContext();
|
||||
|
||||
EndpointInvocationChain chain = mapping.getEndpoint(messageContext);
|
||||
assertNotNull("MethodEndpoint not registered", chain);
|
||||
Assert.assertNotNull("MethodEndpoint not registered", chain);
|
||||
MethodEndpoint expected = new MethodEndpoint(applicationContext.getBean("endpoint"), "doIt", new Class[0]);
|
||||
assertEquals("Invalid endpoint registered", expected, chain.getEndpoint());
|
||||
Assert.assertEquals("Invalid endpoint registered", expected, chain.getEndpoint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddress() throws Exception {
|
||||
applicationContext.registerSingleton("endpoint", Endpoint2.class);
|
||||
applicationContext.refresh();
|
||||
MessageContext messageContext = createMessageContext();
|
||||
|
||||
EndpointInvocationChain chain = mapping.getEndpoint(messageContext);
|
||||
assertNotNull("MethodEndpoint not registered", chain);
|
||||
Assert.assertNotNull("MethodEndpoint not registered", chain);
|
||||
MethodEndpoint expected = new MethodEndpoint(applicationContext.getBean("endpoint"), "doIt", new Class[0]);
|
||||
assertEquals("Invalid endpoint registered", expected, chain.getEndpoint());
|
||||
Assert.assertEquals("Invalid endpoint registered", expected, chain.getEndpoint());
|
||||
}
|
||||
|
||||
private MessageContext createMessageContext() throws SOAPException, IOException {
|
||||
|
||||
@@ -30,16 +30,21 @@ import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class SimpleActionEndpointMappingTest extends AbstractWsAddressingTestCase {
|
||||
|
||||
private SimpleActionEndpointMapping mapping;
|
||||
|
||||
private Endpoint1 endpoint1;
|
||||
|
||||
@Override
|
||||
protected void onSetUp() throws Exception {
|
||||
@Before
|
||||
public void createMappings() throws Exception {
|
||||
mapping = new SimpleActionEndpointMapping();
|
||||
Map map = new HashMap();
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
endpoint1 = new Endpoint1();
|
||||
Endpoint2 endpoint2 = new Endpoint2();
|
||||
map.put("http://example.com/fabrikam/mail/Delete", endpoint1);
|
||||
@@ -51,6 +56,7 @@ public class SimpleActionEndpointMappingTest extends AbstractWsAddressingTestCas
|
||||
mapping.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatch() throws Exception {
|
||||
SaajSoapMessage message = loadSaajMessage("200408/valid.xml");
|
||||
MessageContext messageContext = new DefaultMessageContext(message, new SaajSoapMessageFactory(messageFactory));
|
||||
@@ -65,6 +71,7 @@ public class SimpleActionEndpointMappingTest extends AbstractWsAddressingTestCas
|
||||
assertTrue("Invalid first interceptor", interceptors[2] instanceof PayloadValidatingInterceptor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoMatch() throws Exception {
|
||||
SaajSoapMessage message = loadSaajMessage("200408/response-no-message-id.xml");
|
||||
MessageContext messageContext = new DefaultMessageContext(message, new SaajSoapMessageFactory(messageFactory));
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
|
||||
|
||||
<aop:aspectj-autoproxy/>
|
||||
|
||||
<bean id="mapping"
|
||||
class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"/>
|
||||
|
||||
<bean id="endpoint" class="org.springframework.ws.server.endpoint.mapping.PayloadRootEndpoint"/>
|
||||
|
||||
<bean id="other" class="org.springframework.ws.server.endpoint.mapping.OtherBean"/>
|
||||
|
||||
<bean id="logAspect" class="org.springframework.ws.server.endpoint.mapping.LogAspect"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,17 @@
|
||||
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope"
|
||||
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
|
||||
xmlns:f123="http://www.fabrikam123.example/svc53">
|
||||
<S:Header>
|
||||
<wsa:MessageID>uuid:aaaabbbb-cccc-dddd-eeee-ffffffffffff</wsa:MessageID>
|
||||
<wsa:ReplyTo>
|
||||
<wsa:Address>http://example.com/business/client1</wsa:Address>
|
||||
</wsa:ReplyTo>
|
||||
<wsa:To S:mustUnderstand="true">mailto:joe@fabrikam123.example</wsa:To>
|
||||
<wsa:Action>http://fabrikam123.example/mail/Delete</wsa:Action>
|
||||
</S:Header>
|
||||
<S:Body>
|
||||
<f123:Delete>
|
||||
<maxCount>42</maxCount>
|
||||
</f123:Delete>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
||||
Reference in New Issue
Block a user