View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.issues;
8   
9   import org.mule.api.MuleException;
10  import org.mule.api.MuleMessage;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.functional.StringAppendTestTransformer;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertEquals;
18  import static org.junit.Assert.assertNotNull;
19  
20  public class EndpointTransformerMule2131TestCase extends FunctionalTestCase
21  {
22  
23      public static final String MESSAGE = "a message";
24  
25      public EndpointTransformerMule2131TestCase()
26      {
27          setDisposeContextPerClass(true);
28      }
29  
30      @Override
31      protected String getConfigResources()
32      {
33          return "issues/endpoint-transformer-mule-2131-test.xml";
34      }
35  
36      protected MuleClient send() throws MuleException
37      {
38          MuleClient client = new MuleClient(muleContext);
39          client.dispatch("in", MESSAGE, null);
40          return client;
41      }
42  
43      @Test
44      public void testDirect() throws Exception
45      {
46          String response = request(send(), "direct");
47          assertEquals(MESSAGE, response);
48      }
49  
50      /* TODO This behaviour changed with BL-137, is this acceptable?
51      @Test
52      public void testGlobalNameGlobalTransformer() throws Exception
53      {
54          String response = request(send(), "global-name-global-transformer");
55          // Transformer is applied twice because it is on global endpoint and is
56          // therfore
57          // used for both the inbound and outbound endpoints because both use the
58          // global endpoint name and thus use the global endpoint as a template
59          assertEquals(MESSAGE + StringAppendTestTransformer.DEFAULT_TEXT
60                       + StringAppendTestTransformer.DEFAULT_TEXT, response);
61      }
62      */
63  
64      @Test
65      public void testGlobalNameLocalTransformer() throws Exception
66      {
67          doTestTransformed("global-name-local-transformer");
68      }
69  
70      @Test
71      public void testNoNameLocalTransformer() throws Exception
72      {
73          doTestTransformed("vm://no-name-local-transformer");
74      }
75  
76      @Test
77      public void testLocalNameLocalTransformer() throws Exception
78      {
79          doTestTransformed("vm://local-name-local-transformer");
80      }
81  
82      protected void doTestTransformed(String endpoint) throws Exception
83      {
84          String response = request(send(), endpoint);
85          assertEquals(MESSAGE + StringAppendTestTransformer.DEFAULT_TEXT, response);
86      }
87  
88      protected String request(MuleClient client, String endpoint) throws Exception
89      {
90          MuleMessage message = client.request(endpoint, RECEIVE_TIMEOUT);
91          assertNotNull(message);
92          assertNotNull(message.getPayloadAsString());
93          return message.getPayloadAsString();
94      }
95  
96  }