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 HttpTransformersMule1822TestCase extends FunctionalTestCase
23  {
24      public static final String OUTBOUND_MESSAGE = "Test message";
25  
26      @Rule
27      public DynamicPort dynamicPort1 = new DynamicPort("port1");
28  
29      @Rule
30      public DynamicPort dynamicPort2 = new DynamicPort("port2");
31  
32      @Rule
33      public DynamicPort dynamicPort3 = new DynamicPort("port3");
34  
35      @Override
36      protected String getConfigResources()
37      {
38          return "http-transformers-mule-1822-test.xml";
39      }
40  
41      private MuleMessage sendTo(String uri) throws MuleException
42      {
43          MuleClient client = new MuleClient(muleContext);
44          MuleMessage message = client.send(uri, OUTBOUND_MESSAGE, null);
45          assertNotNull(message);
46          return message;
47      }
48  
49      /**
50       * With no transformer we expect just the modification from the FTC
51       */
52      @Test
53      public void testBase() throws Exception
54      {
55          assertEquals(OUTBOUND_MESSAGE  + " Received", sendTo("base").getPayloadAsString());
56      }
57  
58      /**
59       * But response transformers on the base model should be applied
60       */
61      @Test
62      public void testResponse() throws Exception
63      {
64          assertEquals(
65                  StringAppendTestTransformer.append(" response",
66                          StringAppendTestTransformer.append(" response 2",
67                                          OUTBOUND_MESSAGE + " Received")),
68                  sendTo("response").getPayloadAsString());
69      }
70  
71      /**
72       * Should also work with inbound transformers
73       */
74      @Test
75      public void testBoth() throws Exception
76      {
77          assertEquals(
78              StringAppendTestTransformer.append(" response",
79                  StringAppendTestTransformer.append(" response 2",
80                      StringAppendTestTransformer.append(" transformed 2",
81                          StringAppendTestTransformer.appendDefault(OUTBOUND_MESSAGE)) + " Received")),
82                  sendTo("both").getPayloadAsString());
83      }
84  
85  }