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 org.mule.tck.junit4.AbstractMuleTestCase;
10  import org.mule.transport.tcp.TcpProtocol;
11  
12  import org.junit.Test;
13  
14  import static org.junit.Assert.assertEquals;
15  
16  public class DefaultProtocolTestCase extends AbstractMuleTestCase
17  {
18  
19      private TcpProtocol protocol;
20      private int expectedLength;
21  
22      public DefaultProtocolTestCase()
23      {
24          // for old (full buffer) condition in DefaultProtocol
25  //        this(new DefaultProtocol(), 1);
26  
27          this(new DirectProtocol(), SlowInputStream.FULL_LENGTH);
28      }
29  
30      protected DefaultProtocolTestCase(TcpProtocol protocol, int expectedLength)
31      {
32          this.protocol = protocol;
33          this.expectedLength = expectedLength;
34      }
35  
36      @Test
37      public void testRead() throws Exception
38      {
39          byte[] result = (byte[]) protocol.read(new SlowInputStream());
40          assertEquals(expectedLength, result.length);
41      }
42  
43      protected TcpProtocol getProtocol()
44      {
45          return protocol;
46      }
47  
48  }