Search in sources :

Example 6 with Response

use of com.blade.mvc.http.Response in project blade by biezhi.

the class HttpResponseTest method testCookie.

@Test
public void testCookie() {
    Response mockResponse = mockHttpResponse(200);
    when(mockResponse.cookies()).thenReturn(Collections.singletonMap("c1", "value1"));
    Response response = new HttpResponse(mockResponse);
    assertEquals(1, response.cookies().size());
    assertEquals("value1", response.cookies().get("c1"));
}
Also used : HttpResponse(com.blade.mvc.http.HttpResponse) Response(com.blade.mvc.http.Response) HttpResponse(com.blade.mvc.http.HttpResponse) Test(org.junit.Test)

Example 7 with Response

use of com.blade.mvc.http.Response in project blade by biezhi.

the class HttpResponseTest method testHeaders.

@Test
public void testHeaders() {
    Response mockResponse = mockHttpResponse(200);
    when(mockResponse.headers()).thenReturn(new HashMap<>());
    Response response = new HttpResponse(mockResponse);
    assertEquals(0, response.headers().size());
    response.header("a", "123");
    assertEquals(1, response.headers().size());
}
Also used : HttpResponse(com.blade.mvc.http.HttpResponse) Response(com.blade.mvc.http.Response) HttpResponse(com.blade.mvc.http.HttpResponse) Test(org.junit.Test)

Example 8 with Response

use of com.blade.mvc.http.Response in project blade by biezhi.

the class HttpResponseTest method testStatus.

@Test
public void testStatus() {
    Response mockResponse = mockHttpResponse(666);
    assertEquals(666, mockResponse.statusCode());
}
Also used : HttpResponse(com.blade.mvc.http.HttpResponse) Response(com.blade.mvc.http.Response) Test(org.junit.Test)

Example 9 with Response

use of com.blade.mvc.http.Response in project blade by biezhi.

the class HttpResponseTest method testBadRequest.

@Test
public void testBadRequest() {
    Response mockResponse = mockHttpResponse(200);
    Response response = new HttpResponse(mockResponse);
    response.badRequest();
    assertEquals(400, response.statusCode());
}
Also used : HttpResponse(com.blade.mvc.http.HttpResponse) Response(com.blade.mvc.http.Response) HttpResponse(com.blade.mvc.http.HttpResponse) Test(org.junit.Test)

Example 10 with Response

use of com.blade.mvc.http.Response in project blade by biezhi.

the class ExceptionHandlerTest method before.

@Before
public void before() {
    request = mock(Request.class);
    when(request.header("Accept")).thenReturn("text/html");
    response = mock(Response.class);
    WebContext.init(Blade.me(), "/");
    WebContext.set(new WebContext(request, response, null));
}
Also used : Response(com.blade.mvc.http.Response) WebContext(com.blade.mvc.WebContext) Request(com.blade.mvc.http.Request) Before(org.junit.Before)

Aggregations

Response (com.blade.mvc.http.Response)12 Test (org.junit.Test)10 HttpResponse (com.blade.mvc.http.HttpResponse)8 WebContext (com.blade.mvc.WebContext)3 Request (com.blade.mvc.http.Request)3 RouteContext (com.blade.mvc.RouteContext)2 HttpRequest (com.blade.mvc.http.HttpRequest)2 AuthOption (com.blade.security.web.auth.AuthOption)2 BasicAuthMiddleware (com.blade.security.web.auth.BasicAuthMiddleware)2 HashMap (java.util.HashMap)2 Before (org.junit.Before)1