View Javadoc

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