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 = 1000L;
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 protected String getConfigResources()
52 {
53 return "issues/response-transformer-mule-2165-test.xml";
54 }
55
56 protected MuleClient send(String endpoint) throws MuleException
57 {
58 MuleClient client = new MuleClient();
59 client.send(endpoint, MESSAGE, null);
60 return client;
61 }
62
63 protected MuleClient dispatch(String endpoint) throws MuleException
64 {
65 MuleClient client = new MuleClient();
66 client.dispatch(endpoint, MESSAGE, null);
67 return client;
68 }
69
70 protected String request(MuleClient client, String endpoint) throws Exception
71 {
72 MuleMessage message = client.request(endpoint, TIMEOUT);
73 assertNotNull("no response from " + endpoint, message);
74 assertNotNull(message.getPayloadAsString());
75 return message.getPayloadAsString();
76 }
77
78 protected void testTransformered(String endpoint, String response) throws Exception
79 {
80 String message = request(send("in-" + endpoint), "out-" + endpoint);
81 assertEquals("bad response (" + message + ") for " + endpoint, response, message);
82 }
83
84 protected void testTransformeredAsync(String endpoint, String response) throws Exception
85 {
86 String message = request(dispatch("in-" + endpoint), "out-" + endpoint);
87 assertEquals("bad response (" + message + ") for " + endpoint, response, message);
88 }
89
90 public void testGlobalNameGlobalTransformer() throws Exception
91 {
92 testTransformered("global-name-global-transformer", GLOBAL_RESPONSE);
93 }
94
95 public void testGlobalNameUrlTransformer() throws Exception
96 {
97 testTransformered("global-name-url-transformer", GLOBAL_RESPONSE);
98 }
99
100 public void testGlobalNameLocalTransformer() throws Exception
101 {
102 testTransformered("global-name-local-transformer", LOCAL_RESPONSE);
103 }
104
105 public void testLocalNameLocalTransformer() throws Exception
106 {
107 testTransformered("local-name-local-transformer", LOCAL_RESPONSE);
108 }
109
110 public void testLocalNameUrlTransformer() throws Exception
111 {
112 testTransformered("local-name-url-transformer", LOCAL_RESPONSE);
113 }
114
115
116 public void testGlobalNameGlobalTransformerAsync() throws Exception
117 {
118 testTransformeredAsync("global-name-global-transformer", GLOBAL_RESPONSE);
119 }
120
121 public void testGlobalNameUrlTransformerAsync() throws Exception
122 {
123 testTransformeredAsync("global-name-url-transformer", GLOBAL_RESPONSE);
124 }
125
126 public void testGlobalNameLocalTransformerAsync() throws Exception
127 {
128 testTransformeredAsync("global-name-local-transformer", LOCAL_RESPONSE);
129 }
130
131 public void testLocalNameLocalTransformerAsync() throws Exception
132 {
133 testTransformeredAsync("local-name-local-transformer", LOCAL_RESPONSE);
134 }
135
136 public void testLocalNameUrlTransformerAsync() throws Exception
137 {
138 testTransformeredAsync("local-name-url-transformer", LOCAL_RESPONSE);
139 }
140 }