View Javadoc

1   /*
2    * $Id: ResponseTransformerMule2165TestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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 = 2000L;
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      @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 }