Search in sources :

Example 1 with HttpResponse

use of com.blade.mvc.http.HttpResponse 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 2 with HttpResponse

use of com.blade.mvc.http.HttpResponse 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 3 with HttpResponse

use of com.blade.mvc.http.HttpResponse 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 4 with HttpResponse

use of com.blade.mvc.http.HttpResponse 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)

Example 5 with HttpResponse

use of com.blade.mvc.http.HttpResponse 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)

Aggregations

HttpResponse (com.blade.mvc.http.HttpResponse)7 Response (com.blade.mvc.http.Response)7 Test (org.junit.Test)7