View Javadoc

1   /*
2    * $Id: HttpTransformersMule1822TestCase.java 20321 2010-11-24 15:21:24Z dfeist $
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.functional.StringAppendTestTransformer;
18  
19  public class HttpTransformersMule1822TestCase extends DynamicPortTestCase
20  {
21      public static final String OUTBOUND_MESSAGE = "Test message";
22  
23      @Override
24      protected String getConfigResources()
25      {
26          return "http-transformers-mule-1822-test.xml";
27      }
28  
29      private MuleMessage sendTo(String uri) throws MuleException
30      {
31          MuleClient client = new MuleClient(muleContext);
32          MuleMessage message = client.send(uri, OUTBOUND_MESSAGE, null);
33          assertNotNull(message);
34          return message;
35      }
36  
37      /**
38       * With no transformer we expect just the modification from the FTC
39       */
40      public void testBase() throws Exception
41      {
42          assertEquals(OUTBOUND_MESSAGE  + " Received",
43                  sendTo("base").getPayloadAsString());
44      }
45  
46      /**
47       * But response transformers on the base model should be applied
48       */
49      public void testResponse() throws Exception
50      {
51          assertEquals(
52                  StringAppendTestTransformer.append(" response",
53                          StringAppendTestTransformer.append(" response 2",
54                                          OUTBOUND_MESSAGE + " Received")),
55                  sendTo("response").getPayloadAsString());
56      }
57  
58      /**
59       * Should also work with inbound transformers
60       */
61      public void testBoth() throws Exception
62      {
63          assertEquals(
64              StringAppendTestTransformer.append(" response",
65                  StringAppendTestTransformer.append(" response 2",
66                      StringAppendTestTransformer.append(" transformed 2",
67                          StringAppendTestTransformer.appendDefault(OUTBOUND_MESSAGE)) + " Received")),
68                  sendTo("both").getPayloadAsString());
69      }
70  
71      @Override
72      protected int getNumPortsToFind()
73      {
74          return 3;
75      }
76  }