View Javadoc

1   /*
2    * $Id: HttpTransformersMule1815TestCase.java 22518 2011-07-22 07:00:22Z 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.transport.http.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  import org.mule.tck.junit4.rule.DynamicPort;
22  
23  import java.util.Arrays;
24  import java.util.Collection;
25  
26  import org.junit.Rule;
27  import org.junit.Test;
28  import org.junit.runners.Parameterized.Parameters;
29  
30  public class HttpTransformersMule1815TestCase extends AbstractServiceAndFlowTestCase
31  {
32  
33      public static final String OUTBOUND_MESSAGE = "Test message";
34  
35      @Rule
36      public DynamicPort dynamicPort1 = new DynamicPort("port1");
37  
38      @Rule
39      public DynamicPort dynamicPort2 = new DynamicPort("port2");
40  
41      @Rule
42      public DynamicPort dynamicPort3 = new DynamicPort("port3");
43  
44      @Rule
45      public DynamicPort dynamicPort4 = new DynamicPort("port4");
46     
47      public HttpTransformersMule1815TestCase(ConfigVariant variant, String configResources)
48      {
49          super(variant, configResources);
50      }
51  
52      @Parameters
53      public static Collection<Object[]> parameters()
54      {
55          return Arrays.asList(new Object[][]{
56              {ConfigVariant.SERVICE, "http-transformers-mule-1815-test-service.xml"},
57              {ConfigVariant.FLOW, "http-transformers-mule-1815-test-flow.xml"}
58          });
59      }      
60      
61      private MuleMessage sendTo(String uri) throws MuleException
62      {
63          MuleClient client = new MuleClient(muleContext);
64          MuleMessage message = client.send(uri, OUTBOUND_MESSAGE, null);
65          assertNotNull(message);
66          return message;
67      }
68  
69      /**
70       * With no transformer we expect just the modification from the FTC
71       *
72       * @throws Exception
73       */
74      @Test
75      public void testBase() throws Exception
76      {
77          assertEquals(OUTBOUND_MESSAGE + " Received", sendTo("base").getPayloadAsString());
78      }
79  
80      /**
81       * Adapted model, which should not apply transformers
82       *
83       * @throws Exception
84       */
85      @Test
86      public void testAdapted() throws Exception
87      {
88          assertEquals(OUTBOUND_MESSAGE + " Received", sendTo("adapted").getPayloadAsString());
89      }
90  
91      /**
92       * Change in behaviour: transformers are now always applied as part of inbound flow even if component doesn't invoke them.
93       * was: Transformers on the adapted model should be ignored
94       *
95       * @throws Exception
96       */
97      @Test
98      public void testIgnored() throws Exception
99      {
100         assertEquals(OUTBOUND_MESSAGE +" transformed" +" transformed 2" + " Received",
101                 sendTo("ignored").getPayloadAsString());
102     }
103 
104     /**
105      * But transformers on the base model should be applied
106      *
107      * @throws Exception
108      */
109     @Test
110     public void testInbound() throws Exception
111     {
112         assertEquals(
113             // this reads backwards - innermost is first in chain
114             StringAppendTestTransformer.append(" transformed 2",
115                 StringAppendTestTransformer.appendDefault(OUTBOUND_MESSAGE)) + " Received",
116                 sendTo("inbound").getPayloadAsString());
117     }
118 
119 }