Moving client2 to client

This commit is contained in:
Arjen Poutsma
2010-07-14 06:59:14 +00:00
parent f4b37ceadb
commit 79354777dc
5 changed files with 0 additions and 444 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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 = "<request xmlns='http://example.com'/>";
String response = "<response xmlns='http://example.com'/>";
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 = "<request xmlns='http://example.com'/>";
String response = "<response xmlns='http://example.com'/>";
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 = "<request1 xmlns='http://example.com'/>";
messageSender.whenConnecting().expectPayload(expectedRequest);
messageSender.replay();
String realRequest = "<request2 xmlns='http://example.com'/>";
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 = "<request xmlns='http://example.com'/>";
String response = "<response xmlns='http://example.com'/>";
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 = "<root xmlns='http://example.com'/>";
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 = "<root xmlns='http://example.com'/>";
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 = "<root xmlns='http://example.com'/>";
String faultString = "Foo";
messageSender.whenConnecting().expectPayload(request).andRespondWithMustUnderstandFault(faultString, null);
messageSender.replay();
template.sendSourceAndReceiveToResult(new StringSource(request), new StringResult());
messageSender.verify();
}
}

View File

@@ -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 = "<element xmlns='http://example.com'/>";
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 = "<element1 xmlns='http://example.com'/>";
WebServiceMessage message = createMock(WebServiceMessage.class);
expect(message.getPayloadSource()).andReturn(new StringSource(actual));
replay(message);
String expected = "<element2 xmlns='http://example.com'/>";
PayloadMatcher matcher = new PayloadMatcher(new StringSource(expected));
matcher.match(message);
}
}

View File

@@ -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);
}
}