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.transport.http.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  import org.mule.tck.junit4.rule.DynamicPort;
15  
16  import org.junit.Rule;
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertNotNull;
21  
22  public class HttpTransformersMule1815TestCase extends FunctionalTestCase
23  {
24  
25      public static final String OUTBOUND_MESSAGE = "Test message";
26  
27      @Rule
28      public DynamicPort dynamicPort1 = new DynamicPort("port1");
29  
30      @Rule
31      public DynamicPort dynamicPort2 = new DynamicPort("port2");
32  
33      @Rule
34      public DynamicPort dynamicPort3 = new DynamicPort("port3");
35  
36      @Rule
37      public DynamicPort dynamicPort4 = new DynamicPort("port4");
38  
39      @Override
40      protected String getConfigResources()
41      {
42          return "http-transformers-mule-1815-test.xml";
43      }
44  
45      private MuleMessage sendTo(String uri) throws MuleException
46      {
47          MuleClient client = new MuleClient(muleContext);
48          MuleMessage message = client.send(uri, OUTBOUND_MESSAGE, null);
49          assertNotNull(message);
50          return message;
51      }
52  
53      /**
54       * With no transformer we expect just the modification from the FTC
55       *
56       * @throws Exception
57       */
58      @Test
59      public void testBase() throws Exception
60      {
61          assertEquals(OUTBOUND_MESSAGE + " Received", sendTo("base").getPayloadAsString());
62      }
63  
64      /**
65       * Adapted model, which should not apply transformers
66       *
67       * @throws Exception
68       */
69      @Test
70      public void testAdapted() throws Exception
71      {
72          assertEquals(OUTBOUND_MESSAGE + " Received", sendTo("adapted").getPayloadAsString());
73      }
74  
75      /**
76       * Change in behaviour: transformers are now always applied as part of inbound flow even if component doesn't invoke them.
77       * was: Transformers on the adapted model should be ignored
78       *
79       * @throws Exception
80       */
81      @Test
82      public void testIgnored() throws Exception
83      {
84          assertEquals(OUTBOUND_MESSAGE +" transformed" +" transformed 2" + " Received",
85                  sendTo("ignored").getPayloadAsString());
86      }
87  
88      /**
89       * But transformers on the base model should be applied
90       *
91       * @throws Exception
92       */
93      @Test
94      public void testInbound() throws Exception
95      {
96          assertEquals(
97              // this reads backwards - innermost is first in chain
98              StringAppendTestTransformer.append(" transformed 2",
99                  StringAppendTestTransformer.appendDefault(OUTBOUND_MESSAGE)) + " Received",
100                 sendTo("inbound").getPayloadAsString());
101     }
102 
103 }