View Javadoc

1   /*
2    * $Id: CustomByteProtocolTestCase.java 22471 2011-07-20 10:36:17Z 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.tcp.integration;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertTrue;
15  
16  import org.mule.DefaultMuleMessage;
17  import org.mule.api.MuleMessage;
18  import org.mule.module.client.MuleClient;
19  import org.mule.tck.AbstractServiceAndFlowTestCase;
20  import org.mule.tck.junit4.rule.DynamicPort;
21  
22  import java.util.Arrays;
23  import java.util.Collection;
24  
25  import org.junit.Rule;
26  import org.junit.Test;
27  import org.junit.runners.Parameterized.Parameters;
28  
29  /**
30   * This test was set for the new changes due to Mule1199
31   */
32  public class CustomByteProtocolTestCase extends AbstractServiceAndFlowTestCase
33  {
34      final private int messages = 100;
35  
36      @Rule
37      public DynamicPort dynamicPort = new DynamicPort("port1");
38  
39      public CustomByteProtocolTestCase(ConfigVariant variant, String configResources)
40      {
41          super(variant, configResources);
42      }
43  
44      @Parameters
45      public static Collection<Object[]> parameters()
46      {
47          return Arrays.asList(new Object[][]{
48              {ConfigVariant.SERVICE, "custom-serialisation-mule-config-service.xml"},
49              {ConfigVariant.FLOW, "custom-serialisation-mule-config-flow.xml"}
50          });
51      }            
52  
53      @Test
54      public void testCustomObject() throws Exception
55      {
56          MuleClient client = new MuleClient(muleContext);
57          NonSerializableMessageObject message = new NonSerializableMessageObject(1, "Hello", true);
58  
59          for (int i = 0; i < messages; i++)
60          {
61              client.dispatch("vm://in", new DefaultMuleMessage(message, muleContext));
62          }
63  
64          for (int i = 0; i < messages; i++)
65          {
66              MuleMessage msg = client.request("vm://out", 30000);
67              assertTrue(msg.getPayload() instanceof NonSerializableMessageObject);
68              NonSerializableMessageObject received = (NonSerializableMessageObject)msg.getPayload();
69              assertEquals("Hello", received.s);
70              assertEquals(1, received.i);
71              assertEquals(true, received.b);
72          }
73      }
74  
75  }