1   /*
2    * $Id: ResponseTransformerMule2165TestCase.java 10789 2008-02-12 20:04:43Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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      // i don't know if this is the "correct" response - it's *one* of the responses in 1.4,
24      // and it seems vaguely reasonable.
25  
26      /* RM
27      Described as:
28      1. Client dispatch = "outbound"
29      2. First Service receiver = "inbound"
30      3. First Service dispatch (first endpoint) = "outbound"
31      4. Second Service receiver = "inbound"
32      5. Response transformer from SecondComponent = "response"
33      Note that because the response transformer is configured locally on the outbound endppoint it only gets called once
34      */
35      public static final String LOCAL_RESPONSE = MESSAGE + " outbound inbound outbound inbound response";
36      // an alternative in 1.4 is " outbound outbound response response" for the global
37      // transformers, which also makes some sense
38      /* RM
39      Described as:
40      1. Client dispatch = "outbound"
41      2. First Service receiver = "inbound"
42      3. First Service dispatch (first endpoint) = "outbound"
43      4. Second Service receiver = "inbound"
44      5. Response transformer from SecondComponent = "response"
45      6. Response from outbound endpoint (to the service) = "response"
46      Note that because the global outbound inpoint is also the inbound endpoint of the bounce service
47      The "response" ResponseTransformer gets called twice
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 }