Search in sources :

Example 1 with WsView

use of io.leopard.web.view.WsView in project leopard by tanhaichao.

the class WsViewTest method getData.

@Test
public void getData() {
    WsView webserviceView = new WsView("success");
    Assert.assertEquals("success", webserviceView.getData());
    Assert.assertEquals(200, webserviceView.getStatus());
    Assert.assertEquals("", webserviceView.getMessage());
}
Also used : WsView(io.leopard.web.view.WsView) Test(org.junit.Test)

Example 2 with WsView

use of io.leopard.web.view.WsView in project leopard by tanhaichao.

the class WsViewTest method getBody.

@Test
public void getBody() {
    HttpServletRequest request = new MockHttpServletRequest();
    HttpServletResponse response = new MockHttpServletResponse();
    WsView webserviceView = new WsView("data");
    String body = webserviceView.getBody(request, response);
    // System.out.println("body:" + body);
    Assert.assertEquals("{\"status\":200,\"message\":\"\",\"clazz\":\"java.lang.String\",\"data\":\"\\\"data\\\"\"}", body);
    Assert.assertEquals("text/plain; charset=UTF-8", webserviceView.getContentType());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) WsView(io.leopard.web.view.WsView) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 3 with WsView

use of io.leopard.web.view.WsView in project leopard by tanhaichao.

the class WsViewTrynbResolver method resolveView.

@Override
public ModelAndView resolveView(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler, Exception exception, TrynbInfo trynbInfo) {
    Class<?> returnType = handler.getMethod().getReturnType();
    if (!returnType.equals(WsView.class)) {
        return null;
    }
    WsView webserviceView = new WsView(null);
    if (exception instanceof StatusCodeException) {
        StatusCodeException e = (StatusCodeException) exception;
        webserviceView.setStatus(e.getStatus());
        webserviceView.setMessage(e.getMessage());
    } else {
        webserviceView.setStatus(trynbInfo.getStatusCode());
        webserviceView.setMessage(trynbInfo.getMessage());
    }
    return webserviceView;
}
Also used : WsView(io.leopard.web.view.WsView) StatusCodeException(io.leopard.web.view.StatusCodeException)

Aggregations

WsView (io.leopard.web.view.WsView)3 Test (org.junit.Test)2 StatusCodeException (io.leopard.web.view.StatusCodeException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1