SWS-544 - Removed String payload() and withPayload() variants

This commit is contained in:
Arjen Poutsma
2010-07-19 10:47:16 +00:00
parent 18dee1a352
commit d3a1a72163
4 changed files with 64 additions and 47 deletions

View File

@@ -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.
*

View File

@@ -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 = "<request xmlns='http://example.com'/>";
String response = "<response xmlns='http://example.com'/>";
Source request = new StringSource("<request xmlns='http://example.com'/>");
Source response = new StringSource("<response xmlns='http://example.com'/>");
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 = "<request xmlns='http://example.com'/>";
Source expected = new StringSource("<request xmlns='http://example.com'/>");
expect(payload(expected));
@@ -140,29 +141,29 @@ public class WebServiceMockTest {
@Test
public void verifyThreadLocalCleanUp() throws Exception {
String request = "<request xmlns='http://example.com'/>";
String response = "<response xmlns='http://example.com'/>";
Source request = new StringSource("<request xmlns='http://example.com'/>");
Source response = new StringSource("<response xmlns='http://example.com'/>");
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 = "<request xmlns='http://example.com'/>";
String response = "<response xmlns='http://example.com'/>";
Source request = new StringSource("<request xmlns='http://example.com'/>");
Source response = new StringSource("<response xmlns='http://example.com'/>");
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());
}

View File

@@ -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 = "<customerCountRequest xmlns='http://springframework.org/client'>" +
"<customerName>John Doe</customerName>" + "</customerCountRequest>";
String responsePayload = "<customerCountResponse xmlns='http://springframework.org/client'>" +
"<customerCount>10</customerCount>" + "</customerCountResponse>";
Source expectedRequestPayload = new StringSource("<customerCountRequest xmlns='http://springframework.org/client'>" +
"<customerName>John Doe</customerName>" + "</customerCountRequest>");
Source responsePayload = new StringSource("<customerCountResponse xmlns='http://springframework.org/client'>" +
"<customerCount>10</customerCount>" + "</customerCountResponse>");
expect(payload(expectedRequestPayload)).andRespond(withPayload(responsePayload));

View File

@@ -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 <code>StreamSource</code> that reads from a <code>StringReader</code>. 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 <code>StringSource</code> 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 <code>StringSource</code> 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;
}
}