diff --git a/test/src/main/java/org/springframework/ws/mock/client/WebServiceMock.java b/test/src/main/java/org/springframework/ws/mock/client/WebServiceMock.java
index 5ca1b2ec..9735265d 100644
--- a/test/src/main/java/org/springframework/ws/mock/client/WebServiceMock.java
+++ b/test/src/main/java/org/springframework/ws/mock/client/WebServiceMock.java
@@ -26,7 +26,6 @@ import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.xml.transform.ResourceSource;
-import org.springframework.xml.transform.StringSource;
/**
* @author Arjen Poutsma
@@ -63,17 +62,6 @@ public abstract class WebServiceMock {
// RequestMatchers
- /**
- * Expects the given String XML payload.
- *
- * @param payload the XML payload
- * @return the request matcher
- */
- public static RequestMatcher payload(String payload) {
- Assert.notNull(payload, "'payload' must not be null");
- return new PayloadDiffMatcher(new StringSource(payload));
- }
-
/**
* Expects the given {@link Source} XML payload.
*
@@ -131,17 +119,6 @@ public abstract class WebServiceMock {
// ResponseCallbacks
- /**
- * Respond with the given String XML as payload response.
- *
- * @param payload the response payload
- * @return the response callback
- */
- public static ResponseCallback withPayload(String payload) {
- Assert.notNull(payload, "'payload' must not be null");
- return new PayloadResponseCallback(new StringSource(payload));
- }
-
/**
* Respond with the given {@link Source} XML as payload response.
*
diff --git a/test/src/test/java/org/springframework/ws/mock/client/WebServiceMockTest.java b/test/src/test/java/org/springframework/ws/mock/client/WebServiceMockTest.java
index c1ee184a..bd29dc9c 100644
--- a/test/src/test/java/org/springframework/ws/mock/client/WebServiceMockTest.java
+++ b/test/src/test/java/org/springframework/ws/mock/client/WebServiceMockTest.java
@@ -19,6 +19,7 @@ package org.springframework.ws.mock.client;
import java.io.IOException;
import java.net.URI;
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import org.springframework.ws.WebServiceMessage;
@@ -73,19 +74,19 @@ public class WebServiceMockTest {
@Test
public void payloadMatch() throws Exception {
- String request = "";
- String response = "";
+ Source request = new StringSource("");
+ Source response = new StringSource("");
expect(payload(request)).andRespond(withPayload(response));
StringResult result = new StringResult();
- template.sendSourceAndReceiveToResult(new StringSource(request), result);
- assertXMLEqual(result.toString(), response);
+ template.sendSourceAndReceiveToResult(request, result);
+ assertXMLEqual(result.toString(), response.toString());
}
@Test(expected = AssertionError.class)
public void payloadNonMatch() throws Exception {
- String expected = "";
+ Source expected = new StringSource("");
expect(payload(expected));
@@ -140,29 +141,29 @@ public class WebServiceMockTest {
@Test
public void verifyThreadLocalCleanUp() throws Exception {
- String request = "";
- String response = "";
+ Source request = new StringSource("");
+ Source response = new StringSource("");
expect(payload(request)).andRespond(withPayload(response));
expect(payload(request)).andRespond(withPayload(response));
assertNotNull(MockWebServiceMessageSenderHolder.get());
- template.sendSourceAndReceiveToResult(new StringSource(request), new StringResult());
+ template.sendSourceAndReceiveToResult(request, new StringResult());
assertNotNull(MockWebServiceMessageSenderHolder.get());
- template.sendSourceAndReceiveToResult(new StringSource(request), new StringResult());
+ template.sendSourceAndReceiveToResult(request, new StringResult());
assertNull(MockWebServiceMessageSenderHolder.get());
}
@Test(expected = AssertionError.class)
public void unexpectedConnection() throws Exception {
- String request = "";
- String response = "";
+ Source request = new StringSource("");
+ Source response = new StringSource("");
expect(payload(request)).andRespond(withPayload(response));
- template.sendSourceAndReceiveToResult(new StringSource(request), new StringResult());
- template.sendSourceAndReceiveToResult(new StringSource(request), new StringResult());
+ template.sendSourceAndReceiveToResult(request, new StringResult());
+ template.sendSourceAndReceiveToResult(request, new StringResult());
}
diff --git a/test/src/test/java/org/springframework/ws/mock/client/integration/IntegrationTest.java b/test/src/test/java/org/springframework/ws/mock/client/integration/IntegrationTest.java
index bbc30efe..c8197984 100644
--- a/test/src/test/java/org/springframework/ws/mock/client/integration/IntegrationTest.java
+++ b/test/src/test/java/org/springframework/ws/mock/client/integration/IntegrationTest.java
@@ -16,10 +16,13 @@
package org.springframework.ws.mock.client.integration;
+import javax.xml.transform.Source;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.ws.client.core.WebServiceTemplate;
+import org.springframework.xml.transform.StringSource;
import org.junit.Before;
import org.junit.Test;
@@ -48,10 +51,10 @@ public class IntegrationTest {
@Test
public void basic() throws Exception {
- String expectedRequestPayload = "" +
- "John Doe" + "";
- String responsePayload = "" +
- "10" + "";
+ Source expectedRequestPayload = new StringSource("" +
+ "John Doe" + "");
+ Source responsePayload = new StringSource("" +
+ "10" + "");
expect(payload(expectedRequestPayload)).andRespond(withPayload(responsePayload));
diff --git a/xml/src/main/java/org/springframework/xml/transform/StringSource.java b/xml/src/main/java/org/springframework/xml/transform/StringSource.java
index 2a9fb8ae..ec6a4d04 100644
--- a/xml/src/main/java/org/springframework/xml/transform/StringSource.java
+++ b/xml/src/main/java/org/springframework/xml/transform/StringSource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006 the original author or authors.
+ * Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,13 @@
package org.springframework.xml.transform;
+import java.io.InputStream;
+import java.io.Reader;
import java.io.StringReader;
import javax.xml.transform.stream.StreamSource;
+import org.springframework.util.Assert;
+
/**
* Convenient subclass of StreamSource that reads from a StringReader. The string to be read
* can be set via the constructor.
@@ -28,23 +32,55 @@ import javax.xml.transform.stream.StreamSource;
*/
public class StringSource extends StreamSource {
+ private final String content;
+
/**
* Initializes a new instance of the StringSource with the given string content.
*
* @param content the content
*/
public StringSource(String content) {
- super(new StringReader(content));
+ Assert.notNull(content, "'content' must not be null");
+ this.content = content;
+ }
+
+ @Override
+ public Reader getReader() {
+ return new StringReader(content);
}
/**
- * Initializes a new instance of the StringSource with the given string content and system id.
+ * Throws {@link UnsupportedOperationException}.
*
- * @param content the content
- * @param systemId a string that conforms to the URI syntax
+ * @throws UnsupportedOperationException always
*/
- public StringSource(String content, String systemId) {
- super(new StringReader(content), systemId);
+ @Override
+ public void setInputStream(InputStream inputStream) {
+ throw new UnsupportedOperationException("setInputStream is not supported");
}
+ /**
+ * Returns {@code null}.
+ *
+ * @return {@code null}
+ */
+ @Override
+ public InputStream getInputStream() {
+ return null;
+ }
+
+ /**
+ * Throws {@link UnsupportedOperationException}.
+ *
+ * @throws UnsupportedOperationException always
+ */
+ @Override
+ public void setReader(Reader reader) {
+ throw new UnsupportedOperationException("setReader is not supported");
+ }
+
+ @Override
+ public String toString() {
+ return content;
+ }
}