Search in sources :

Example 1 with Response

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

the class BaseTestCase method mockHttpResponse.

protected Response mockHttpResponse(int code) {
    Response response = mock(Response.class);
    when(response.statusCode()).thenReturn(code);
    return response;
}
Also used : Response(com.blade.mvc.http.Response)

Example 2 with Response

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

the class HttpResponseTest method testUnauthorized.

@Test
public void testUnauthorized() {
    Response mockResponse = mockHttpResponse(200);
    Response response = new HttpResponse(mockResponse);
    response.unauthorized();
    assertEquals(401, 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 3 with Response

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

the class HttpResponseTest method testHeader.

@Test
public void testHeader() {
    Response mockResponse = mockHttpResponse(200);
    when(mockResponse.headers()).thenReturn(Collections.singletonMap("Server", "Nginx"));
    Response response = new HttpResponse(mockResponse);
    assertEquals(1, response.headers().size());
    assertEquals("Nginx", response.headers().get("Server"));
}
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 4 with Response

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

the class HttpResponseTest method testNotFound.

@Test
public void testNotFound() {
    Response mockResponse = mockHttpResponse(200);
    Response response = new HttpResponse(mockResponse);
    response.notFound();
    assertEquals(404, 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 5 with Response

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

the class HttpResponseTest method testContentType.

@Test
public void testContentType() {
    Response mockResponse = mockHttpResponse(200);
    Response response = new HttpResponse(mockResponse);
    response.contentType(Const.CONTENT_TYPE_HTML);
    assertEquals(Const.CONTENT_TYPE_HTML, response.contentType());
    response.contentType("hello.world");
    assertEquals("hello.world", response.contentType());
}
Also used : HttpResponse(com.blade.mvc.http.HttpResponse) Response(com.blade.mvc.http.Response) HttpResponse(com.blade.mvc.http.HttpResponse) Test(org.junit.Test)

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