Allow for extensions to create faults
This commit is contained in:
@@ -24,17 +24,16 @@ import java.util.List;
|
|||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.ws.WebServiceMessage;
|
import org.springframework.ws.WebServiceMessage;
|
||||||
import org.springframework.ws.WebServiceMessageFactory;
|
import org.springframework.ws.WebServiceMessageFactory;
|
||||||
import org.springframework.ws.transport.FaultAwareWebServiceConnection;
|
import org.springframework.ws.transport.WebServiceConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock implementation of {@link FaultAwareWebServiceConnection}. Implements {@link ResponseActions} to form a fluent
|
* Mock implementation of {@link WebServiceConnection}. Implements {@link ResponseActions} to form a fluent API.
|
||||||
* API.
|
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @author Lukas Krecan
|
* @author Lukas Krecan
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
class MockSenderConnection implements FaultAwareWebServiceConnection, ResponseActions {
|
class MockSenderConnection implements WebServiceConnection, ResponseActions {
|
||||||
|
|
||||||
private final List<RequestMatcher> requestMatchers = new LinkedList<RequestMatcher>();
|
private final List<RequestMatcher> requestMatchers = new LinkedList<RequestMatcher>();
|
||||||
|
|
||||||
@@ -114,14 +113,6 @@ class MockSenderConnection implements FaultAwareWebServiceConnection, ResponseAc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasFault() throws IOException {
|
|
||||||
return responseCreator instanceof SoapFaultResponseCreator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFault(boolean fault) throws IOException {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
requestMatchers.clear();
|
requestMatchers.clear();
|
||||||
request = null;
|
request = null;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package org.springframework.ws.mock.client;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.xml.namespace.QName;
|
import javax.xml.namespace.QName;
|
||||||
import javax.xml.soap.MessageFactory;
|
import javax.xml.soap.MessageFactory;
|
||||||
@@ -31,6 +32,7 @@ import org.springframework.ws.WebServiceMessage;
|
|||||||
import org.springframework.ws.client.core.WebServiceMessageCallback;
|
import org.springframework.ws.client.core.WebServiceMessageCallback;
|
||||||
import org.springframework.ws.client.core.WebServiceTemplate;
|
import org.springframework.ws.client.core.WebServiceTemplate;
|
||||||
import org.springframework.ws.soap.SoapMessage;
|
import org.springframework.ws.soap.SoapMessage;
|
||||||
|
import org.springframework.ws.soap.client.SoapFaultClientException;
|
||||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||||
import org.springframework.xml.transform.StringResult;
|
import org.springframework.xml.transform.StringResult;
|
||||||
@@ -259,4 +261,14 @@ public class WebServiceMockTest {
|
|||||||
public void verifyOnly() throws Exception {
|
public void verifyOnly() throws Exception {
|
||||||
verifyConnections();
|
verifyConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = SoapFaultClientException.class)
|
||||||
|
public void fault() throws Exception {
|
||||||
|
Source request = new StringSource("<request xmlns='http://example.com'/>");
|
||||||
|
|
||||||
|
expect(anything()).andRespond(withClientOrSenderFault("reason", Locale.ENGLISH));
|
||||||
|
|
||||||
|
StringResult result = new StringResult();
|
||||||
|
template.sendSourceAndReceiveToResult(request, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user