View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.tcp.integration;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleMessage;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  import org.mule.tck.junit4.rule.DynamicPort;
14  
15  import org.junit.Rule;
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertTrue;
20  
21  /**
22   * This test was set for the new changes due to Mule1199
23   */
24  public class CustomSerializationProtocolTestCase extends FunctionalTestCase
25  {
26      final private int messages = 1;
27  
28      @Rule
29      public DynamicPort dynamicPort = new DynamicPort("port1");
30  
31      @Override
32      protected String getConfigResources()
33      {
34          return "custom-serialisation-mule-config.xml";
35      }
36  
37      @Test
38      public void testCustomObject() throws Exception
39      {
40          MuleClient client = new MuleClient(muleContext);
41          NonSerializableMessageObject message = new NonSerializableMessageObject(1, "Hello", true);
42  
43          for (int i = 0; i < messages; i++)
44          {
45              client.dispatch("vm://in", new DefaultMuleMessage(message, muleContext));
46          }
47  
48          for (int i = 0; i < messages; i++)
49          {
50              MuleMessage msg = client.request("vm://out", 30000);
51              assertTrue(msg.getPayload() instanceof NonSerializableMessageObject);
52              NonSerializableMessageObject received = (NonSerializableMessageObject)msg.getPayload();
53              assertEquals("Hello", received.s);
54              assertEquals(1, received.i);
55              assertEquals(true, received.b);
56          }
57      }
58  }