Search in sources :

Example 1 with RemoteTcpServer

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();
}
Also used : Scanner(java.util.Scanner) RemoteTcpServer(org.evosuite.runtime.vnet.RemoteTcpServer) EndPointInfo(org.evosuite.runtime.vnet.EndPointInfo) Test(org.junit.Test)

Example 2 with RemoteTcpServer

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;
}
Also used : RemoteTcpServer(org.evosuite.runtime.vnet.RemoteTcpServer) EndPointInfo(org.evosuite.runtime.vnet.EndPointInfo)

Aggregations

EndPointInfo (org.evosuite.runtime.vnet.EndPointInfo)2 RemoteTcpServer (org.evosuite.runtime.vnet.RemoteTcpServer)2 Scanner (java.util.Scanner)1 Test (org.junit.Test)1