1   /*
2    * $Id: EndpointTransformerMule2131TestCase.java 11912 2008-06-03 13:25:13Z 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  import org.mule.tck.functional.StringAppendTestTransformer;
18  
19  public class EndpointTransformerMule2131TestCase extends FunctionalTestCase
20  {
21  
22      public static final String MESSAGE = "a message";
23  
24      protected String getConfigResources()
25      {
26          return "issues/endpoint-transformer-mule-2131-test.xml";
27      }
28  
29      protected MuleClient send() throws MuleException
30      {
31          MuleClient client = new MuleClient();
32          client.dispatch("in", MESSAGE, null);
33          return client;
34      }
35  
36      public void testDirect() throws Exception
37      {
38          String response = request(send(), "direct");
39          assertEquals(MESSAGE, response);
40      }
41  
42      public void testGlobalNameGlobalTransformer() throws Exception
43      {
44          String response = request(send(), "global-name-global-transformer");
45          // Transformer is applied twice because it is on global endpoint and is
46          // therfore
47          // used for both the inbound and outbound endpoints because both use the
48          // global endpoint name and thus use the global endpoint as a template
49          assertEquals(MESSAGE + StringAppendTestTransformer.DEFAULT_TEXT
50                       + StringAppendTestTransformer.DEFAULT_TEXT, response);
51      }
52  
53      public void testGlobalNameLocalTransformer() throws Exception
54      {
55          doTestTransformed("global-name-local-transformer");
56      }
57  
58      public void testNoNameLocalTransformer() throws Exception
59      {
60          doTestTransformed("vm://no-name-local-transformer?connector=queue");
61      }
62  
63      public void testLocalNameLocalTransformer() throws Exception
64      {
65          doTestTransformed("vm://local-name-local-transformer?connector=queue");
66      }
67  
68      protected void doTestTransformed(String endpoint) throws Exception
69      {
70          String response = request(send(), endpoint);
71          assertEquals(MESSAGE + StringAppendTestTransformer.DEFAULT_TEXT, response);
72      }
73  
74      protected String request(MuleClient client, String endpoint) throws Exception
75      {
76          MuleMessage message = client.request(endpoint, RECEIVE_TIMEOUT);
77          assertNotNull(message);
78          assertNotNull(message.getPayloadAsString());
79          return message.getPayloadAsString();
80      }
81  
82  }