SWS-631 -verifyConnections() method
This commit is contained in:
@@ -87,6 +87,8 @@ public class GetFlightsTest {
|
||||
|
||||
getFlights.getFlights();
|
||||
|
||||
verifyConnections();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -70,4 +70,13 @@ class MockWebServiceMessageSender implements WebServiceMessageSender {
|
||||
return connection;
|
||||
}
|
||||
|
||||
void verifyConnections() {
|
||||
if (expectedConnections.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (connectionIterator == null || connectionIterator.hasNext()) {
|
||||
throw new AssertionError("Further connection(s) expected");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -282,6 +282,20 @@ public abstract class WebServiceMock {
|
||||
return SoapFaultResponseCallback.createVersionMismatchFault(faultStringOrReason, locale);
|
||||
}
|
||||
|
||||
// Verification
|
||||
|
||||
/**
|
||||
* Verifies that all connections were used.
|
||||
*
|
||||
* @throws AssertionError in case of unused connections.
|
||||
*/
|
||||
public static void verifyConnections() {
|
||||
MockWebServiceMessageSender messageSender = MockWebServiceMessageSenderHolder.get();
|
||||
if (messageSender != null) {
|
||||
messageSender.verifyConnections();
|
||||
}
|
||||
}
|
||||
|
||||
private static ResourceSource createResourceSource(Resource resource) {
|
||||
try {
|
||||
return new ResourceSource(resource);
|
||||
|
||||
@@ -19,13 +19,34 @@ package org.springframework.ws.mock.client;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MockWebServiceMessageSenderTest {
|
||||
|
||||
private MockWebServiceMessageSender sender;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
sender = new MockWebServiceMessageSender();
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testNoMoreExpectedConnections() throws IOException {
|
||||
MockWebServiceMessageSender sender = new MockWebServiceMessageSender();
|
||||
public void noMoreExpectedConnections() throws IOException {
|
||||
sender.createConnection(URI.create("http://localhost"));
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void verify() throws IOException {
|
||||
sender.expectNewConnection();
|
||||
sender.verifyConnections();
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void verifyMoteThanOne() throws IOException {
|
||||
sender.expectNewConnection();
|
||||
sender.expectNewConnection();
|
||||
sender.createConnection(URI.create("http://localhost"));
|
||||
sender.verifyConnections();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,6 +225,8 @@ public class WebServiceMockTest {
|
||||
StringResult result = new StringResult();
|
||||
template.sendSourceAndReceiveToResult(request, result);
|
||||
assertXMLEqual(result.toString(), response.toString());
|
||||
|
||||
verifyConnections();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@@ -242,5 +244,14 @@ public class WebServiceMockTest {
|
||||
expect(anything()).andRespond(withPayload(response));
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void verifyFailure() throws Exception {
|
||||
expect(anything());
|
||||
verifyConnections();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyOnly() throws Exception {
|
||||
verifyConnections();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,8 @@ public class IntegrationTest {
|
||||
|
||||
CustomerCountResponse response = (CustomerCountResponse) webServiceTemplate.marshalSendAndReceive(request);
|
||||
assertEquals(10, response.getCustomerCount());
|
||||
|
||||
verifyConnections();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user