View Javadoc

1   /*
2    * $Id: InboundTransformingCatchAllTestCase.java 22431 2011-07-18 07:40:35Z dirk.olmes $
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.test.usecases.routing;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleMessage;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.AbstractServiceAndFlowTestCase;
17  
18  import java.util.Arrays;
19  import java.util.Collection;
20  
21  import org.junit.Test;
22  import org.junit.runners.Parameterized.Parameters;
23  
24  import static org.junit.Assert.assertNotNull;
25  import static org.junit.Assert.assertTrue;
26  
27  /*
28   * In this Test Case we make use of a Custom Catch All Strategy in order to show how
29   * to send the transformed message instead of the non-transformed message.
30   */
31  public class InboundTransformingCatchAllTestCase extends AbstractServiceAndFlowTestCase
32  {
33      @Parameters
34      public static Collection<Object[]> parameters()
35      {
36          return Arrays.asList(new Object[][]{{ConfigVariant.SERVICE,
37              "org/mule/test/usecases/routing/inbound-transforming-catchall-service.xml"}
38  
39          });
40      }
41  
42      public InboundTransformingCatchAllTestCase(ConfigVariant variant, String configResources)
43      {
44          super(variant, configResources);
45      }
46  
47  
48      @Test
49      public void testNormal() throws Exception
50      {
51          MuleClient client = new MuleClient(muleContext);
52          client.dispatch("vm://in1", new DefaultMuleMessage("HELLO!", muleContext));
53          MuleMessage msg = client.request("vm://catchall", 3000);
54          assertNotNull(msg);
55          assertTrue(msg.getPayload() instanceof String);
56  
57          client.dispatch("vm://in2", new DefaultMuleMessage("HELLO!", muleContext));
58          msg = client.request("vm://catchall", 3000);
59          assertNotNull(msg);
60          assertTrue(msg.getPayload() instanceof byte[]);
61      }
62  }