Search in sources :

Example 6 with Request

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

the class HttpRequestTest method testAddress.

@Test
public void testAddress() {
    Request mockRequest = mockHttpRequest("GET");
    when(mockRequest.address()).thenReturn("127.0.0.1");
    assertEquals("127.0.0.1", mockRequest.address());
}
Also used : HttpRequest(com.blade.mvc.http.HttpRequest) Request(com.blade.mvc.http.Request) Test(org.junit.Test)

Example 7 with Request

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

the class HttpRequestTest method testKeepAlive.

@Test
public void testKeepAlive() {
    Request mockRequest = mockHttpRequest("GET");
    when(mockRequest.keepAlive()).thenReturn(true);
    assertEquals(Boolean.TRUE, mockRequest.keepAlive());
}
Also used : HttpRequest(com.blade.mvc.http.HttpRequest) Request(com.blade.mvc.http.Request) Test(org.junit.Test)

Example 8 with Request

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

the class HttpRequestTest method testUri.

@Test
public void testUri() throws Exception {
    Request mockRequest = mockHttpRequest("GET");
    when(mockRequest.url()).thenReturn("/a");
    Request request = new HttpRequest(mockRequest);
    assertEquals("/a", request.uri());
    when(mockRequest.url()).thenReturn("/a/b?username=jack");
    request = new HttpRequest(mockRequest);
    assertEquals("/a/b", request.uri());
}
Also used : HttpRequest(com.blade.mvc.http.HttpRequest) HttpRequest(com.blade.mvc.http.HttpRequest) Request(com.blade.mvc.http.Request) Test(org.junit.Test)

Example 9 with Request

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

the class HttpRequestTest method testQueryParam.

@Test
public void testQueryParam() {
    Request mockRequest = mockHttpRequest("GET");
    Map<String, List<String>> parameters = new HashMap<>();
    parameters.put("name", Collections.singletonList("jack"));
    parameters.put("price", Collections.singletonList("22.1"));
    parameters.put("age", Collections.singletonList("25"));
    parameters.put("id", Collections.singletonList("220291"));
    when(mockRequest.parameters()).thenReturn(parameters);
    Request request = new HttpRequest(mockRequest);
    assertEquals("jack", request.query("name").get());
    assertEquals(Double.valueOf(22.1), request.queryDouble("price").get());
    assertEquals(Long.valueOf(220291), request.queryLong("id").get());
    assertEquals(Integer.valueOf(25), request.queryInt("age").get());
}
Also used : HttpRequest(com.blade.mvc.http.HttpRequest) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.blade.kit.CaseInsensitiveHashMap) HttpRequest(com.blade.mvc.http.HttpRequest) Request(com.blade.mvc.http.Request) List(java.util.List) Test(org.junit.Test)

Example 10 with Request

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

the class HttpRequestTest method testPathParam.

@Test
public void testPathParam() {
    Request mockRequest = mockHttpRequest("GET");
    Map<String, String> pathParams = new HashMap<>();
    pathParams.put("id", "6");
    pathParams.put("age", "24");
    pathParams.put("name", "jack");
    when(mockRequest.pathParams()).thenReturn(pathParams);
    Request request = new HttpRequest(mockRequest);
    assertEquals(Long.valueOf(6), request.pathLong("id"));
    assertEquals(Integer.valueOf(24), request.pathInt("age"));
    assertEquals("jack", request.pathString("name"));
}
Also used : HttpRequest(com.blade.mvc.http.HttpRequest) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.blade.kit.CaseInsensitiveHashMap) HttpRequest(com.blade.mvc.http.HttpRequest) Request(com.blade.mvc.http.Request) Test(org.junit.Test)

Aggregations

Request (com.blade.mvc.http.Request)29 HttpRequest (com.blade.mvc.http.HttpRequest)18 Test (org.junit.Test)18 HashMap (java.util.HashMap)7 CaseInsensitiveHashMap (com.blade.kit.CaseInsensitiveHashMap)5 WebContext (com.blade.mvc.WebContext)3 Response (com.blade.mvc.http.Response)3 RouteContext (com.blade.mvc.RouteContext)2 AuthOption (com.blade.security.web.auth.AuthOption)2 BasicAuthMiddleware (com.blade.security.web.auth.BasicAuthMiddleware)2 ForbiddenException (com.blade.exception.ForbiddenException)1 NotFoundException (com.blade.exception.NotFoundException)1 TemplateException (com.blade.exception.TemplateException)1 Session (com.blade.mvc.http.Session)1 FileItem (com.blade.mvc.multipart.FileItem)1 Contents (com.tale.model.entity.Contents)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 DefaultFileRegion (io.netty.channel.DefaultFileRegion)1 SslHandler (io.netty.handler.ssl.SslHandler)1