diff --git a/test/src/test/java/org/springframework/ws/mock/client/ExceptionResponseCallbackTest.java b/test/src/test/java/org/springframework/ws/mock/client/ExceptionResponseCallbackTest.java deleted file mode 100644 index a80c6233..00000000 --- a/test/src/test/java/org/springframework/ws/mock/client/ExceptionResponseCallbackTest.java +++ /dev/null @@ -1,38 +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.mock.client; - -import java.io.IOException; - -import org.junit.Test; - -public class ExceptionResponseCallbackTest { - - @Test(expected = IOException.class) - public void ioException() throws Exception { - ExceptionResponseCallback callback = new ExceptionResponseCallback(new IOException()); - - callback.doWithResponse(null, null); - } - - @Test(expected = RuntimeException.class) - public void runtimeException() throws Exception { - ExceptionResponseCallback callback = new ExceptionResponseCallback(new RuntimeException()); - - callback.doWithResponse(null, null); - } -} diff --git a/test/src/test/java/org/springframework/ws/mock/client/MockSenderConnectionTest.java b/test/src/test/java/org/springframework/ws/mock/client/MockSenderConnectionTest.java deleted file mode 100644 index 0a441a2b..00000000 --- a/test/src/test/java/org/springframework/ws/mock/client/MockSenderConnectionTest.java +++ /dev/null @@ -1,123 +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.mock.client; - -import java.net.URI; - -import org.springframework.ws.WebServiceMessage; -import org.springframework.ws.WebServiceMessageFactory; - -import org.junit.Before; -import org.junit.Test; - -import static org.easymock.EasyMock.*; -import static org.junit.Assert.*; - -/** @author Arjen Poutsma */ -public class MockSenderConnectionTest { - - private MockSenderConnection connection; - - @Before - public void setUp() throws Exception { - connection = new MockSenderConnection(); - } - - @Test - public void uri() throws Exception { - assertTrue("connection does not have any URI", connection.hasAnyUri()); - URI uri = new URI("http://example.com"); - connection = new MockSenderConnection(uri); - assertEquals("Invalid uri", uri, connection.getUri()); - } - - @Test - public void sendMatch() throws Exception { - RequestMatcher requestMatcher1 = createMock("requestMatcher1", RequestMatcher.class); - RequestMatcher requestMatcher2 = createMock("requestMatcher2", RequestMatcher.class); - connection.addRequestMatcher(requestMatcher1); - connection.addRequestMatcher(requestMatcher2); - WebServiceMessage request = createMock("request", WebServiceMessage.class); - - requestMatcher1.match(request); - requestMatcher2.match(request); - - replay(requestMatcher1, requestMatcher2, request); - - connection.send(request); - - verify(requestMatcher1, requestMatcher2, request); - } - - @Test(expected = AssertionError.class) - public void sendNonMatch() throws Exception { - RequestMatcher requestMatcher1 = createMock("requestMatcher1", RequestMatcher.class); - RequestMatcher requestMatcher2 = createMock("requestMatcher2", RequestMatcher.class); - connection.addRequestMatcher(requestMatcher1); - connection.addRequestMatcher(requestMatcher2); - WebServiceMessage request = createMock("request", WebServiceMessage.class); - - requestMatcher1.match(request); - expectLastCall().andThrow(new AssertionError()); - - replay(requestMatcher1, requestMatcher2, request); - - connection.send(request); - } - - @Test - public void receive() throws Exception { - ResponseCallback responseCallback = createMock(ResponseCallback.class); - WebServiceMessageFactory messageFactory = createMock(WebServiceMessageFactory.class); - WebServiceMessage response = createMock("response", WebServiceMessage.class); - connection.setResponseCallback(responseCallback); - - expect(messageFactory.createWebServiceMessage()).andReturn(response); - responseCallback.doWithResponse(null, response); - - replay(responseCallback, messageFactory, response); - - WebServiceMessage result = connection.receive(messageFactory); - assertSame(response, result); - - verify(responseCallback, messageFactory, response); - } - - @Test - public void sendAndReceive() throws Exception { - WebServiceMessageFactory messageFactory = createMock(WebServiceMessageFactory.class); - WebServiceMessage request = createMock("request", WebServiceMessage.class); - WebServiceMessage response = createMock("response", WebServiceMessage.class); - - RequestMatcher requestMatcher = createMock("requestMatcher1", RequestMatcher.class); - ResponseCallback responseCallback = createMock(ResponseCallback.class); - connection.addRequestMatcher(requestMatcher).setResponseCallback(responseCallback); - - requestMatcher.match(request); - - expect(messageFactory.createWebServiceMessage()).andReturn(response); - responseCallback.doWithResponse(request, response); - - replay(responseCallback, messageFactory, response, request, requestMatcher); - - connection.send(request); - WebServiceMessage result = connection.receive(messageFactory); - assertSame(response, result); - - verify(responseCallback, messageFactory, response, request, requestMatcher); - } -} diff --git a/test/src/test/java/org/springframework/ws/mock/client/MockWebServiceMessageSenderTest.java b/test/src/test/java/org/springframework/ws/mock/client/MockWebServiceMessageSenderTest.java deleted file mode 100644 index f551913a..00000000 --- a/test/src/test/java/org/springframework/ws/mock/client/MockWebServiceMessageSenderTest.java +++ /dev/null @@ -1,160 +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.mock.client; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.dom.DOMSource; - -import org.springframework.ws.client.WebServiceIOException; -import org.springframework.ws.client.WebServiceTransportException; -import org.springframework.ws.client.core.WebServiceTemplate; -import org.springframework.ws.soap.client.SoapFaultClientException; -import org.springframework.xml.transform.StringResult; -import org.springframework.xml.transform.StringSource; - -import org.custommonkey.xmlunit.XMLUnit; -import org.junit.Before; -import org.junit.Test; -import org.w3c.dom.Document; - -import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; - -public class MockWebServiceMessageSenderTest { - - private MockWebServiceMessageSender messageSender; - - private WebServiceTemplate template; - - @Before - public void setUp() throws Exception { - messageSender = new MockWebServiceMessageSender(); - template = new WebServiceTemplate(); - template.setMessageSender(messageSender); - template.setDefaultUri("http://example.com/airline"); - XMLUnit.setIgnoreWhitespace(true); - } - - @Test - public void normal() throws Exception { - String request = ""; - String response = ""; - - messageSender.whenConnecting().expectPayload(request).andRespondWithPayload(response); - messageSender.replay(); - - StringResult result = new StringResult(); - template.sendSourceAndReceiveToResult(new StringSource(request), result); - assertXMLEqual(result.toString(), response); - messageSender.verify(); - } - - @Test - public void normalDomSource() throws Exception { - String request = ""; - String response = ""; - - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - Document document = factory.newDocumentBuilder().parse(new ByteArrayInputStream(request.getBytes())); - - messageSender.whenConnecting().expectPayload(new DOMSource(document)).andRespondWithPayload(response); - messageSender.replay(); - - - StringResult result = new StringResult(); - template.sendSourceAndReceiveToResult(new StringSource(request), result); - assertXMLEqual(result.toString(), response); - messageSender.verify(); - } - - @Test(expected = AssertionError.class) - public void invalidRequest() throws Exception { - String expectedRequest = ""; - - messageSender.whenConnecting().expectPayload(expectedRequest); - messageSender.replay(); - - String realRequest = ""; - template.sendSourceAndReceiveToResult(new StringSource(realRequest), new StringResult()); - messageSender.verify(); - } - - @Test(expected = AssertionError.class) - public void wrongUri() throws Exception { - String expectedUri = "http://example.com/1"; - - messageSender.whenConnectingTo(expectedUri); - messageSender.replay(); - - String realUri = "http://example.com/2"; - template.sendSourceAndReceiveToResult(realUri, null, null); - messageSender.verify(); - } - - @Test(expected = AssertionError.class) - public void notAllUris() throws Exception { - String expectedUri1 = "http://example.com/1"; - String expectedUri2 = "http://example.com/2"; - String request = ""; - String response = ""; - - - messageSender.whenConnectingTo(expectedUri1).expectPayload(request).andRespondWithPayload(response); - messageSender.whenConnectingTo(expectedUri2).expectPayload(request).andRespondWithPayload(response); - messageSender.replay(); - - template.sendSourceAndReceiveToResult(expectedUri1, new StringSource(request), new StringResult()); - messageSender.verify(); - } - - @Test(expected = WebServiceTransportException.class) - public void error() throws Exception { - String request = ""; - - messageSender.whenConnecting().expectPayload(request).andRespondWithError("Something went wrong"); - messageSender.replay(); - - template.sendSourceAndReceiveToResult(new StringSource(request), new StringResult()); - messageSender.verify(); - } - - @Test(expected = WebServiceIOException.class) - public void ioException() throws Exception { - String request = ""; - - IOException ex = new IOException("Something went wrong"); - messageSender.whenConnecting().expectPayload(request).andThrowException(ex); - messageSender.replay(); - - template.sendSourceAndReceiveToResult(new StringSource(request), new StringResult()); - messageSender.verify(); - } - - @Test(expected = SoapFaultClientException.class) - public void soapFault() throws Exception { - String request = ""; - - String faultString = "Foo"; - messageSender.whenConnecting().expectPayload(request).andRespondWithMustUnderstandFault(faultString, null); - messageSender.replay(); - - template.sendSourceAndReceiveToResult(new StringSource(request), new StringResult()); - messageSender.verify(); - } - -} diff --git a/test/src/test/java/org/springframework/ws/mock/client/PayloadMatcherTest.java b/test/src/test/java/org/springframework/ws/mock/client/PayloadMatcherTest.java deleted file mode 100644 index 3bf69d74..00000000 --- a/test/src/test/java/org/springframework/ws/mock/client/PayloadMatcherTest.java +++ /dev/null @@ -1,53 +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.mock.client; - -import org.springframework.ws.WebServiceMessage; -import org.springframework.xml.transform.StringSource; - -import org.junit.Test; - -import static org.easymock.EasyMock.*; - -public class PayloadMatcherTest { - - @Test - public void match() throws Exception { - String xml = ""; - WebServiceMessage message = createMock(WebServiceMessage.class); - expect(message.getPayloadSource()).andReturn(new StringSource(xml)); - replay(message); - - PayloadMatcher matcher = new PayloadMatcher(new StringSource(xml)); - matcher.match(message); - - verify(message); - } - - @Test(expected = AssertionError.class) - public void nonMatch() throws Exception { - String actual = ""; - WebServiceMessage message = createMock(WebServiceMessage.class); - expect(message.getPayloadSource()).andReturn(new StringSource(actual)); - replay(message); - - String expected = ""; - PayloadMatcher matcher = new PayloadMatcher(new StringSource(expected)); - matcher.match(message); - } - -} diff --git a/test/src/test/java/org/springframework/ws/mock/client/SoapHeaderMatcherTest.java b/test/src/test/java/org/springframework/ws/mock/client/SoapHeaderMatcherTest.java deleted file mode 100644 index 3f8cfd26..00000000 --- a/test/src/test/java/org/springframework/ws/mock/client/SoapHeaderMatcherTest.java +++ /dev/null @@ -1,70 +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.mock.client; - -import javax.xml.namespace.QName; -import javax.xml.soap.MessageFactory; -import javax.xml.soap.SOAPMessage; - -import org.springframework.ws.WebServiceMessage; -import org.springframework.ws.soap.SoapMessage; -import org.springframework.ws.soap.saaj.SaajSoapMessage; - -import org.junit.Before; -import org.junit.Test; - -import static org.easymock.EasyMock.createMock; - -public class SoapHeaderMatcherTest { - - private SoapHeaderMatcher matcher; - - private QName expectedHeaderName; - - @Before - public void setUp() throws Exception { - expectedHeaderName = new QName("http://example.com", "header"); - matcher = new SoapHeaderMatcher(expectedHeaderName); - } - - @Test - public void match() throws Exception { - MessageFactory messageFactory = MessageFactory.newInstance(); - SOAPMessage saajMessage = messageFactory.createMessage(); - saajMessage.getSOAPHeader().addHeaderElement(expectedHeaderName); - SoapMessage soapMessage = new SaajSoapMessage(saajMessage); - - matcher.match(soapMessage); - } - - @Test(expected = AssertionError.class) - public void nonMatch() throws Exception { - MessageFactory messageFactory = MessageFactory.newInstance(); - SOAPMessage saajMessage = messageFactory.createMessage(); - SoapMessage soapMessage = new SaajSoapMessage(saajMessage); - - matcher.match(soapMessage); - } - - @Test(expected = AssertionError.class) - public void nonSoap() throws Exception { - WebServiceMessage message = createMock(WebServiceMessage.class); - - matcher.match(message); - } - -}