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.protocols;
8   
9   import java.io.ByteArrayInputStream;
10  
11  import org.junit.Test;
12  
13  import static org.junit.Assert.assertEquals;
14  
15  public class LengthProtocolTestCase extends DefaultProtocolTestCase
16  {
17  
18      public LengthProtocolTestCase()
19      {
20          super(new LengthProtocol(), 1);
21      }
22  
23      @Test
24      public void testFinalValue() throws Exception
25      {
26          byte[] result = (byte[]) getProtocol().read(new SlowInputStream());
27          assertEquals((byte) SlowInputStream.PAYLOAD, result[0]);
28      }
29  
30      // try also with a "generous" input stream (ie one that will return all data
31      // without delay) to make sure reset logic is ok
32      @Test
33      public void testGenerous() throws Exception
34      {
35          byte[] bytes = new byte[SlowInputStream.FULL_LENGTH];
36          for (int i = 0; i < SlowInputStream.FULL_LENGTH; ++i)
37          {
38              bytes[i] = (byte) SlowInputStream.CONTENTS[i];
39          }
40          ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
41          byte[] result = (byte[]) getProtocol().read(bis);
42          assertEquals((byte) SlowInputStream.PAYLOAD, result[0]);
43      }
44  
45  }