Skip to content

Commit d3a1a72

Browse files
committed
SWS-544 - Removed String payload() and withPayload() variants
1 parent 18dee1a commit d3a1a72

File tree

4 files changed

+64
-47
lines changed

4 files changed

+64
-47
lines changed

test/src/main/java/org/springframework/ws/mock/client/WebServiceMock.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.springframework.util.Assert;
2727
import org.springframework.ws.client.core.WebServiceTemplate;
2828
import org.springframework.xml.transform.ResourceSource;
29-
import org.springframework.xml.transform.StringSource;
3029

3130
/**
3231
* @author Arjen Poutsma
@@ -63,17 +62,6 @@ public static ResponseActions expect(RequestMatcher requestMatcher) {
6362

6463
// RequestMatchers
6564

66-
/**
67-
* Expects the given String XML payload.
68-
*
69-
* @param payload the XML payload
70-
* @return the request matcher
71-
*/
72-
public static RequestMatcher payload(String payload) {
73-
Assert.notNull(payload, "'payload' must not be null");
74-
return new PayloadDiffMatcher(new StringSource(payload));
75-
}
76-
7765
/**
7866
* Expects the given {@link Source} XML payload.
7967
*
@@ -131,17 +119,6 @@ public static RequestMatcher connectionTo(URI uri) {
131119

132120
// ResponseCallbacks
133121

134-
/**
135-
* Respond with the given String XML as payload response.
136-
*
137-
* @param payload the response payload
138-
* @return the response callback
139-
*/
140-
public static ResponseCallback withPayload(String payload) {
141-
Assert.notNull(payload, "'payload' must not be null");
142-
return new PayloadResponseCallback(new StringSource(payload));
143-
}
144-
145122
/**
146123
* Respond with the given {@link Source} XML as payload response.
147124
*

test/src/test/java/org/springframework/ws/mock/client/WebServiceMockTest.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.net.URI;
2121
import javax.xml.namespace.QName;
22+
import javax.xml.transform.Source;
2223
import javax.xml.transform.TransformerException;
2324

2425
import org.springframework.ws.WebServiceMessage;
@@ -73,19 +74,19 @@ public void mocks() throws Exception {
7374

7475
@Test
7576
public void payloadMatch() throws Exception {
76-
String request = "<request xmlns='http://example.com'/>";
77-
String response = "<response xmlns='http://example.com'/>";
77+
Source request = new StringSource("<request xmlns='http://example.com'/>");
78+
Source response = new StringSource("<response xmlns='http://example.com'/>");
7879

7980
expect(payload(request)).andRespond(withPayload(response));
8081

8182
StringResult result = new StringResult();
82-
template.sendSourceAndReceiveToResult(new StringSource(request), result);
83-
assertXMLEqual(result.toString(), response);
83+
template.sendSourceAndReceiveToResult(request, result);
84+
assertXMLEqual(result.toString(), response.toString());
8485
}
8586

8687
@Test(expected = AssertionError.class)
8788
public void payloadNonMatch() throws Exception {
88-
String expected = "<request xmlns='http://example.com'/>";
89+
Source expected = new StringSource("<request xmlns='http://example.com'/>");
8990

9091
expect(payload(expected));
9192

@@ -140,29 +141,29 @@ public void connectionNonMatch() throws Exception {
140141

141142
@Test
142143
public void verifyThreadLocalCleanUp() throws Exception {
143-
String request = "<request xmlns='http://example.com'/>";
144-
String response = "<response xmlns='http://example.com'/>";
144+
Source request = new StringSource("<request xmlns='http://example.com'/>");
145+
Source response = new StringSource("<response xmlns='http://example.com'/>");
145146

146147
expect(payload(request)).andRespond(withPayload(response));
147148
expect(payload(request)).andRespond(withPayload(response));
148149
assertNotNull(MockWebServiceMessageSenderHolder.get());
149150

150-
template.sendSourceAndReceiveToResult(new StringSource(request), new StringResult());
151+
template.sendSourceAndReceiveToResult(request, new StringResult());
151152
assertNotNull(MockWebServiceMessageSenderHolder.get());
152153

153-
template.sendSourceAndReceiveToResult(new StringSource(request), new StringResult());
154+
template.sendSourceAndReceiveToResult(request, new StringResult());
154155
assertNull(MockWebServiceMessageSenderHolder.get());
155156
}
156157

157158
@Test(expected = AssertionError.class)
158159
public void unexpectedConnection() throws Exception {
159-
String request = "<request xmlns='http://example.com'/>";
160-
String response = "<response xmlns='http://example.com'/>";
160+
Source request = new StringSource("<request xmlns='http://example.com'/>");
161+
Source response = new StringSource("<response xmlns='http://example.com'/>");
161162

162163
expect(payload(request)).andRespond(withPayload(response));
163164

164-
template.sendSourceAndReceiveToResult(new StringSource(request), new StringResult());
165-
template.sendSourceAndReceiveToResult(new StringSource(request), new StringResult());
165+
template.sendSourceAndReceiveToResult(request, new StringResult());
166+
template.sendSourceAndReceiveToResult(request, new StringResult());
166167
}
167168

168169

test/src/test/java/org/springframework/ws/mock/client/integration/IntegrationTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616

1717
package org.springframework.ws.mock.client.integration;
1818

19+
import javax.xml.transform.Source;
20+
1921
import org.springframework.beans.factory.annotation.Autowired;
2022
import org.springframework.test.context.ContextConfiguration;
2123
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2224
import org.springframework.ws.client.core.WebServiceTemplate;
25+
import org.springframework.xml.transform.StringSource;
2326

2427
import org.junit.Before;
2528
import org.junit.Test;
@@ -48,10 +51,10 @@ public void setUpMocks() throws Exception {
4851

4952
@Test
5053
public void basic() throws Exception {
51-
String expectedRequestPayload = "<customerCountRequest xmlns='http://springframework.org/client'>" +
52-
"<customerName>John Doe</customerName>" + "</customerCountRequest>";
53-
String responsePayload = "<customerCountResponse xmlns='http://springframework.org/client'>" +
54-
"<customerCount>10</customerCount>" + "</customerCountResponse>";
54+
Source expectedRequestPayload = new StringSource("<customerCountRequest xmlns='http://springframework.org/client'>" +
55+
"<customerName>John Doe</customerName>" + "</customerCountRequest>");
56+
Source responsePayload = new StringSource("<customerCountResponse xmlns='http://springframework.org/client'>" +
57+
"<customerCount>10</customerCount>" + "</customerCountResponse>");
5558

5659
expect(payload(expectedRequestPayload)).andRespond(withPayload(responsePayload));
5760

xml/src/main/java/org/springframework/xml/transform/StringSource.java

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006 the original author or authors.
2+
* Copyright 2005-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,9 +16,13 @@
1616

1717
package org.springframework.xml.transform;
1818

19+
import java.io.InputStream;
20+
import java.io.Reader;
1921
import java.io.StringReader;
2022
import javax.xml.transform.stream.StreamSource;
2123

24+
import org.springframework.util.Assert;
25+
2226
/**
2327
* Convenient subclass of <code>StreamSource</code> that reads from a <code>StringReader</code>. The string to be read
2428
* can be set via the constructor.
@@ -28,23 +32,55 @@
2832
*/
2933
public class StringSource extends StreamSource {
3034

35+
private final String content;
36+
3137
/**
3238
* Initializes a new instance of the <code>StringSource</code> with the given string content.
3339
*
3440
* @param content the content
3541
*/
3642
public StringSource(String content) {
37-
super(new StringReader(content));
43+
Assert.notNull(content, "'content' must not be null");
44+
this.content = content;
45+
}
46+
47+
@Override
48+
public Reader getReader() {
49+
return new StringReader(content);
3850
}
3951

4052
/**
41-
* Initializes a new instance of the <code>StringSource</code> with the given string content and system id.
53+
* Throws {@link UnsupportedOperationException}.
4254
*
43-
* @param content the content
44-
* @param systemId a string that conforms to the URI syntax
55+
* @throws UnsupportedOperationException always
4556
*/
46-
public StringSource(String content, String systemId) {
47-
super(new StringReader(content), systemId);
57+
@Override
58+
public void setInputStream(InputStream inputStream) {
59+
throw new UnsupportedOperationException("setInputStream is not supported");
4860
}
4961

62+
/**
63+
* Returns {@code null}.
64+
*
65+
* @return {@code null}
66+
*/
67+
@Override
68+
public InputStream getInputStream() {
69+
return null;
70+
}
71+
72+
/**
73+
* Throws {@link UnsupportedOperationException}.
74+
*
75+
* @throws UnsupportedOperationException always
76+
*/
77+
@Override
78+
public void setReader(Reader reader) {
79+
throw new UnsupportedOperationException("setReader is not supported");
80+
}
81+
82+
@Override
83+
public String toString() {
84+
return content;
85+
}
5086
}

0 commit comments

Comments
 (0)