use of org.springframework.integration.ip.tcp.connection.TcpNioConnection.ChannelInputStream in project spring-integration by spring-projects.
the class TcpNetConnectionTests method testBinary.
@Test
public void testBinary() throws Exception {
SocketChannel socketChannel = mock(SocketChannel.class);
Socket socket = mock(Socket.class);
when(socketChannel.socket()).thenReturn(socket);
TcpNioConnection connection = new TcpNioConnection(socketChannel, true, false, e -> {
}, null);
ChannelInputStream inputStream = TestUtils.getPropertyValue(connection, "channelInputStream", ChannelInputStream.class);
inputStream.write(ByteBuffer.wrap(new byte[] { (byte) 0x80 }));
assertEquals(0x80, inputStream.read());
}
use of org.springframework.integration.ip.tcp.connection.TcpNioConnection.ChannelInputStream in project spring-integration by spring-projects.
the class TcpNioConnectionTests method testByteArrayReadWithBadArgs.
@Test
public void testByteArrayReadWithBadArgs() throws Exception {
SocketChannel socketChannel = mock(SocketChannel.class);
Socket socket = mock(Socket.class);
when(socketChannel.socket()).thenReturn(socket);
TcpNioConnection connection = new TcpNioConnection(socketChannel, false, false, null, null);
TcpNioConnection.ChannelInputStream stream = (ChannelInputStream) new DirectFieldAccessor(connection).getPropertyValue("channelInputStream");
stream.write(ByteBuffer.wrap("foo".getBytes()));
byte[] out = new byte[5];
try {
stream.read(out, 1, 5);
fail("Expected IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException e) {
}
try {
stream.read(null, 1, 5);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
assertEquals(0, stream.read(out, 0, 0));
assertEquals(3, stream.read(out));
}
use of org.springframework.integration.ip.tcp.connection.TcpNioConnection.ChannelInputStream in project spring-integration by spring-projects.
the class TcpNioConnectionTests method testByteArrayReadWithOffset.
@Test
public void testByteArrayReadWithOffset() throws Exception {
SocketChannel socketChannel = mock(SocketChannel.class);
Socket socket = mock(Socket.class);
when(socketChannel.socket()).thenReturn(socket);
TcpNioConnection connection = new TcpNioConnection(socketChannel, false, false, null, null);
TcpNioConnection.ChannelInputStream stream = (ChannelInputStream) new DirectFieldAccessor(connection).getPropertyValue("channelInputStream");
stream.write(ByteBuffer.wrap("foo".getBytes()));
byte[] out = new byte[5];
int n = stream.read(out, 1, 4);
assertEquals(3, n);
assertEquals("\u0000foo\u0000", new String(out));
}
use of org.springframework.integration.ip.tcp.connection.TcpNioConnection.ChannelInputStream in project spring-integration by spring-projects.
the class TcpNioConnectionTests method testByteArrayReadMulti.
@Test
public void testByteArrayReadMulti() throws Exception {
SocketChannel socketChannel = mock(SocketChannel.class);
Socket socket = mock(Socket.class);
when(socketChannel.socket()).thenReturn(socket);
TcpNioConnection connection = new TcpNioConnection(socketChannel, false, false, null, null);
TcpNioConnection.ChannelInputStream stream = (ChannelInputStream) new DirectFieldAccessor(connection).getPropertyValue("channelInputStream");
stream.write(ByteBuffer.wrap("foo".getBytes()));
stream.write(ByteBuffer.wrap("bar".getBytes()));
byte[] out = new byte[6];
int n = stream.read(out);
assertEquals(6, n);
assertEquals("foobar", new String(out));
}
use of org.springframework.integration.ip.tcp.connection.TcpNioConnection.ChannelInputStream in project spring-integration by spring-projects.
the class TcpNioConnectionTests method testByteArrayRead.
@Test
public void testByteArrayRead() throws Exception {
SocketChannel socketChannel = mock(SocketChannel.class);
Socket socket = mock(Socket.class);
when(socketChannel.socket()).thenReturn(socket);
TcpNioConnection connection = new TcpNioConnection(socketChannel, false, false, null, null);
TcpNioConnection.ChannelInputStream stream = (ChannelInputStream) new DirectFieldAccessor(connection).getPropertyValue("channelInputStream");
stream.write(ByteBuffer.wrap("foo".getBytes()));
byte[] out = new byte[2];
int n = stream.read(out);
assertEquals(2, n);
assertEquals("fo", new String(out));
out = new byte[2];
n = stream.read(out);
assertEquals(1, n);
assertEquals("o\u0000", new String(out));
}
Aggregations