use of org.evosuite.runtime.vnet.RemoteTcpServer in project evosuite by EvoSuite.
the class SocketTest method testSingleConnection.
@Test
public void testSingleConnection() throws IOException {
String remoteHost = "127.42.0.42";
int remotePort = 666;
InetSocketAddress saddr = new MockInetSocketAddress(MockInetAddress.getByName(remoteHost), remotePort);
MockSocket s = new MockSocket();
RemoteTcpServer server = new RemoteTcpServer(new EndPointInfo(saddr.getAddress().getHostAddress(), saddr.getPort(), ConnectionType.TCP));
VirtualNetwork.getInstance().addRemoteTcpServer(server);
String msgFromServer = "server";
server.sendMessage(msgFromServer);
s.connect(saddr);
String msgFromSUT = "SUT";
s.getOutputStream().write(msgFromSUT.getBytes());
String sutReceived = new Scanner(s.getInputStream()).nextLine();
Assert.assertEquals(msgFromServer, sutReceived);
Assert.assertEquals(msgFromSUT, server.getAllReceivedDataAsString());
s.close();
}
use of org.evosuite.runtime.vnet.RemoteTcpServer in project evosuite by EvoSuite.
the class NetworkHandling method openRemoteTcpServer.
/**
* Create a one-time listener on remote address/port
* @param remoteServer
* @return
*/
public static boolean openRemoteTcpServer(EvoSuiteRemoteAddress remoteServer) {
if (remoteServer == null) {
return false;
}
RemoteTcpServer server = new RemoteTcpServer(new EndPointInfo(remoteServer.getHost(), remoteServer.getPort(), VirtualNetwork.ConnectionType.TCP));
VirtualNetwork.getInstance().addRemoteTcpServer(server);
return true;
}
Aggregations