Search in sources :

Example 1 with SocketServer

use of com.github.dreamhead.moco.SocketServer in project moco by dreamhead.

the class SocketServerParser method createServer.

@Override
protected SocketServer createServer(final ImmutableList<SessionSetting> sessionSettings, final Optional<Integer> port, final MocoConfig... configs) {
    SocketServer server = ActualSocketServer.createLogServer(port);
    for (SessionSetting session : sessionSettings) {
        logger.debug("Parse session: {}", session);
        session.bindTo(server);
    }
    return server;
}
Also used : SocketServer(com.github.dreamhead.moco.SocketServer) ActualSocketServer(com.github.dreamhead.moco.internal.ActualSocketServer) SessionSetting(com.github.dreamhead.moco.parser.model.SessionSetting)

Example 2 with SocketServer

use of com.github.dreamhead.moco.SocketServer in project moco by dreamhead.

the class ActualSocketServerTest method should_merge_socket_servers_with_first_port.

@Test
public void should_merge_socket_servers_with_first_port() throws Exception {
    SocketServer server = socketServer(12306);
    SocketServer secondServer = socketServer();
    final SocketServer newServer = ((ActualSocketServer) server).mergeServer((ActualSocketServer) secondServer);
    running(newServer, new Runnable() {

        @Override
        public void run() throws Exception {
            assertThat(newServer.port(), is(12306));
        }
    });
}
Also used : SocketServer(com.github.dreamhead.moco.SocketServer) Runnable(com.github.dreamhead.moco.Runnable) Test(org.junit.Test)

Example 3 with SocketServer

use of com.github.dreamhead.moco.SocketServer in project moco by dreamhead.

the class ActualSocketServerTest method should_merge_socket_servers.

@Test
public void should_merge_socket_servers() throws Exception {
    SocketServer server = socketServer(12306);
    SocketServer secondServer = socketServer(12306);
    server.request(by("foo")).response(line("bar"));
    secondServer.request(by("foo1")).response(line("bar1"));
    SocketServer newServer = ((ActualSocketServer) server).mergeServer((ActualSocketServer) secondServer);
    running(newServer, new Runnable() {

        @Override
        public void run() throws Exception {
            helper.connect();
            assertThat(helper.send("foo"), is("bar"));
            assertThat(helper.send("foo1"), is("bar1"));
            helper.close();
        }
    });
}
Also used : SocketServer(com.github.dreamhead.moco.SocketServer) Runnable(com.github.dreamhead.moco.Runnable) Test(org.junit.Test)

Example 4 with SocketServer

use of com.github.dreamhead.moco.SocketServer in project moco by dreamhead.

the class ActualSocketServerTest method should_merge_socket_servers_without_ports_for_both_server.

@Test
public void should_merge_socket_servers_without_ports_for_both_server() throws Exception {
    SocketServer server = socketServer();
    SocketServer secondServer = socketServer();
    final ActualSocketServer newServer = ((ActualSocketServer) server).mergeServer((ActualSocketServer) secondServer);
    assertThat(newServer.getPort().isPresent(), is(false));
}
Also used : SocketServer(com.github.dreamhead.moco.SocketServer) Test(org.junit.Test)

Example 5 with SocketServer

use of com.github.dreamhead.moco.SocketServer in project moco by dreamhead.

the class ActualSocketServerTest method should_merge_socket_servers_with_second_port.

@Test
public void should_merge_socket_servers_with_second_port() throws Exception {
    SocketServer server = socketServer();
    SocketServer secondServer = socketServer(12307);
    final SocketServer newServer = ((ActualSocketServer) server).mergeServer((ActualSocketServer) secondServer);
    running(newServer, new Runnable() {

        @Override
        public void run() throws Exception {
            assertThat(newServer.port(), is(12307));
        }
    });
}
Also used : SocketServer(com.github.dreamhead.moco.SocketServer) Runnable(com.github.dreamhead.moco.Runnable) Test(org.junit.Test)

Aggregations

SocketServer (com.github.dreamhead.moco.SocketServer)6 Test (org.junit.Test)4 Runnable (com.github.dreamhead.moco.Runnable)3 ActualSocketServer (com.github.dreamhead.moco.internal.ActualSocketServer)2 SessionSetting (com.github.dreamhead.moco.parser.model.SessionSetting)1 RunnerSetting.aRunnerSetting (com.github.dreamhead.moco.runner.RunnerSetting.aRunnerSetting)1