Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -rupN original/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java new/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java
- --- original/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java 2010-11-04 15:40:20.774255000 +0300
- +++ new/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java 2012-07-20 20:41:57.790534224 +0400
- @@ -27,6 +27,7 @@ import org.springframework.util.Assert;
- import org.springframework.ws.WebServiceMessage;
- import org.springframework.ws.test.support.matcher.PayloadDiffMatcher;
- import org.springframework.ws.test.support.matcher.SchemaValidatingMatcher;
- +import org.springframework.ws.test.support.matcher.SoapEnvelopeDiffMatcher;
- import org.springframework.ws.test.support.matcher.SoapHeaderMatcher;
- import org.springframework.xml.transform.ResourceSource;
- @@ -75,6 +76,32 @@ public abstract class RequestMatchers {
- Assert.notNull(payload, "'payload' must not be null");
- return payload(new ResourceSource(payload));
- }
- +
- + /**
- + * Expects the given {@link javax.xml.transform.Source} XML SOAP envelope.
- + *
- + * @param soapEnvelope the XML SOAP envelope
- + * @return the request matcher
- + * @author Alexander Shutyaev
- + * @since 2.1.1
- + */
- + public static RequestMatcher soapEnvelope(Source soapEnvelope) {
- + Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
- + return new WebServiceMessageMatcherAdapter(new SoapEnvelopeDiffMatcher(soapEnvelope));
- + }
- +
- + /**
- + * Expects the given {@link org.springframework.core.io.Resource} XML SOAP envelope.
- + *
- + * @param soapEnvelope the XML SOAP envelope
- + * @return the request matcher
- + * @author Alexander Shutyaev
- + * @since 2.1.1
- + */
- + public static RequestMatcher soapEnvelope(Resource soapEnvelope) throws IOException {
- + Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
- + return soapEnvelope(new ResourceSource(soapEnvelope));
- + }
- /**
- * Expects the payload to validate against the given XSD schema(s).
- diff -rupN original/test/src/main/java/org/springframework/ws/test/client/ResponseCreators.java new/test/src/main/java/org/springframework/ws/test/client/ResponseCreators.java
- --- original/test/src/main/java/org/springframework/ws/test/client/ResponseCreators.java 2010-11-05 14:32:32.463811000 +0300
- +++ new/test/src/main/java/org/springframework/ws/test/client/ResponseCreators.java 2012-07-21 00:26:18.462962872 +0400
- @@ -27,6 +27,7 @@ import org.springframework.ws.WebService
- import org.springframework.ws.WebServiceMessageFactory;
- import org.springframework.ws.soap.SoapBody;
- import org.springframework.ws.test.support.creator.PayloadMessageCreator;
- +import org.springframework.ws.test.support.creator.SoapEnvelopeMessageCreator;
- import org.springframework.ws.test.support.creator.WebServiceMessageCreator;
- import org.springframework.xml.transform.ResourceSource;
- @@ -63,6 +64,32 @@ public abstract class ResponseCreators {
- Assert.notNull(payload, "'payload' must not be null");
- return withPayload(new ResourceSource(payload));
- }
- +
- + /**
- + * Respond with the given {@link javax.xml.transform.Source} XML as SOAP envelope response.
- + *
- + * @param soapEnvelope the response SOAP envelope
- + * @return the response callback
- + * @author Alexander Shutyaev
- + * @since 2.1.1
- + */
- + public static ResponseCreator withSoapEnvelope(Source soapEnvelope) {
- + Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
- + return new WebServiceMessageCreatorAdapter(new SoapEnvelopeMessageCreator(soapEnvelope));
- + }
- +
- + /**
- + * Respond with the given {@link org.springframework.core.io.Resource} XML as SOAP envelope response.
- + *
- + * @param soapEnvelope the response SOAP envelope
- + * @return the response callback
- + * @author Alexander Shutyaev
- + * @since 2.1.1
- + */
- + public static ResponseCreator withSoapEnvelope(Resource soapEnvelope) throws IOException {
- + Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
- + return withSoapEnvelope(new ResourceSource(soapEnvelope));
- + }
- /**
- * Respond with an error.
- diff -rupN original/test/src/main/java/org/springframework/ws/test/server/RequestCreators.java new/test/src/main/java/org/springframework/ws/test/server/RequestCreators.java
- --- original/test/src/main/java/org/springframework/ws/test/server/RequestCreators.java 2010-11-05 13:22:32.460749000 +0300
- +++ new/test/src/main/java/org/springframework/ws/test/server/RequestCreators.java 2012-07-21 00:30:03.954972217 +0400
- @@ -24,6 +24,7 @@ import org.springframework.util.Assert;
- import org.springframework.ws.WebServiceMessage;
- import org.springframework.ws.WebServiceMessageFactory;
- import org.springframework.ws.test.support.creator.PayloadMessageCreator;
- +import org.springframework.ws.test.support.creator.SoapEnvelopeMessageCreator;
- import org.springframework.ws.test.support.creator.WebServiceMessageCreator;
- import org.springframework.xml.transform.ResourceSource;
- @@ -60,6 +61,32 @@ public abstract class RequestCreators {
- Assert.notNull(payload, "'payload' must not be null");
- return withPayload(new ResourceSource(payload));
- }
- +
- + /**
- + * Create a request with the given {@link Source} XML as SOAP envelope.
- + *
- + * @param soapEnvelope the request SOAP envelope
- + * @return the request creator
- + * @author Alexander Shutyaev
- + * @since 2.1.1
- + */
- + public static RequestCreator withSoapEnvelope(Source soapEnvelope) {
- + Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
- + return new WebServiceMessageCreatorAdapter(new SoapEnvelopeMessageCreator(soapEnvelope));
- + }
- +
- + /**
- + * Create a request with the given {@link Resource} XML as SOAP envelope.
- + *
- + * @param soapEnvelope the request SOAP envelope
- + * @return the request creator
- + * @author Alexander Shutyaev
- + * @since 2.1.1
- + */
- + public static RequestCreator withSoapEnvelope(Resource soapEnvelope) throws IOException {
- + Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
- + return withSoapEnvelope(new ResourceSource(soapEnvelope));
- + }
- /**
- * Adapts a {@link WebServiceMessageCreator} to the {@link RequestCreator} contract.
- diff -rupN original/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java new/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java
- --- original/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java 2010-12-10 12:44:28.170784000 +0300
- +++ new/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java 2012-07-20 20:44:37.806540857 +0400
- @@ -29,6 +29,7 @@ import org.springframework.ws.WebService
- import org.springframework.ws.soap.SoapVersion;
- import org.springframework.ws.test.support.matcher.PayloadDiffMatcher;
- import org.springframework.ws.test.support.matcher.SchemaValidatingMatcher;
- +import org.springframework.ws.test.support.matcher.SoapEnvelopeDiffMatcher;
- import org.springframework.ws.test.support.matcher.SoapHeaderMatcher;
- import org.springframework.xml.transform.ResourceSource;
- @@ -45,6 +46,32 @@ public abstract class ResponseMatchers {
- private ResponseMatchers() {
- }
- +
- + // SOAP envelope
- +
- + /**
- + * Expects the given {@link Source} XML SOAP envelope.
- + *
- + * @param soapEnvelope the XML SOAP envelope
- + * @return the response matcher
- + * @author Alexander Shutyaev
- + * @since 2.1.1
- + */
- + public static ResponseMatcher soapEnvelope(Source soapEnvelope) {
- + return new WebServiceMessageMatcherAdapter(new SoapEnvelopeDiffMatcher(soapEnvelope));
- + }
- +
- + /**
- + * Expects the given {@link Resource} XML SOAP envelope.
- + *
- + * @param soapEnvelope the XML SOAP envelope
- + * @return the response matcher
- + * @author Alexander Shutyaev
- + * @since 2.1.1
- + */
- + public static ResponseMatcher soapEnvelope(Resource soapEnvelope) throws IOException {
- + return soapEnvelope(new ResourceSource(soapEnvelope));
- + }
- // Payload
- diff -rupN original/test/src/main/java/org/springframework/ws/test/support/creator/SoapEnvelopeMessageCreator.java new/test/src/main/java/org/springframework/ws/test/support/creator/SoapEnvelopeMessageCreator.java
- --- original/test/src/main/java/org/springframework/ws/test/support/creator/SoapEnvelopeMessageCreator.java 1970-01-01 03:00:00.000000000 +0300
- +++ new/test/src/main/java/org/springframework/ws/test/support/creator/SoapEnvelopeMessageCreator.java 2012-07-21 00:22:00.442952168 +0400
- @@ -0,0 +1,69 @@
- +/*
- + * Copyright 2005-2012 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.
- + * You may obtain a copy of the License at
- + *
- + * http://www.apache.org/licenses/LICENSE-2.0
- + *
- + * Unless required by applicable law or agreed to in writing, software
- + * distributed under the License is distributed on an "AS IS" BASIS,
- + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- + * See the License for the specific language governing permissions and
- + * limitations under the License.
- + */
- +
- +package org.springframework.ws.test.support.creator;
- +
- +import static org.springframework.ws.test.support.AssertionErrors.assertTrue;
- +import static org.springframework.ws.test.support.AssertionErrors.fail;
- +
- +import java.io.IOException;
- +
- +import javax.xml.transform.Source;
- +import javax.xml.transform.TransformerException;
- +import javax.xml.transform.dom.DOMResult;
- +
- +import org.springframework.util.Assert;
- +import org.springframework.ws.WebServiceMessage;
- +import org.springframework.ws.soap.SoapMessage;
- +import org.springframework.xml.transform.TransformerHelper;
- +import org.w3c.dom.Document;
- +
- +/**
- + * Implementation of {@link WebServiceMessageCreator} that creates a request based on a SOAP envelope {@link Source}.
- + *
- + * @author Alexander Shutyaev
- + * @since 2.1.1
- + */
- +public class SoapEnvelopeMessageCreator extends AbstractMessageCreator {
- +
- + private final Source soapEnvelope;
- +
- + private final TransformerHelper transformerHelper = new TransformerHelper();
- +
- + /**
- + * Creates a new instance of the {@code SoapEnvelopeMessageCreator} with the given SOAP envelope source.
- + *
- + * @param soapEnvelope the SOAP envelope source
- + */
- + public SoapEnvelopeMessageCreator(Source soapEnvelope) {
- + Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
- + this.soapEnvelope = soapEnvelope;
- + }
- +
- + @Override
- + protected void doWithMessage(WebServiceMessage message) throws IOException {
- + assertTrue("Message created with factory is not a SOAP message", message instanceof SoapMessage);
- + try {
- + DOMResult result = new DOMResult();
- + transformerHelper.transform(soapEnvelope, result);
- + ((SoapMessage)message).setDocument((Document)result.getNode());
- + }
- + catch (TransformerException ex) {
- + fail("Could not transform request SOAP envelope to message: " + ex.getMessage());
- + }
- + }
- +
- +}
- diff -rupN original/test/src/main/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcher.java new/test/src/main/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcher.java
- --- original/test/src/main/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcher.java 1970-01-01 03:00:00.000000000 +0300
- +++ new/test/src/main/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcher.java 2012-07-20 23:50:08.378872902 +0400
- @@ -0,0 +1,71 @@
- +/*
- + * Copyright 2005-2012 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.
- + * You may obtain a copy of the License at
- + *
- + * http://www.apache.org/licenses/LICENSE-2.0
- + *
- + * Unless required by applicable law or agreed to in writing, software
- + * distributed under the License is distributed on an "AS IS" BASIS,
- + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- + * See the License for the specific language governing permissions and
- + * limitations under the License.
- + */
- +
- +package org.springframework.ws.test.support.matcher;
- +
- +import static org.springframework.ws.test.support.AssertionErrors.assertTrue;
- +import static org.springframework.ws.test.support.AssertionErrors.fail;
- +
- +import java.io.IOException;
- +
- +import javax.xml.transform.Source;
- +import javax.xml.transform.TransformerException;
- +import javax.xml.transform.dom.DOMResult;
- +
- +import org.custommonkey.xmlunit.Diff;
- +import org.springframework.util.Assert;
- +import org.springframework.ws.soap.SoapMessage;
- +import org.springframework.xml.transform.TransformerHelper;
- +import org.w3c.dom.Document;
- +
- +/**
- + * Matches {@link Source} SOAP envelopes.
- + *
- + * @author Alexander Shutyaev
- + * @since 2.1.1
- + */
- +public class SoapEnvelopeDiffMatcher extends AbstractSoapMessageMatcher {
- +
- + private final Source expected;
- +
- + private final TransformerHelper transformerHelper = new TransformerHelper();
- +
- + public SoapEnvelopeDiffMatcher(Source expected) {
- + Assert.notNull(expected, "'expected' must not be null");
- + this.expected = expected;
- + }
- +
- + @Override
- + protected void match(SoapMessage soapMessage) throws IOException, AssertionError {
- + Document actualDocument = soapMessage.getDocument();
- + Document expectedDocument = createDocumentFromSource(expected);
- + Diff diff = new Diff(expectedDocument, actualDocument);
- + assertTrue("Envelopes are different, " + diff.toString(), diff.similar());
- + }
- +
- + private Document createDocumentFromSource(Source source) {
- + try {
- + DOMResult result = new DOMResult();
- + transformerHelper.transform(source, result);
- + return (Document) result.getNode();
- + }
- + catch (TransformerException ex) {
- + fail("Could not transform source to DOMResult" + ex.getMessage());
- + return null;
- + }
- + }
- +
- +}
- diff -rupN original/test/src/test/java/org/springframework/ws/test/client/ResponseCreatorsTest.java new/test/src/test/java/org/springframework/ws/test/client/ResponseCreatorsTest.java
- --- original/test/src/test/java/org/springframework/ws/test/client/ResponseCreatorsTest.java 2010-11-05 14:32:32.463811000 +0300
- +++ new/test/src/test/java/org/springframework/ws/test/client/ResponseCreatorsTest.java 2012-07-21 00:37:46.774991403 +0400
- @@ -16,12 +16,21 @@
- package org.springframework.ws.test.client;
- +import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
- +import static org.junit.Assert.assertEquals;
- +import static org.junit.Assert.assertSame;
- +import static org.junit.Assert.assertTrue;
- +
- import java.io.IOException;
- import java.util.Locale;
- +
- import javax.xml.namespace.QName;
- import javax.xml.transform.Result;
- import javax.xml.transform.TransformerException;
- +import javax.xml.transform.dom.DOMSource;
- +import org.junit.Before;
- +import org.junit.Test;
- import org.springframework.core.io.ByteArrayResource;
- import org.springframework.ws.WebServiceMessage;
- import org.springframework.ws.soap.SoapMessage;
- @@ -32,12 +41,6 @@ import org.springframework.xml.transform
- import org.springframework.xml.transform.StringSource;
- import org.springframework.xml.transform.TransformerHelper;
- -import org.junit.Before;
- -import org.junit.Test;
- -
- -import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
- -import static org.junit.Assert.*;
- -
- public class ResponseCreatorsTest {
- private final TransformerHelper transformerHelper = new TransformerHelper();
- @@ -71,6 +74,34 @@ public class ResponseCreatorsTest {
- assertXMLEqual(payload, getPayloadAsString(response));
- }
- +
- + @Test
- + public void withSoapEnvelopeSource() throws Exception {
- + StringBuilder xmlBuilder = new StringBuilder();
- + xmlBuilder.append("<?xml version='1.0'?>");
- + xmlBuilder.append("<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>");
- + xmlBuilder.append("<soap:Header><header xmlns='http://springframework.org'/></soap:Header>");
- + xmlBuilder.append("<soap:Body><payload xmlns='http://springframework.org'/></soap:Body>");
- + xmlBuilder.append("</soap:Envelope>");
- + String envelope = xmlBuilder.toString();
- + ResponseCreator responseCreator = ResponseCreators.withSoapEnvelope(new StringSource(envelope));
- + WebServiceMessage response = responseCreator.createResponse(null, null, messageFactory);
- + assertXMLEqual(envelope, getSoapEnvelopeAsString((SoapMessage)response));
- + }
- +
- + @Test
- + public void withSoapEnvelopeResource() throws Exception {
- + StringBuilder xmlBuilder = new StringBuilder();
- + xmlBuilder.append("<?xml version='1.0'?>");
- + xmlBuilder.append("<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>");
- + xmlBuilder.append("<soap:Header><header xmlns='http://springframework.org'/></soap:Header>");
- + xmlBuilder.append("<soap:Body><payload xmlns='http://springframework.org'/></soap:Body>");
- + xmlBuilder.append("</soap:Envelope>");
- + String envelope = xmlBuilder.toString();
- + ResponseCreator responseCreator = ResponseCreators.withSoapEnvelope(new ByteArrayResource(envelope.getBytes("UTF-8")));
- + WebServiceMessage response = responseCreator.createResponse(null, null, messageFactory);
- + assertXMLEqual(envelope, getSoapEnvelopeAsString((SoapMessage)response));
- + }
- @Test
- public void withIOException() throws Exception {
- @@ -145,4 +176,11 @@ public class ResponseCreatorsTest {
- transformerHelper.transform(message.getPayloadSource(), result);
- return result.toString();
- }
- +
- + private String getSoapEnvelopeAsString(SoapMessage message) throws TransformerException {
- + DOMSource source = new DOMSource(message.getDocument());
- + Result result = new StringResult();
- + transformerHelper.transform(source, result);
- + return result.toString();
- + }
- }
- diff -rupN original/test/src/test/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcherTest.java new/test/src/test/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcherTest.java
- --- original/test/src/test/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcherTest.java 1970-01-01 03:00:00.000000000 +0300
- +++ new/test/src/test/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcherTest.java 2012-07-20 23:57:29.578891192 +0400
- @@ -0,0 +1,78 @@
- +/*
- + * Copyright 2005-2012 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.
- + * You may obtain a copy of the License at
- + *
- + * http://www.apache.org/licenses/LICENSE-2.0
- + *
- + * Unless required by applicable law or agreed to in writing, software
- + * distributed under the License is distributed on an "AS IS" BASIS,
- + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- + * See the License for the specific language governing permissions and
- + * limitations under the License.
- + */
- +
- +package org.springframework.ws.test.support.matcher;
- +
- +import static org.easymock.EasyMock.createMock;
- +import static org.easymock.EasyMock.expect;
- +import static org.easymock.EasyMock.replay;
- +import static org.easymock.EasyMock.verify;
- +
- +import javax.xml.transform.dom.DOMResult;
- +
- +import org.junit.Test;
- +import org.springframework.ws.soap.SoapMessage;
- +import org.springframework.xml.transform.StringSource;
- +import org.springframework.xml.transform.TransformerHelper;
- +import org.w3c.dom.Document;
- +
- +public class SoapEnvelopeDiffMatcherTest {
- +
- + @Test
- + public void match() throws Exception {
- + StringBuilder xmlBuilder = new StringBuilder();
- + xmlBuilder.append("<?xml version='1.0'?>");
- + xmlBuilder.append("<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>");
- + xmlBuilder.append("<soap:Header><header xmlns='http://example.com'/></soap:Header>");
- + xmlBuilder.append("<soap:Body><payload xmlns='http://example.com'/></soap:Body>");
- + xmlBuilder.append("</soap:Envelope>");
- + String xml = xmlBuilder.toString();
- + DOMResult result = new DOMResult();
- + TransformerHelper transformerHelper = new TransformerHelper();
- + transformerHelper.transform(new StringSource(xml), result);
- + SoapMessage message = createMock(SoapMessage.class);
- + expect(message.getDocument()).andReturn((Document)result.getNode()).once();
- + replay(message);
- +
- + SoapEnvelopeDiffMatcher matcher = new SoapEnvelopeDiffMatcher(new StringSource(xml));
- + matcher.match(message);
- +
- + verify(message);
- + }
- +
- + @Test(expected = AssertionError.class)
- + public void nonMatch() throws Exception {
- + StringBuilder xmlBuilder = new StringBuilder();
- + xmlBuilder.append("<?xml version='1.0'?>");
- + xmlBuilder.append("<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>");
- + xmlBuilder.append("<soap:Header><header xmlns='http://example.com'/></soap:Header>");
- + xmlBuilder.append("<soap:Body><payload%s xmlns='http://example.com'/></soap:Body>");
- + xmlBuilder.append("</soap:Envelope>");
- + String xml = xmlBuilder.toString();
- + String actual = String.format(xml, "1");
- + DOMResult result = new DOMResult();
- + TransformerHelper transformerHelper = new TransformerHelper();
- + transformerHelper.transform(new StringSource(actual), result);
- + SoapMessage message = createMock(SoapMessage.class);
- + expect(message.getDocument()).andReturn((Document)result.getNode()).once();
- + replay(message);
- +
- + String expected = String.format(xml, "2");
- + SoapEnvelopeDiffMatcher matcher = new SoapEnvelopeDiffMatcher(new StringSource(expected));
- + matcher.match(message);
- + }
- +
- +}
Advertisement
Add Comment
Please, Sign In to add comment