View Javadoc

1   /*
2    * $Id: EndpointTransformerMule2131TestCase.java 22491 2011-07-21 10:04:30Z claude.mamo $
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 static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  
16  import org.mule.api.MuleException;
17  import org.mule.api.MuleMessage;
18  import org.mule.module.client.MuleClient;
19  import org.mule.tck.AbstractServiceAndFlowTestCase;
20  import org.mule.tck.functional.StringAppendTestTransformer;
21  
22  import java.util.Arrays;
23  import java.util.Collection;
24  
25  import org.junit.Test;
26  import org.junit.runners.Parameterized.Parameters;
27  
28  public class EndpointTransformerMule2131TestCase extends AbstractServiceAndFlowTestCase
29  {
30  
31      public static final String MESSAGE = "a message";
32  
33      public EndpointTransformerMule2131TestCase(ConfigVariant variant, String configResources)
34      {
35          super(variant, configResources);
36          setDisposeContextPerClass(true);
37      }
38  
39      @Parameters
40      public static Collection<Object[]> parameters()
41      {
42          return Arrays.asList(new Object[][]{
43              {ConfigVariant.SERVICE, "issues/endpoint-transformer-mule-2131-test-service.xml"},
44              {ConfigVariant.FLOW, "issues/endpoint-transformer-mule-2131-test-flow.xml"}
45          });
46      }      
47  
48      protected MuleClient send() throws MuleException
49      {
50          MuleClient client = new MuleClient(muleContext);
51          client.dispatch("in", MESSAGE, null);
52          return client;
53      }
54  
55      @Test
56      public void testDirect() throws Exception
57      {
58          String response = request(send(), "direct");
59          assertEquals(MESSAGE, response);
60      }
61  
62      /* TODO This behaviour changed with BL-137, is this acceptable?
63      @Test
64      public void testGlobalNameGlobalTransformer() throws Exception
65      {
66          String response = request(send(), "global-name-global-transformer");
67          // Transformer is applied twice because it is on global endpoint and is
68          // therfore
69          // used for both the inbound and outbound endpoints because both use the
70          // global endpoint name and thus use the global endpoint as a template
71          assertEquals(MESSAGE + StringAppendTestTransformer.DEFAULT_TEXT
72                       + StringAppendTestTransformer.DEFAULT_TEXT, response);
73      }
74      */
75  
76      @Test
77      public void testGlobalNameLocalTransformer() throws Exception
78      {
79          doTestTransformed("global-name-local-transformer");
80      }
81  
82      @Test
83      public void testNoNameLocalTransformer() throws Exception
84      {
85          doTestTransformed("vm://no-name-local-transformer");
86      }
87  
88      @Test
89      public void testLocalNameLocalTransformer() throws Exception
90      {
91          doTestTransformed("vm://local-name-local-transformer");
92      }
93  
94      protected void doTestTransformed(String endpoint) throws Exception
95      {
96          String response = request(send(), endpoint);
97          assertEquals(MESSAGE + StringAppendTestTransformer.DEFAULT_TEXT, response);
98      }
99  
100     protected String request(MuleClient client, String endpoint) throws Exception
101     {
102         MuleMessage message = client.request(endpoint, RECEIVE_TIMEOUT);
103         assertNotNull(message);
104         assertNotNull(message.getPayloadAsString());
105         return message.getPayloadAsString();
106     }
107 
108 }