use of com.blade.mvc.http.Request in project blade by biezhi.
the class HttpRequestTest method testUserAgent.
@Test
public void testUserAgent() {
Map<String, String> headers = Collections.singletonMap("User-Agent", firefoxUA);
Request mockRequest = mockHttpRequest("GET");
when(mockRequest.headers()).thenReturn(headers);
Request request = new HttpRequest(mockRequest);
assertEquals(firefoxUA, request.userAgent());
}
use of com.blade.mvc.http.Request in project blade by biezhi.
the class HttpRequestTest method testIsAjax.
@Test
public void testIsAjax() {
Request mockRequest = mockHttpRequest("GET");
Map<String, String> headers = Collections.singletonMap("x-requested-with", "XMLHttpRequest");
when(mockRequest.headers()).thenReturn(headers);
Request request = new HttpRequest(mockRequest);
assertEquals(Boolean.TRUE, request.isAjax());
when(mockRequest.headers()).thenReturn(Collections.EMPTY_MAP);
request = new HttpRequest(mockRequest);
assertEquals(Boolean.FALSE, request.isAjax());
}
use of com.blade.mvc.http.Request in project blade by biezhi.
the class HttpRequestTest method testHeaders.
@Test
public void testHeaders() {
Request mockRequest = mockHttpRequest("GET");
Map<String, String> headers = new CaseInsensitiveHashMap<>();
headers.put("h1", "a1");
headers.put("H2", "a2");
when(mockRequest.headers()).thenReturn(headers);
Request request = new HttpRequest(mockRequest);
assertEquals("a1", request.header("h1"));
assertEquals("a1", request.header("H1"));
assertEquals("a2", request.header("h2"));
assertEquals("a2", request.header("H2"));
request.headers().forEach((key, val) -> System.out.println(key + "\t=\t" + val));
}
use of com.blade.mvc.http.Request in project blade by biezhi.
the class HttpRequestTest method testQueryString.
@Test
public void testQueryString() {
Request mockRequest = mockHttpRequest("GET");
when(mockRequest.url()).thenReturn("/hello?name=q1");
Request request = new HttpRequest(mockRequest);
assertEquals("name=q1", request.queryString());
}
Aggregations