View Javadoc

1   /*
2    * $Id: HttpTransformersMule1822TestCase.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 HttpTransformersMule1822TestCase extends DynamicPortTestCase
21  {
22      public static final String OUTBOUND_MESSAGE = "Test message";
23  
24      @Override
25      protected String getConfigResources()
26      {
27          return "http-transformers-mule-1822-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      public void testBase() throws Exception
42      {
43          assertEquals(OUTBOUND_MESSAGE  + " Received",
44                  sendTo("base").getPayloadAsString());
45      }
46  
47      /**
48       * But response transformers on the base model should be applied
49       */
50      public void testResponse() throws Exception
51      {
52          assertEquals(
53                  StringAppendTestTransformer.append(" response",
54                          StringAppendTestTransformer.append(" response 2",
55                                          OUTBOUND_MESSAGE + " Received")),
56                  sendTo("response").getPayloadAsString());
57      }
58  
59      /**
60       * Should also work with inbound transformers
61       */
62      public void testBoth() throws Exception
63      {
64          assertEquals(
65              StringAppendTestTransformer.append(" response",
66                  StringAppendTestTransformer.append(" response 2",
67                      StringAppendTestTransformer.append(" transformed 2",
68                          StringAppendTestTransformer.appendDefault(OUTBOUND_MESSAGE)) + " Received")),
69                  sendTo("both").getPayloadAsString());
70      }
71  
72      @Override
73      protected int getNumPortsToFind()
74      {
75          return 3;
76      }
77  }