1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.test.client;
18
19 import java.io.IOException;
20 import java.net.URI;
21 import java.util.Map;
22 import javax.xml.namespace.QName;
23 import javax.xml.transform.Source;
24
25 import org.springframework.core.io.Resource;
26 import org.springframework.util.Assert;
27 import org.springframework.ws.WebServiceMessage;
28 import org.springframework.ws.test.support.matcher.PayloadDiffMatcher;
29 import org.springframework.ws.test.support.matcher.SchemaValidatingMatcher;
30 import org.springframework.ws.test.support.matcher.SoapEnvelopeDiffMatcher;
31 import org.springframework.ws.test.support.matcher.SoapHeaderMatcher;
32 import org.springframework.xml.transform.ResourceSource;
33
34
35
36
37
38
39
40
41 public abstract class RequestMatchers {
42
43 private RequestMatchers() {
44 }
45
46
47
48
49
50
51 public static RequestMatcher anything() {
52 return new RequestMatcher() {
53 public void match(URI uri, WebServiceMessage request) throws IOException, AssertionError {
54 }
55 };
56 }
57
58
59
60
61
62
63
64
65
66 public static RequestMatcher payload(Source payload) {
67 Assert.notNull(payload, "'payload' must not be null");
68 return new WebServiceMessageMatcherAdapter(new PayloadDiffMatcher(payload));
69 }
70
71
72
73
74
75
76
77 public static RequestMatcher payload(Resource payload) throws IOException {
78 Assert.notNull(payload, "'payload' must not be null");
79 return payload(new ResourceSource(payload));
80 }
81
82
83
84
85
86
87
88
89 public static RequestMatcher validPayload(Resource schema, Resource... furtherSchemas) throws IOException {
90 return new WebServiceMessageMatcherAdapter(new SchemaValidatingMatcher(schema, furtherSchemas));
91 }
92
93
94
95
96
97
98
99 public static RequestXPathExpectations xpath(String xpathExpression) {
100 return new XPathExpectationsHelperAdapter(xpathExpression, null);
101 }
102
103
104
105
106
107
108
109
110 public static RequestXPathExpectations xpath(String xpathExpression, Map<String, String> namespaceMapping) {
111 return new XPathExpectationsHelperAdapter(xpathExpression, namespaceMapping);
112 }
113
114
115
116
117
118
119
120
121
122
123 public static RequestMatcher soapEnvelope(Source soapEnvelope) {
124 Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
125 return new WebServiceMessageMatcherAdapter(new SoapEnvelopeDiffMatcher(soapEnvelope));
126 }
127
128
129
130
131
132
133
134
135 public static RequestMatcher soapEnvelope(Resource soapEnvelope) throws IOException {
136 Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
137 return soapEnvelope(new ResourceSource(soapEnvelope));
138 }
139
140
141
142
143
144
145
146 public static RequestMatcher soapHeader(QName soapHeaderName) {
147 Assert.notNull(soapHeaderName, "'soapHeaderName' must not be null");
148 return new WebServiceMessageMatcherAdapter(new SoapHeaderMatcher(soapHeaderName));
149 }
150
151
152
153
154
155
156
157
158
159 public static RequestMatcher connectionTo(String uri) {
160 Assert.notNull(uri, "'uri' must not be null");
161 return connectionTo(URI.create(uri));
162 }
163
164
165
166
167
168
169
170 public static RequestMatcher connectionTo(URI uri) {
171 Assert.notNull(uri, "'uri' must not be null");
172 return new UriMatcher(uri);
173 }
174
175 }