View Javadoc

1   /*
2    * $Id: LengthProtocolTestCase.java 20321 2010-11-24 15:21:24Z dfeist $
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 org.mule.transport.tcp.protocols.LengthProtocol;
14  
15  import java.io.ByteArrayInputStream;
16  
17  public class LengthProtocolTestCase extends DefaultProtocolTestCase
18  {
19  
20      public LengthProtocolTestCase()
21      {
22          super(new LengthProtocol(), 1);
23      }
24  
25      public void testFinalValue() throws Exception
26      {
27          byte[] result = (byte[]) getProtocol().read(new SlowInputStream());
28          assertEquals((byte) SlowInputStream.PAYLOAD, result[0]);
29      }
30  
31      // try also with a "generous" input stream (ie one that will return all data
32      // without delay) to make sure reset logic is ok
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  }