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