@Test public void testSimple() throws Exception { IServer server = new Server(new ServerHandler()); server.start(); IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort()); con.write("A test\r\n"); String response = con.readStringByDelimiter("\r\n"); Assert.assertEquals("OK", response); con.write("other\r\n"); response = con.readStringByDelimiter("\r\n"); Assert.assertEquals("other failed", response); System.out.println("finished"); con.close(); server.close(); }
@Before public void init() throws Exception { networkingService.start(); verify(discoveryService).addLanDiscoveryListener(networkingService); when(acceptor.isOpen()).thenReturn(true); networkingService.addMessageListener(listener); when(nodeFactory.newNode(anyString())).thenReturn(lanNode); when(localInetAddress.getHostAddress()).thenReturn(localAddress); when(lanNode.getConnection()).thenReturn(connection); when(connection.getLocalAddress()).thenReturn(localInetAddress); when(connection.getRemoteAddress()).thenReturn(remoteInetAddress); }