View Javadoc

1   /*
2    * $Id: HttpTransformersMule1822TestCase.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 HttpTransformersMule1822TestCase extends AbstractServiceAndFlowTestCase
31  {
32      public static final String OUTBOUND_MESSAGE = "Test message";
33  
34      @Rule
35      public DynamicPort dynamicPort1 = new DynamicPort("port1");
36  
37      @Rule
38      public DynamicPort dynamicPort2 = new DynamicPort("port2");
39  
40      @Rule
41      public DynamicPort dynamicPort3 = new DynamicPort("port3");
42  
43      public HttpTransformersMule1822TestCase(ConfigVariant variant, String configResources)
44      {
45          super(variant, configResources);
46      }
47  
48      @Parameters
49      public static Collection<Object[]> parameters()
50      {
51          return Arrays.asList(new Object[][]{
52              {ConfigVariant.SERVICE, "http-transformers-mule-1822-test-service.xml"},
53              {ConfigVariant.FLOW, "http-transformers-mule-1822-test-flow.xml"}
54          });
55      }      
56  
57      private MuleMessage sendTo(String uri) throws MuleException
58      {
59          MuleClient client = new MuleClient(muleContext);
60          MuleMessage message = client.send(uri, OUTBOUND_MESSAGE, null);
61          assertNotNull(message);
62          return message;
63      }
64  
65      /**
66       * With no transformer we expect just the modification from the FTC
67       */
68      @Test
69      public void testBase() throws Exception
70      {
71          assertEquals(OUTBOUND_MESSAGE  + " Received", sendTo("base").getPayloadAsString());
72      }
73  
74      /**
75       * But response transformers on the base model should be applied
76       */
77      @Test
78      public void testResponse() throws Exception
79      {
80          assertEquals(
81                  StringAppendTestTransformer.append(" response",
82                          StringAppendTestTransformer.append(" response 2",
83                                          OUTBOUND_MESSAGE + " Received")),
84                  sendTo("response").getPayloadAsString());
85      }
86  
87      /**
88       * Should also work with inbound transformers
89       */
90      @Test
91      public void testBoth() throws Exception
92      {
93          assertEquals(
94              StringAppendTestTransformer.append(" response",
95                  StringAppendTestTransformer.append(" response 2",
96                      StringAppendTestTransformer.append(" transformed 2",
97                          StringAppendTestTransformer.appendDefault(OUTBOUND_MESSAGE)) + " Received")),
98                  sendTo("both").getPayloadAsString());
99      }
100 
101 }