Example usage for org.springframework.integration.ip.tcp.connection TcpNetConnection registerListener

List of usage examples for org.springframework.integration.ip.tcp.connection TcpNetConnection registerListener

Introduction

In this page you can find the example usage for org.springframework.integration.ip.tcp.connection TcpNetConnection registerListener.

Prototype

public void registerListener(@Nullable TcpListener listener) 

Source Link

Document

Set the listener that will receive incoming Messages.

Usage

From source file:org.springframework.integration.ip.tcp.connection.TcpNetConnectionTests.java

@Test
public void testErrorLog() throws Exception {
    Socket socket = mock(Socket.class);
    InputStream stream = mock(InputStream.class);
    when(socket.getInputStream()).thenReturn(stream);
    when(stream.read()).thenReturn((int) 'x');
    TcpNetConnection connection = new TcpNetConnection(socket, true, false, nullPublisher, null);
    connection.setDeserializer(new ByteArrayStxEtxSerializer());
    final AtomicReference<Object> log = new AtomicReference<Object>();
    Log logger = mock(Log.class);
    doAnswer(new Answer<Object>() {
        public Object answer(InvocationOnMock invocation) throws Throwable {
            log.set(invocation.getArguments()[0]);
            return null;
        }/*from ww w.j a  v  a 2  s  .c o m*/
    }).when(logger).error(Mockito.anyString());
    DirectFieldAccessor accessor = new DirectFieldAccessor(connection);
    accessor.setPropertyValue("logger", logger);
    connection.registerListener(mock(TcpListener.class));
    connection.setMapper(new TcpMessageMapper());
    connection.run();
    assertNotNull(log.get());
    assertEquals("Read exception " + connection.getConnectionId()
            + " MessageMappingException:Expected STX to begin message", log.get());
}