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());
}
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());
}
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());
}
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());
}
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"));
}
Aggregations