use of com.blade.mvc.http.HttpRequest 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.HttpRequest 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.HttpRequest 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"));
}
use of com.blade.mvc.http.HttpRequest in project blade by biezhi.
the class HttpRequestTest method testIsIE.
@Test
public void testIsIE() {
Request mockRequest = mockHttpRequest("GET");
Map<String, String> headers = Collections.singletonMap("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
when(mockRequest.headers()).thenReturn(headers);
Request request = new HttpRequest(mockRequest);
assertEquals(Boolean.TRUE, request.isIE());
when(mockRequest.headers()).thenReturn(Collections.EMPTY_MAP);
request = new HttpRequest(mockRequest);
assertEquals(Boolean.FALSE, request.isIE());
}
use of com.blade.mvc.http.HttpRequest in project blade by biezhi.
the class HttpRequestTest method testHost.
@Test
public void testHost() {
HttpRequest request = mockHttpRequest("GET");
when(request.host()).thenReturn("127.0.0.1");
Assert.assertEquals(request.host(), "127.0.0.1");
when(request.host()).thenReturn("localhost");
Assert.assertEquals(request.host(), "localhost");
}
Aggregations