1
2
3
4
5
6
7
8
9
10
11 package org.mule.issues;
12
13 import org.mule.api.MuleException;
14 import org.mule.api.MuleMessage;
15 import org.mule.module.client.MuleClient;
16 import org.mule.tck.FunctionalTestCase;
17
18 public class ResponseTransformerMule2165TestCase extends FunctionalTestCase
19 {
20
21 public static final long TIMEOUT = 2000L;
22 public static final String MESSAGE = "a message";
23
24
25
26
27
28
29
30
31
32
33
34
35 public static final String LOCAL_RESPONSE = MESSAGE + " outbound inbound outbound inbound response";
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public static final String GLOBAL_RESPONSE = LOCAL_RESPONSE + " response";
50
51 @Override
52 protected String getConfigResources()
53 {
54 return "issues/response-transformer-mule-2165-test.xml";
55 }
56
57 protected MuleClient send(String endpoint) throws MuleException
58 {
59 MuleClient client = new MuleClient(muleContext);
60 client.dispatch(endpoint, MESSAGE, null);
61 return client;
62 }
63
64 protected MuleClient dispatch(String endpoint) throws MuleException
65 {
66 MuleClient client = new MuleClient(muleContext);
67 client.dispatch(endpoint, MESSAGE, null);
68 return client;
69 }
70
71 protected String request(MuleClient client, String endpoint) throws Exception
72 {
73 MuleMessage message = client.request(endpoint, TIMEOUT);
74 assertNotNull("no response from " + endpoint, message);
75 assertNotNull(message.getPayloadAsString());
76 return message.getPayloadAsString();
77 }
78
79 protected void testTransformered(String endpoint, String response) throws Exception
80 {
81 String message = request(send("in-" + endpoint), "out-" + endpoint);
82 assertEquals("bad response (" + message + ") for " + endpoint, response, message);
83 }
84
85 protected void testTransformeredAsync(String endpoint, String response) throws Exception
86 {
87 String message = request(dispatch("in-" + endpoint), "out-" + endpoint);
88 assertEquals("bad response (" + message + ") for " + endpoint, response, message);
89 }
90
91 public void testGlobalNameGlobalTransformer() throws Exception
92 {
93 testTransformered("global-name-global-transformer", GLOBAL_RESPONSE);
94 }
95
96 public void testGlobalNameUrlTransformer() throws Exception
97 {
98 testTransformered("global-name-url-transformer", GLOBAL_RESPONSE);
99 }
100
101 public void testGlobalNameLocalTransformer() throws Exception
102 {
103 testTransformered("global-name-local-transformer", LOCAL_RESPONSE);
104 }
105
106 public void testLocalNameLocalTransformer() throws Exception
107 {
108 testTransformered("local-name-local-transformer", LOCAL_RESPONSE);
109 }
110
111 public void testLocalNameUrlTransformer() throws Exception
112 {
113 testTransformered("local-name-url-transformer", LOCAL_RESPONSE);
114 }
115
116
117 public void testGlobalNameGlobalTransformerAsync() throws Exception
118 {
119 testTransformeredAsync("global-name-global-transformer", GLOBAL_RESPONSE);
120 }
121
122 public void testGlobalNameUrlTransformerAsync() throws Exception
123 {
124 testTransformeredAsync("global-name-url-transformer", GLOBAL_RESPONSE);
125 }
126
127 public void testGlobalNameLocalTransformerAsync() throws Exception
128 {
129 testTransformeredAsync("global-name-local-transformer", LOCAL_RESPONSE);
130 }
131
132 public void testLocalNameLocalTransformerAsync() throws Exception
133 {
134 testTransformeredAsync("local-name-local-transformer", LOCAL_RESPONSE);
135 }
136
137 public void testLocalNameUrlTransformerAsync() throws Exception
138 {
139 testTransformeredAsync("local-name-url-transformer", LOCAL_RESPONSE);
140 }
141 }