View Javadoc

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