Search in sources :

Example 1 with RestClientInvoke

use of org.mx.service.client.rest.RestClientInvoke in project main by JohnPeng739.

the class TestServer method testHttpServer.

@Test
public void testHttpServer() {
    AbstractServerFactory factory = context.getBean(HttpServerFactory.class);
    assertNotNull(factory);
    Server server = factory.getServer();
    assertNotNull(server);
    // test service client
    try {
        RestClientInvoke invoke = new RestClientInvoke();
        DataVO<String> str = invoke.get("http://localhost:9999/service/get", DataVO.class);
        assertNotNull(str);
        assertEquals("match the response data.", "get data.", str.getData());
        String data = "hello world";
        str = invoke.post("http://localhost:9999/service/post", data, DataVO.class);
        assertNotNull(str);
        assertEquals("match the response data.", String.format("post data: %s.", data), str.getData());
        data = "hello world";
        str = invoke.put("http://localhost:9999/service/put", data, DataVO.class);
        assertNotNull(str);
        assertEquals("match the response data.", String.format("put data: %s.", data), str.getData());
        invoke.close();
    } catch (RestInvokeException ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : Server(org.eclipse.jetty.server.Server) DataVO(org.mx.service.rest.vo.DataVO) RestInvokeException(org.mx.service.client.rest.RestInvokeException) RestClientInvoke(org.mx.service.client.rest.RestClientInvoke) Test(org.junit.Test)

Aggregations

Server (org.eclipse.jetty.server.Server)1 Test (org.junit.Test)1 RestClientInvoke (org.mx.service.client.rest.RestClientInvoke)1 RestInvokeException (org.mx.service.client.rest.RestInvokeException)1 DataVO (org.mx.service.rest.vo.DataVO)1