1   /*
2    * $Id: ResponseTransformerMule2165TestCase.java 7963 2007-08-21 08:53:15Z dirk.olmes $
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.providers.vm.issues;
12  
13  import org.mule.tck.FunctionalTestCase;
14  import org.mule.extras.client.MuleClient;
15  import org.mule.umo.UMOException;
16  import org.mule.umo.UMOMessage;
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,
24      // and it seems vaguely reasonable.
25      public static final String LOCAL_RESPONSE = MESSAGE + " outbound outbound inbound response";
26      // an alternative is " outbound outbound response response" for the global
27      // transformers, which also makes some sense
28      public static final String GLOBAL_RESPONSE = MESSAGE + " outbound outbound response response";
29  
30      protected String getConfigResources()
31      {
32          return "response-transformer-mule-2165-test.xml";
33      }
34  
35      protected MuleClient send(String endpoint) throws UMOException
36      {
37          MuleClient client = new MuleClient();
38          client.dispatch(endpoint, MESSAGE, null);
39          return client;
40      }
41  
42      protected String receive(MuleClient client, String endpoint) throws Exception
43      {
44          UMOMessage message = client.receive(endpoint, TIMEOUT);
45          assertNotNull("no response from " + endpoint, message);
46          assertNotNull(message.getPayloadAsString());
47          return message.getPayloadAsString();
48      }
49  
50      protected void testTransformered(String endpoint, String response) throws Exception
51      {
52          String message = receive(send("in-" + endpoint), "out-" + endpoint);
53          assertEquals("bad response (" + message + ")  for " + endpoint, response, message);
54      }
55  
56      public void testGlobalNameGlobalTransformer() throws Exception
57      {
58          testTransformered("global-name-global-transformer", GLOBAL_RESPONSE);
59      }
60  
61      public void testGlobalNameUrlTransformer() throws Exception
62      {
63          testTransformered("global-name-url-transformer", GLOBAL_RESPONSE);
64      }
65  
66      public void testGlobalNameLocalTransformer() throws Exception
67      {
68          testTransformered("global-name-local-transformer", LOCAL_RESPONSE);
69      }
70  
71      public void testLocalNameLocalTransformer() throws Exception
72      {
73          testTransformered("local-name-local-transformer", LOCAL_RESPONSE);
74      }
75  
76      public void testLocalNameUrlTransformer() throws Exception
77      {
78          testTransformered("local-name-url-transformer", LOCAL_RESPONSE);
79      }
80  
81  }