1
2
3
4
5
6
7
8
9
10
11 package org.mule.tck.providers.soap;
12
13 import org.mule.extras.client.MuleClient;
14 import org.mule.providers.http.HttpConnector;
15 import org.mule.providers.http.HttpConstants;
16 import org.mule.tck.FunctionalTestCase;
17 import org.mule.tck.testmodels.services.Person;
18 import org.mule.umo.UMOException;
19 import org.mule.umo.UMOMessage;
20 import org.mule.umo.provider.DispatchException;
21
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 public abstract class AbstractSoapFunctionalTestCase extends FunctionalTestCase
28 {
29
30 protected AbstractSoapFunctionalTestCase()
31 {
32 super.setDisposeManagerPerSuite(true);
33 }
34
35 protected abstract String getRequestResponseEndpoint();
36
37 protected abstract String getReceiveEndpoint();
38
39 protected abstract String getReceiveComplexEndpoint();
40
41 protected abstract String getSendReceiveComplexEndpoint1();
42
43 protected abstract String getSendReceiveComplexEndpoint2();
44
45 protected abstract String getReceiveComplexCollectionEndpoint();
46
47 protected abstract String getDispatchAsyncComplexEndpoint1();
48
49 protected abstract String getDispatchAsyncComplexEndpoint2();
50
51 protected abstract String getTestExceptionEndpoint();
52
53 protected abstract String getWsdlEndpoint();
54
55 public void testRequestResponse() throws Throwable
56 {
57 MuleClient client = new MuleClient();
58
59 List results = new ArrayList();
60 int number = 1;
61 Map props = new HashMap();
62 for (int i = 0; i < number; i++)
63 {
64 props.put("X-Message-Number", String.valueOf(i));
65 UMOMessage msg = client.send(getRequestResponseEndpoint(), "Message " + i, props);
66 assertNotNull(msg);
67 results.add(msg.getPayload());
68 }
69
70 assertEquals(number, results.size());
71 for (int i = 0; i < number; i++)
72 {
73 assertEquals("Message " + i, results.get(i).toString());
74 }
75 }
76
77 public void testReceive() throws Throwable
78 {
79 MuleClient client = new MuleClient();
80 UMOMessage result = client.receive(getReceiveEndpoint(), 0);
81 assertNotNull(result);
82 assertNotNull(result.getPayload());
83 assertTrue(result.getPayload().toString().length() > 0);
84 }
85
86 public void testReceiveComplex() throws Throwable
87 {
88 MuleClient client = new MuleClient();
89 UMOMessage result = client.receive(getReceiveComplexEndpoint(), 0);
90 assertNotNull(result);
91 assertTrue(result.getPayload() instanceof Person);
92 assertEquals("Fred", ((Person)result.getPayload()).getFirstName());
93 assertEquals("Flintstone", ((Person)result.getPayload()).getLastName());
94
95 result = client.receive(getReceiveComplexEndpoint(), 0);
96 assertNotNull(result);
97 assertTrue(result.getPayload() instanceof Person);
98 assertEquals("Fred", ((Person)result.getPayload()).getFirstName());
99 assertEquals("Flintstone", ((Person)result.getPayload()).getLastName());
100 }
101
102 public void testSendAndReceiveComplex() throws Throwable
103 {
104 MuleClient client = new MuleClient();
105 UMOMessage result = client.send(getSendReceiveComplexEndpoint1(), new Person("Dino", "Flintstone"),
106 null);
107 assertNull(result);
108
109 result = client.receive(getSendReceiveComplexEndpoint2(), 0);
110 assertNotNull(result);
111 assertTrue(result.getPayload() instanceof Person);
112 assertEquals("Dino", ((Person)result.getPayload()).getFirstName());
113 assertEquals("Flintstone", ((Person)result.getPayload()).getLastName());
114 }
115
116 public void testReceiveComplexCollection() throws Throwable
117 {
118 MuleClient client = new MuleClient();
119 UMOMessage result = client.receive(getReceiveComplexCollectionEndpoint(), 0);
120 assertNotNull(result);
121 assertTrue(result.getPayload() instanceof Person[]);
122 assertEquals(3, ((Person[])result.getPayload()).length);
123 }
124
125 public void testDispatchAsyncComplex() throws Throwable
126 {
127 MuleClient client = new MuleClient();
128
129 client.dispatch(getDispatchAsyncComplexEndpoint1(), new Person("Betty", "Rubble"), null);
130 Thread.sleep(4500);
131
132
133 UMOMessage result = client.receive(getDispatchAsyncComplexEndpoint2(), 0);
134 assertNotNull(result);
135 assertTrue("Did not receive a Person but: " + result.getPayload().getClass(),
136 result.getPayload() instanceof Person);
137 assertEquals("Betty", ((Person)result.getPayload()).getFirstName());
138 assertEquals("Rubble", ((Person)result.getPayload()).getLastName());
139 }
140
141 public void testException() throws Exception
142 {
143 MuleClient client = new MuleClient();
144 try
145 {
146 client.send(getTestExceptionEndpoint(), new Person("Ross", "Mason"), null);
147 fail("A nested Fault should have been raised");
148 }
149 catch (UMOException e)
150 {
151
152 assertTrue(e instanceof DispatchException);
153
154 assertTrue(e.getCause() instanceof Exception);
155 }
156 }
157
158 public void testLocationUrlInWSDL() throws Exception
159 {
160 Map props = new HashMap();
161 props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
162 MuleClient client = new MuleClient();
163 UMOMessage result = client.send(getWsdlEndpoint(), null, props);
164 assertNotNull(result);
165 if (logger.isDebugEnabled())
166 {
167 logger.debug(result.getPayloadAsString());
168 }
169
170 String location = getWsdlEndpoint();
171 location = location.substring(0, location.length() - 5);
172 if (location.endsWith("/"))
173 {
174 location = location.substring(0, location.length() - 1);
175 }
176 if (result.getPayloadAsString().indexOf("location=\"" + location) == -1)
177 {
178 assertTrue(result.getPayloadAsString().indexOf("location='" + location) > -1);
179 }
180 else
181 {
182 assertTrue(result.getPayloadAsString().indexOf("location=\"" + location) > -1);
183 }
184
185 assertTrue(result.getStringProperty(HttpConstants.HEADER_CONTENT_TYPE, "").startsWith("text/xml"));
186
187 if (logger.isDebugEnabled())
188 {
189 logger.debug(result.getPayloadAsString());
190 }
191 }
192
193 }