1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.test.client;
18
19 import java.io.IOException;
20 import java.net.URI;
21 import java.util.Iterator;
22 import java.util.LinkedList;
23 import java.util.List;
24
25 import org.springframework.util.Assert;
26 import org.springframework.ws.transport.WebServiceMessageSender;
27
28
29
30
31
32
33
34
35
36 class MockWebServiceMessageSender implements WebServiceMessageSender {
37
38 private final List<MockSenderConnection> expectedConnections = new LinkedList<MockSenderConnection>();
39
40 private Iterator<MockSenderConnection> connectionIterator;
41
42 public MockSenderConnection createConnection(URI uri) throws IOException {
43 Assert.notNull(uri, "'uri' must not be null");
44 if (connectionIterator == null) {
45 connectionIterator = expectedConnections.iterator();
46 }
47 if (!connectionIterator.hasNext()) {
48 throw new AssertionError("No further connections expected");
49 }
50
51 MockSenderConnection currentConnection = connectionIterator.next();
52 currentConnection.setUri(uri);
53 return currentConnection;
54 }
55
56
57
58
59 public boolean supports(URI uri) {
60 return true;
61 }
62
63 MockSenderConnection expectNewConnection() {
64 Assert.state(connectionIterator == null, "Can not expect another connection, the test is already underway");
65 MockSenderConnection connection = new MockSenderConnection();
66 expectedConnections.add(connection);
67 return connection;
68 }
69
70 void verifyConnections() {
71 if (expectedConnections.isEmpty()) {
72 return;
73 }
74 if (connectionIterator == null || connectionIterator.hasNext()) {
75 throw new AssertionError("Further connection(s) expected");
76 }
77 }
78
79 }