diff --git a/test/src/main/java/org/springframework/ws/test/client/DefaultXPathExpectations.java b/test/src/main/java/org/springframework/ws/test/client/DefaultXPathExpectations.java index 9f4da9a9..67d456da 100644 --- a/test/src/main/java/org/springframework/ws/test/client/DefaultXPathExpectations.java +++ b/test/src/main/java/org/springframework/ws/test/client/DefaultXPathExpectations.java @@ -24,7 +24,7 @@ import javax.xml.transform.dom.DOMResult; import org.springframework.util.Assert; import org.springframework.ws.WebServiceMessage; -import org.springframework.xml.transform.TransformerObjectSupport; +import org.springframework.xml.transform.TransformerHelper; import org.springframework.xml.xpath.XPathExpression; import org.springframework.xml.xpath.XPathExpressionFactory; @@ -40,12 +40,14 @@ import static org.springframework.ws.test.support.AssertionErrors.fail; * @author Arjen Poutsma * @since 2.0 */ -class DefaultXPathExpectations extends TransformerObjectSupport implements XPathExpectations { +class DefaultXPathExpectations implements XPathExpectations { private final XPathExpression expression; private final String expressionString; + private final TransformerHelper transformerHelper = new TransformerHelper(); + DefaultXPathExpectations(String expression, Map namespaces) { Assert.hasLength(expression, "'expression' must not be empty"); this.expression = XPathExpressionFactory.createXPathExpression(expression, namespaces); @@ -119,7 +121,7 @@ class DefaultXPathExpectations extends TransformerObjectSupport implements XPath private Node transformToNode(WebServiceMessage request) { DOMResult domResult = new DOMResult(); try { - transform(request.getPayloadSource(), domResult); + transformerHelper.transform(request.getPayloadSource(), domResult); return domResult.getNode(); } catch (TransformerException ex) { diff --git a/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java b/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java index ea6085ea..124fed94 100644 --- a/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java +++ b/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java @@ -25,10 +25,10 @@ import javax.xml.transform.Source; import org.springframework.core.io.Resource; import org.springframework.util.Assert; import org.springframework.ws.WebServiceMessage; -import org.springframework.ws.test.support.PayloadDiffMatcher; +import org.springframework.ws.test.support.matcher.PayloadDiffMatcher; +import org.springframework.ws.test.support.matcher.SchemaValidatingMatcher; +import org.springframework.ws.test.support.matcher.WebServiceMessageMatcher; import org.springframework.xml.transform.ResourceSource; -import org.springframework.xml.validation.XmlValidator; -import org.springframework.xml.validation.XmlValidatorFactory; /** * Factory methods for {@link RequestMatcher} classes. Typically used to provide input for {@link @@ -62,12 +62,7 @@ public abstract class RequestMatchers { */ public static RequestMatcher payload(Source payload) { Assert.notNull(payload, "'payload' must not be null"); - final PayloadDiffMatcher matcher = new PayloadDiffMatcher(payload); - return new RequestMatcher() { - public void match(URI uri, WebServiceMessage request) throws IOException, AssertionError { - matcher.match(request); - } - }; + return new WebServiceMessageMatcherAdapter(new PayloadDiffMatcher(payload)); } /** @@ -88,18 +83,8 @@ public abstract class RequestMatchers { * @param furtherSchemas further schemas, if necessary * @return the request matcher */ - public static RequestMatcher validPayload(Resource schema, Resource... furtherSchemas) { - try { - Resource[] joinedSchemas = new Resource[furtherSchemas.length + 1]; - joinedSchemas[0] = schema; - System.arraycopy(furtherSchemas, 0, joinedSchemas, 1, furtherSchemas.length); - XmlValidator validator = - XmlValidatorFactory.createValidator(joinedSchemas, XmlValidatorFactory.SCHEMA_W3C_XML); - return new SchemaValidatingRequestMatcher(validator); - } - catch (IOException ex) { - throw new IllegalArgumentException("Schema(s) could not be opened", ex); - } + public static RequestMatcher validPayload(Resource schema, Resource... furtherSchemas) throws IOException { + return new WebServiceMessageMatcherAdapter(new SchemaValidatingMatcher(schema, furtherSchemas)); } /** @@ -155,4 +140,21 @@ public abstract class RequestMatchers { Assert.notNull(uri, "'uri' must not be null"); return new UriMatcher(uri); } + + /** + * Adapts a {@link org.springframework.ws.test.support.matcher.WebServiceMessageMatcher} to the {@link RequestMatcher} contract. + */ + private static class WebServiceMessageMatcherAdapter implements RequestMatcher { + + private final WebServiceMessageMatcher adaptee; + + private WebServiceMessageMatcherAdapter(WebServiceMessageMatcher adaptee) { + this.adaptee = adaptee; + } + + public void match(URI uri, WebServiceMessage request) throws IOException, AssertionError { + adaptee.match(request); + } + } + } diff --git a/test/src/main/java/org/springframework/ws/test/client/SchemaValidatingRequestMatcher.java b/test/src/main/java/org/springframework/ws/test/client/SchemaValidatingRequestMatcher.java deleted file mode 100644 index 20ad8e8e..00000000 --- a/test/src/main/java/org/springframework/ws/test/client/SchemaValidatingRequestMatcher.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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. - * 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.client; - -import java.io.IOException; -import java.net.URI; -import java.util.Arrays; - -import org.springframework.util.Assert; -import org.springframework.util.ObjectUtils; -import org.springframework.ws.WebServiceMessage; -import org.springframework.xml.validation.XmlValidator; - -import org.xml.sax.SAXParseException; - -/** - * Uses the {@link XmlValidator} to validate request payload. - * - * @author Lukas Krecan - * @since 2.0 - */ -class SchemaValidatingRequestMatcher implements RequestMatcher { - - private final XmlValidator xmlValidator; - - public SchemaValidatingRequestMatcher(XmlValidator xmlValidator) { - Assert.notNull(xmlValidator, "XmlValidator has to be set"); - this.xmlValidator = xmlValidator; - } - - public void match(URI uri, WebServiceMessage request) throws IOException, AssertionError { - SAXParseException[] exceptions = xmlValidator.validate(request.getPayloadSource()); - if (!ObjectUtils.isEmpty(exceptions)) { - throw new AssertionError("XML is not valid: " + Arrays.toString(exceptions)); - } - } -} diff --git a/test/src/main/java/org/springframework/ws/test/server/AbstractRequestCreator.java b/test/src/main/java/org/springframework/ws/test/server/AbstractRequestCreator.java new file mode 100644 index 00000000..96d7fc10 --- /dev/null +++ b/test/src/main/java/org/springframework/ws/test/server/AbstractRequestCreator.java @@ -0,0 +1,43 @@ +/* + * 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. + * 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.server; + +import java.io.IOException; + +import org.springframework.ws.WebServiceMessage; +import org.springframework.ws.WebServiceMessageFactory; + +/** + * Abstract base class for the {@link org.springframework.ws.test.server.RequestCreator} interface. + *

+ * Creates a response using the given {@link org.springframework.ws.WebServiceMessageFactory}, and passes it on to + * {@link #doWithRequest(org.springframework.ws.WebServiceMessage)}. + * + * @author Arjen Poutsma + * @since 2.0 + */ +abstract class AbstractRequestCreator implements RequestCreator { + + public final WebServiceMessage createRequest(WebServiceMessageFactory messageFactory) throws IOException { + WebServiceMessage request = messageFactory.createWebServiceMessage(); + doWithRequest(request); + return request; + } + + protected abstract void doWithRequest(WebServiceMessage request) throws IOException; + +} diff --git a/test/src/main/java/org/springframework/ws/test/server/PayloadRequestCreator.java b/test/src/main/java/org/springframework/ws/test/server/PayloadRequestCreator.java new file mode 100644 index 00000000..e3a6365c --- /dev/null +++ b/test/src/main/java/org/springframework/ws/test/server/PayloadRequestCreator.java @@ -0,0 +1,52 @@ +/* + * 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. + * 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.server; + +import java.io.IOException; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerException; + +import org.springframework.ws.WebServiceMessage; +import org.springframework.xml.transform.TransformerHelper; + +/** + * Implementation of {@link org.springframework.ws.test.server.RequestCreator} that creates a request based on a {@link + * javax.xml.transform.Source}. + * + * @author Arjen Poutsma + * @since 2.0 + */ +class PayloadRequestCreator extends AbstractRequestCreator { + + private final Source payload; + + private TransformerHelper transformerHelper = new TransformerHelper(); + + PayloadRequestCreator(Source payload) { + this.payload = payload; + } + + @Override + protected void doWithRequest(WebServiceMessage request) throws IOException { + try { + transformerHelper.transform(payload, request.getPayloadResult()); + } + catch (TransformerException ex) { + throw new AssertionError("Could not transform request payload to message: " + ex.getMessage()); + } + } +} diff --git a/test/src/main/java/org/springframework/ws/test/server/RequestCreators.java b/test/src/main/java/org/springframework/ws/test/server/RequestCreators.java index 0b35f4c5..5dc26887 100644 --- a/test/src/main/java/org/springframework/ws/test/server/RequestCreators.java +++ b/test/src/main/java/org/springframework/ws/test/server/RequestCreators.java @@ -18,14 +18,10 @@ package org.springframework.ws.test.server; import java.io.IOException; import javax.xml.transform.Source; -import javax.xml.transform.TransformerException; import org.springframework.core.io.Resource; import org.springframework.util.Assert; -import org.springframework.ws.WebServiceMessage; -import org.springframework.ws.WebServiceMessageFactory; import org.springframework.xml.transform.ResourceSource; -import org.springframework.xml.transform.TransformerHelper; /** * Factory methods for {@link RequestCreator} classes. Typically used to provide input for {@link @@ -61,47 +57,5 @@ public abstract class RequestCreators { return withPayload(new ResourceSource(payload)); } - /** - * Abstract base class for the {@link RequestCreator} interface. - *

- * Creates a response using the given {@link org.springframework.ws.WebServiceMessageFactory}, and passes it on to - * {@link #doWithRequest(org.springframework.ws.WebServiceMessage)}. - */ - private static abstract class AbstractRequestCreator implements RequestCreator { - - public final WebServiceMessage createRequest(WebServiceMessageFactory messageFactory) throws IOException { - WebServiceMessage request = messageFactory.createWebServiceMessage(); - doWithRequest(request); - return request; - } - - protected abstract void doWithRequest(WebServiceMessage request) throws IOException; - - } - - - /** - * Implementation of {@link RequestCreator} that creates a request based on a {@link javax.xml.transform.Source}. - */ - private static class PayloadRequestCreator extends AbstractRequestCreator { - - private final Source payload; - - private TransformerHelper transformerHelper = new TransformerHelper(); - - PayloadRequestCreator(Source payload) { - this.payload = payload; - } - - @Override - protected void doWithRequest(WebServiceMessage request) throws IOException { - try { - transformerHelper.transform(payload, request.getPayloadResult()); - } - catch (TransformerException ex) { - throw new AssertionError("Could not transform request payload to message: " + ex.getMessage()); - } - } - } } diff --git a/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java b/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java index e398bde1..efc38a5d 100644 --- a/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java +++ b/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java @@ -27,7 +27,9 @@ import org.springframework.ws.soap.SoapBody; import org.springframework.ws.soap.SoapFault; import org.springframework.ws.soap.SoapMessage; import org.springframework.ws.soap.SoapVersion; -import org.springframework.ws.test.support.PayloadDiffMatcher; +import org.springframework.ws.test.support.matcher.PayloadDiffMatcher; +import org.springframework.ws.test.support.matcher.SchemaValidatingMatcher; +import org.springframework.ws.test.support.matcher.WebServiceMessageMatcher; import org.springframework.xml.transform.ResourceSource; import static org.springframework.ws.test.support.AssertionErrors.assertEquals; @@ -67,13 +69,7 @@ public abstract class ResponseMatchers { * @return the response matcher */ public static ResponseMatcher payload(Source payload) { - final PayloadDiffMatcher matcher = new PayloadDiffMatcher(payload); - return new ResponseMatcher() { - public void match(WebServiceMessage request, WebServiceMessage response) - throws IOException, AssertionError { - matcher.match(response); - } - }; + return new WebServiceMessageMatcherAdapter(new PayloadDiffMatcher(payload)); } /** @@ -86,6 +82,18 @@ public abstract class ResponseMatchers { return payload(new ResourceSource(payload)); } + /** + * Expects the payload to validate against the given XSD schema(s). + * + * @param schema the schema + * @param furtherSchemas further schemas, if necessary + * @return the response matcher + */ + public static ResponseMatcher validPayload(Resource schema, Resource... furtherSchemas) throws IOException { + return new WebServiceMessageMatcherAdapter(new SchemaValidatingMatcher(schema, furtherSchemas)); + } + + // SOAP Fault /** @@ -242,4 +250,20 @@ public abstract class ResponseMatchers { } + /** + * Adapts a {@link WebServiceMessageMatcher} to the {@link ResponseMatcher} contract. + */ + private static class WebServiceMessageMatcherAdapter implements ResponseMatcher { + + private final WebServiceMessageMatcher adaptee; + + private WebServiceMessageMatcherAdapter(WebServiceMessageMatcher adaptee) { + this.adaptee = adaptee; + } + + public void match(WebServiceMessage request, WebServiceMessage response) throws IOException, AssertionError { + adaptee.match(response); + } + } + } diff --git a/test/src/main/java/org/springframework/ws/test/support/DiffMatcher.java b/test/src/main/java/org/springframework/ws/test/support/matcher/DiffMatcher.java similarity index 56% rename from test/src/main/java/org/springframework/ws/test/support/DiffMatcher.java rename to test/src/main/java/org/springframework/ws/test/support/matcher/DiffMatcher.java index ff0251c8..fd3e3016 100644 --- a/test/src/main/java/org/springframework/ws/test/support/DiffMatcher.java +++ b/test/src/main/java/org/springframework/ws/test/support/matcher/DiffMatcher.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.ws.test.support; +package org.springframework.ws.test.support.matcher; import java.io.IOException; @@ -24,40 +24,31 @@ import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; import static org.springframework.ws.test.support.AssertionErrors.assertTrue; -import static org.springframework.ws.test.support.AssertionErrors.fail; /** - * Implementation of {@link org.springframework.ws.test.client.RequestMatcher} based on XMLUnit's {@link Diff}. + * Implementation of {@link WebServiceMessageMatcher} based on XMLUnit's {@link Diff}. * * @author Arjen Poutsma * @since 2.0 */ -public abstract class DiffMatcher { +public abstract class DiffMatcher implements WebServiceMessageMatcher { static { XMLUnit.setIgnoreWhitespace(true); } - public final void match(WebServiceMessage request) throws IOException, AssertionError { - try { - Diff diff = createDiff(request); - assertTrue("Messages are different, " + diff.toString(), diff.similar()); - } - catch (IOException ex) { - throw ex; - } - catch (Exception ex) { - fail("Could not create Diff: " + ex.getMessage()); - } + public final void match(WebServiceMessage message) throws IOException, AssertionError { + Diff diff = createDiff(message); + assertTrue("Messages are different, " + diff.toString(), diff.similar()); } /** - * Creates a {@link org.custommonkey.xmlunit.Diff} for the given request message. + * Creates a {@link Diff} for the given message. * - * @param request the request message + * @param message the message * @return the diff * @throws Exception in case of errors */ - protected abstract Diff createDiff(WebServiceMessage request) throws Exception; + protected abstract Diff createDiff(WebServiceMessage message); } diff --git a/test/src/main/java/org/springframework/ws/test/support/PayloadDiffMatcher.java b/test/src/main/java/org/springframework/ws/test/support/matcher/PayloadDiffMatcher.java similarity index 75% rename from test/src/main/java/org/springframework/ws/test/support/PayloadDiffMatcher.java rename to test/src/main/java/org/springframework/ws/test/support/matcher/PayloadDiffMatcher.java index e953fb87..d553a689 100644 --- a/test/src/main/java/org/springframework/ws/test/support/PayloadDiffMatcher.java +++ b/test/src/main/java/org/springframework/ws/test/support/matcher/PayloadDiffMatcher.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.ws.test.support; +package org.springframework.ws.test.support.matcher; import javax.xml.transform.Source; import javax.xml.transform.TransformerException; @@ -48,23 +48,29 @@ public class PayloadDiffMatcher extends DiffMatcher { } @Override - protected final Diff createDiff(WebServiceMessage request) throws Exception { - Source payload = request.getPayloadSource(); + protected final Diff createDiff(WebServiceMessage message) { + Source payload = message.getPayloadSource(); if (payload == null) { fail("Request message does not contain payload"); } return createDiff(payload); } - protected Diff createDiff(Source payload) throws TransformerException { + protected Diff createDiff(Source payload) { Document expectedDocument = createDocumentFromSource(expected); Document actualDocument = createDocumentFromSource(payload); return new Diff(expectedDocument, actualDocument); } - private Document createDocumentFromSource(Source source) throws TransformerException { - DOMResult result = new DOMResult(); - transformerHelper.transform(source, result); - return (Document) result.getNode(); + 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; + } } } \ No newline at end of file diff --git a/test/src/main/java/org/springframework/ws/test/support/matcher/SchemaValidatingMatcher.java b/test/src/main/java/org/springframework/ws/test/support/matcher/SchemaValidatingMatcher.java new file mode 100644 index 00000000..19e7fd4a --- /dev/null +++ b/test/src/main/java/org/springframework/ws/test/support/matcher/SchemaValidatingMatcher.java @@ -0,0 +1,66 @@ +/* + * 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. + * 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 java.io.IOException; +import java.util.Arrays; + +import org.springframework.core.io.Resource; +import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; +import org.springframework.ws.WebServiceMessage; +import org.springframework.xml.validation.XmlValidator; +import org.springframework.xml.validation.XmlValidatorFactory; + +import org.xml.sax.SAXParseException; + +import static org.springframework.ws.test.support.AssertionErrors.fail; + +/** + * Uses the {@link XmlValidator} to validate request payload. + * + * @author Lukas Krecan + * @author Arjen Poutsma + * @since 2.0 + */ +public class SchemaValidatingMatcher implements WebServiceMessageMatcher { + + private final XmlValidator xmlValidator; + + /** + * Creates a {@code SchemaValidatingMatcher} based on the given schema resource(s). + * + * @param schema the schema + * @param furtherSchemas further schemas, if necessary + * @throws IOException in case of I/O errors + */ + public SchemaValidatingMatcher(Resource schema, Resource... furtherSchemas) throws IOException { + Assert.notNull(schema, "'schema' must not be null"); + Resource[] joinedSchemas = new Resource[furtherSchemas.length + 1]; + joinedSchemas[0] = schema; + System.arraycopy(furtherSchemas, 0, joinedSchemas, 1, furtherSchemas.length); + xmlValidator = XmlValidatorFactory.createValidator(joinedSchemas, XmlValidatorFactory.SCHEMA_W3C_XML); + + } + + public void match(WebServiceMessage message) throws IOException, AssertionError { + SAXParseException[] exceptions = xmlValidator.validate(message.getPayloadSource()); + if (!ObjectUtils.isEmpty(exceptions)) { + fail("XML is not valid: " + Arrays.toString(exceptions)); + } + } +} diff --git a/test/src/main/java/org/springframework/ws/test/support/matcher/WebServiceMessageMatcher.java b/test/src/main/java/org/springframework/ws/test/support/matcher/WebServiceMessageMatcher.java new file mode 100644 index 00000000..4e96d7b0 --- /dev/null +++ b/test/src/main/java/org/springframework/ws/test/support/matcher/WebServiceMessageMatcher.java @@ -0,0 +1,40 @@ +/* + * 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. + * 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 java.io.IOException; + +import org.springframework.ws.WebServiceMessage; + +/** + * Defines the general contract for matching messages to expectations. + * + * @author Arjen Poutsma + * @since 2.0 + */ +public interface WebServiceMessageMatcher { + + /** + * Matches the given message against the expectations. Implementations typically make use of JUnit-based + * assertions. + * + * @param message the message + * @throws IOException in case of I/O errors + * @throws AssertionError if expectations are not met + */ + void match(WebServiceMessage message) throws IOException, AssertionError; +} diff --git a/test/src/main/java/org/springframework/ws/test/support/matcher/package-info.java b/test/src/main/java/org/springframework/ws/test/support/matcher/package-info.java new file mode 100644 index 00000000..fea27d57 --- /dev/null +++ b/test/src/main/java/org/springframework/ws/test/support/matcher/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + * 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. + */ + +/** + * Provides the generic {@link org.springframework.ws.test.support.matcher.WebServiceMessageMatcher WebServiceMessageMatcher} + * interface, and implementations. + */ +package org.springframework.ws.test.support.matcher; diff --git a/test/src/main/java/org/springframework/ws/test/support/package-info.java b/test/src/main/java/org/springframework/ws/test/support/package-info.java new file mode 100644 index 00000000..cd2ae355 --- /dev/null +++ b/test/src/main/java/org/springframework/ws/test/support/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + * 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. + */ + +/** + * Support classes for the testing framework, used by the classes in the {@link org.springframework.ws.test.client} and + * {@link org.springframework.ws.test.server} packages. + */ +package org.springframework.ws.test.support; diff --git a/test/src/test/java/org/springframework/ws/test/support/PayloadDiffMatcherTest.java b/test/src/test/java/org/springframework/ws/test/support/matcher/PayloadDiffMatcherTest.java similarity index 97% rename from test/src/test/java/org/springframework/ws/test/support/PayloadDiffMatcherTest.java rename to test/src/test/java/org/springframework/ws/test/support/matcher/PayloadDiffMatcherTest.java index 56ba7278..6cad8366 100644 --- a/test/src/test/java/org/springframework/ws/test/support/PayloadDiffMatcherTest.java +++ b/test/src/test/java/org/springframework/ws/test/support/matcher/PayloadDiffMatcherTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.ws.test.support; +package org.springframework.ws.test.support.matcher; import javax.xml.soap.MessageFactory; diff --git a/test/src/test/java/org/springframework/ws/test/client/SchemaValidatingRequestMatcherTest.java b/test/src/test/java/org/springframework/ws/test/support/matcher/SchemaValidatingMatcherTest.java similarity index 73% rename from test/src/test/java/org/springframework/ws/test/client/SchemaValidatingRequestMatcherTest.java rename to test/src/test/java/org/springframework/ws/test/support/matcher/SchemaValidatingMatcherTest.java index 417b3296..c8f0c1f3 100644 --- a/test/src/test/java/org/springframework/ws/test/client/SchemaValidatingRequestMatcherTest.java +++ b/test/src/test/java/org/springframework/ws/test/support/matcher/SchemaValidatingMatcherTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.ws.test.client; +package org.springframework.ws.test.support.matcher; import java.io.IOException; @@ -23,15 +23,13 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.ws.WebServiceMessage; import org.springframework.xml.transform.StringSource; -import org.springframework.xml.validation.XmlValidator; -import org.springframework.xml.validation.XmlValidatorFactory; import org.junit.Before; import org.junit.Test; import static org.easymock.EasyMock.*; -public class SchemaValidatingRequestMatcherTest { +public class SchemaValidatingMatcherTest { private Resource schema2; @@ -42,7 +40,7 @@ public class SchemaValidatingRequestMatcherTest { @Before public void setUp() { message = createMock(WebServiceMessage.class); - schema1 = new ClassPathResource("schemaValidatingRequestMatcherTest.xsd", SchemaValidatingRequestMatcherTest.class); + schema1 = new ClassPathResource("schemaValidatingMatcherTest.xsd", SchemaValidatingMatcherTest.class); schema2 = new ByteArrayResource("".getBytes()); } @@ -51,11 +49,11 @@ public class SchemaValidatingRequestMatcherTest { expect(message.getPayloadSource()).andReturn(new StringSource( "0text")); - RequestMatcher requestMatcher = RequestMatchers.validPayload(schema1); + SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema1); replay(message); - requestMatcher.match(null, message); + matcher.match(message); verify(message); } @@ -65,11 +63,11 @@ public class SchemaValidatingRequestMatcherTest { expect(message.getPayloadSource()).andReturn(new StringSource( "atext")); - RequestMatcher requestMatcher = RequestMatchers.validPayload(schema1); + SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema1); replay(message); - requestMatcher.match(null, message); + matcher.match(message); verify(message); } @@ -79,11 +77,11 @@ public class SchemaValidatingRequestMatcherTest { expect(message.getPayloadSource()).andReturn(new StringSource( "0text")); - RequestMatcher requestMatcher = RequestMatchers.validPayload(schema1, schema2); + SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema1, schema2); replay(message); - requestMatcher.match(null, message); + matcher.match(message); verify(message); } @@ -93,11 +91,11 @@ public class SchemaValidatingRequestMatcherTest { expect(message.getPayloadSource()).andReturn(new StringSource( "atext")); - RequestMatcher requestMatcher = RequestMatchers.validPayload(schema1, schema2); + SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema1, schema2); replay(message); - requestMatcher.match(null, message); + matcher.match(message); verify(message); } @@ -107,11 +105,11 @@ public class SchemaValidatingRequestMatcherTest { expect(message.getPayloadSource()).andReturn(new StringSource( "atext")); - RequestMatcher requestMatcher = RequestMatchers.validPayload(schema2, schema1); + SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema2, schema1); replay(message); - requestMatcher.match(null, message); + matcher.match(message); verify(message); } @@ -121,12 +119,11 @@ public class SchemaValidatingRequestMatcherTest { expect(message.getPayloadSource()).andReturn(new StringSource( "atext")); - XmlValidator validator = XmlValidatorFactory.createValidator(schema1, XmlValidatorFactory.SCHEMA_W3C_XML); - RequestMatcher requestMatcher = new SchemaValidatingRequestMatcher(validator); + SchemaValidatingMatcher matcher = new SchemaValidatingMatcher(schema1); replay(message); - requestMatcher.match(null, message); + matcher.match(message); verify(message); } diff --git a/test/src/test/resources/org/springframework/ws/test/support/matcher/schemaValidatingMatcherTest.xsd b/test/src/test/resources/org/springframework/ws/test/support/matcher/schemaValidatingMatcherTest.xsd new file mode 100644 index 00000000..a0bc71eb --- /dev/null +++ b/test/src/test/resources/org/springframework/ws/test/support/matcher/schemaValidatingMatcherTest.xsd @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/test/src/test/resources/org/springframework/ws/test/support/schemaValidatingMatcherTest.xsd b/test/src/test/resources/org/springframework/ws/test/support/schemaValidatingMatcherTest.xsd new file mode 100644 index 00000000..a0bc71eb --- /dev/null +++ b/test/src/test/resources/org/springframework/ws/test/support/schemaValidatingMatcherTest.xsd @@ -0,0 +1,12 @@ + + + + + + + + + + + +