1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.test.server;
18
19 import java.io.IOException;
20 import javax.xml.namespace.QName;
21
22 import org.springframework.ws.WebServiceMessage;
23 import org.springframework.ws.soap.SoapBody;
24 import org.springframework.ws.soap.SoapFault;
25 import org.springframework.ws.soap.SoapMessage;
26 import org.springframework.ws.soap.SoapVersion;
27
28 import static org.springframework.ws.test.support.AssertionErrors.assertEquals;
29 import static org.springframework.ws.test.support.AssertionErrors.assertTrue;
30
31
32
33
34
35
36
37 abstract class SoapFaultResponseMatcher implements ResponseMatcher {
38
39 private final String expectedFaultStringOrReason;
40
41 SoapFaultResponseMatcher(String expectedFaultStringOrReason) {
42 this.expectedFaultStringOrReason = expectedFaultStringOrReason;
43 }
44
45 public void match(WebServiceMessage request, WebServiceMessage response) throws IOException, AssertionError {
46 assertTrue("Response is not a SOAP message", response instanceof SoapMessage);
47 SoapMessage soapResponse = (SoapMessage) response;
48 SoapBody responseBody = soapResponse.getSoapBody();
49 assertTrue("Response has no SOAP Body", responseBody != null);
50 assertTrue("Response has no SOAP Fault", responseBody.hasFault());
51 SoapFault soapFault = responseBody.getFault();
52 QName expectedFaultCode = getExpectedFaultCode(soapResponse.getVersion());
53 assertEquals("Invalid SOAP Fault code", expectedFaultCode, soapFault.getFaultCode());
54 if (expectedFaultStringOrReason != null) {
55 assertEquals("Invalid SOAP Fault string/reason", expectedFaultStringOrReason,
56 soapFault.getFaultStringOrReason());
57 }
58 }
59
60
61
62
63 protected abstract QName getExpectedFaultCode(SoapVersion version);
64
65 }