From 1859c89040f05fab5ed7a73bc97e9110492726d3 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Fri, 16 Jul 2010 14:19:50 +0000 Subject: [PATCH] SWS-544 - Removed JUnit as a compile dependency --- test/pom.xml | 2 +- .../ws/mock/client/Assert.java | 65 +++++++++++++++++++ .../ws/mock/client/DiffMatcher.java | 8 +-- .../ws/mock/client/PayloadDiffMatcher.java | 2 +- .../client/SoapFaultResponseCallback.java | 4 +- .../ws/mock/client/SoapHeaderMatcher.java | 8 ++- .../ws/mock/client/UriMatcher.java | 2 +- test/template.mf | 1 - 8 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 test/src/main/java/org/springframework/ws/mock/client/Assert.java diff --git a/test/pom.xml b/test/pom.xml index 1feb256b..d99c754a 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -42,7 +42,7 @@ junit junit - compile + test xmlunit diff --git a/test/src/main/java/org/springframework/ws/mock/client/Assert.java b/test/src/main/java/org/springframework/ws/mock/client/Assert.java new file mode 100644 index 00000000..c8a5caff --- /dev/null +++ b/test/src/main/java/org/springframework/ws/mock/client/Assert.java @@ -0,0 +1,65 @@ +/* + * 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.mock.client; + +/** + * JUnit independent assertion class. + * + * @author Lukas Krecan + * @author Arjen Poutsma + * @since 2.0 + */ +class Assert { + + /** + * Fails a test with the given message. + * + * @param message the message + */ + static void fail(String message) { + throw new AssertionError(message); + } + + /** + * Asserts that a condition is {@code true}. If not, throws an {@link AssertionError} with the given message. + * + * @param message the message + * @param condition the condition to test for + */ + static void assertTrue(String message, boolean condition) { + if (!condition) { + fail(message); + } + } + + /** + * Asserts that two objects are equal. If not, an {@link AssertionError} is thrown with the given message. + * + * @param message the message + * @param expected the expected value + * @param actual the actual value + */ + static void assertEquals(String message, Object expected, Object actual) { + if (expected == null && actual == null) { + return; + } + if (expected != null && expected.equals(actual)) { + return; + } + fail(message + " expected:<" + expected + "> but was:<" + actual + ">"); + } +} diff --git a/test/src/main/java/org/springframework/ws/mock/client/DiffMatcher.java b/test/src/main/java/org/springframework/ws/mock/client/DiffMatcher.java index 1ef744e6..a7b545b8 100644 --- a/test/src/main/java/org/springframework/ws/mock/client/DiffMatcher.java +++ b/test/src/main/java/org/springframework/ws/mock/client/DiffMatcher.java @@ -24,8 +24,8 @@ import org.springframework.xml.transform.TransformerObjectSupport; import org.custommonkey.xmlunit.Diff; -import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; -import static org.custommonkey.xmlunit.XMLAssert.fail; +import static org.springframework.ws.mock.client.Assert.assertTrue; +import static org.springframework.ws.mock.client.Assert.fail; /** * Implementation of {@link RequestMatcher} based on XMLUnit's {@link Diff}. @@ -38,7 +38,7 @@ abstract class DiffMatcher extends TransformerObjectSupport implements RequestMa public final void match(URI uri, WebServiceMessage request) throws IOException, AssertionError { try { Diff diff = createDiff(request); - assertXMLEqual(diff, true); + assertTrue("Messages are different, " + diff.toString(), diff.similar()); } catch (IOException ex) { throw ex; @@ -57,4 +57,4 @@ abstract class DiffMatcher extends TransformerObjectSupport implements RequestMa */ protected abstract Diff createDiff(WebServiceMessage request) throws Exception; -} \ No newline at end of file +} diff --git a/test/src/main/java/org/springframework/ws/mock/client/PayloadDiffMatcher.java b/test/src/main/java/org/springframework/ws/mock/client/PayloadDiffMatcher.java index fb716d0f..6ced4252 100644 --- a/test/src/main/java/org/springframework/ws/mock/client/PayloadDiffMatcher.java +++ b/test/src/main/java/org/springframework/ws/mock/client/PayloadDiffMatcher.java @@ -26,7 +26,7 @@ import org.springframework.ws.WebServiceMessage; import org.custommonkey.xmlunit.Diff; import org.w3c.dom.Document; -import static junit.framework.Assert.fail; +import static org.springframework.ws.mock.client.Assert.fail; /** * Matches {@link Source} payloads. diff --git a/test/src/main/java/org/springframework/ws/mock/client/SoapFaultResponseCallback.java b/test/src/main/java/org/springframework/ws/mock/client/SoapFaultResponseCallback.java index 94b84492..3b1579ff 100644 --- a/test/src/main/java/org/springframework/ws/mock/client/SoapFaultResponseCallback.java +++ b/test/src/main/java/org/springframework/ws/mock/client/SoapFaultResponseCallback.java @@ -23,7 +23,7 @@ import org.springframework.ws.WebServiceMessage; import org.springframework.ws.soap.SoapBody; import org.springframework.ws.soap.SoapMessage; -import static org.junit.Assert.fail; +import static org.springframework.ws.mock.client.Assert.fail; /** * Implementation of {@link ResponseCallback} that responds with a SOAP fault. @@ -92,4 +92,4 @@ abstract class SoapFaultResponseCallback implements ResponseCallback { } -} \ No newline at end of file +} diff --git a/test/src/main/java/org/springframework/ws/mock/client/SoapHeaderMatcher.java b/test/src/main/java/org/springframework/ws/mock/client/SoapHeaderMatcher.java index 354b32e5..d13d4036 100644 --- a/test/src/main/java/org/springframework/ws/mock/client/SoapHeaderMatcher.java +++ b/test/src/main/java/org/springframework/ws/mock/client/SoapHeaderMatcher.java @@ -26,8 +26,9 @@ import org.springframework.ws.soap.SoapHeader; import org.springframework.ws.soap.SoapHeaderElement; import org.springframework.ws.soap.SoapMessage; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.springframework.ws.mock.client.Assert.assertTrue; +import static org.springframework.ws.mock.client.Assert.fail; + /** * Matches SOAP headers. @@ -52,6 +53,7 @@ class SoapHeaderMatcher implements RequestMatcher { SoapHeader soapHeader = soapMessage.getSoapHeader(); if (soapHeader == null) { fail("SOAP message [" + soapMessage + "] does not contain SOAP header"); + return; } Iterator soapHeaderElementIterator = soapHeader.examineAllHeaderElements(); boolean found = false; @@ -64,4 +66,4 @@ class SoapHeaderMatcher implements RequestMatcher { } assertTrue("SOAP header [" + soapHeaderName + "] not found", found); } -} \ No newline at end of file +} diff --git a/test/src/main/java/org/springframework/ws/mock/client/UriMatcher.java b/test/src/main/java/org/springframework/ws/mock/client/UriMatcher.java index 0c8ca8ce..461fbc69 100644 --- a/test/src/main/java/org/springframework/ws/mock/client/UriMatcher.java +++ b/test/src/main/java/org/springframework/ws/mock/client/UriMatcher.java @@ -20,7 +20,7 @@ import java.net.URI; import org.springframework.ws.WebServiceMessage; -import static org.junit.Assert.assertEquals; +import static org.springframework.ws.mock.client.Assert.assertEquals; /** * Matches {@link URI}s. diff --git a/test/template.mf b/test/template.mf index 1d992fa0..6e57b41b 100644 --- a/test/template.mf +++ b/test/template.mf @@ -8,7 +8,6 @@ Import-Template: javax.xml.parsers.*;version="0", javax.xml.transform.*;version="0", org.custommonkey.xmlunit.*;version="[1.3.0, 2.0.0)", - org.junit.*;version="[4.7.0, 5.0.0)", org.springframework.core.*;version=${spring.framework.osgi.range}, org.springframework.util.*;version=${spring.framework.osgi.range}, org.springframework.ws.*;version=${osgi.range},