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

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

Introduction

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

Prototype

@Override
public void run() 

Source Link

Document

If there is no listener, this method exits.

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 w  w  w .j a va 2s . 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());
}