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