use of com.blade.mvc.http.HttpRequest 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.HttpRequest 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.HttpRequest 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.HttpRequest 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());
}
use of com.blade.mvc.http.HttpRequest in project blade by biezhi.
the class HttpRequestTest method testCookie.
@Test
public void testCookie() {
Map<String, Cookie> cookieMap = new HashMap<>();
Cookie c1 = new Cookie();
c1.name("c1");
c1.value("hello1");
cookieMap.put("c1", c1);
Cookie c2 = new Cookie();
c2.name("c1");
c2.value("hello1");
c2.httpOnly(true);
cookieMap.put("c2", c2);
Cookie c3 = new Cookie();
c3.name("c3");
c3.value("hello3");
c3.secure(false);
cookieMap.put("c3", c3);
Cookie c4 = new Cookie();
c4.name("c4");
c4.value("hello4");
c4.domain("www.github.com");
c4.path("/github");
cookieMap.put("c4", c4);
HttpRequest request = mockHttpRequest("GET");
when(request.cookies()).thenReturn(cookieMap);
when(request.cookie("c1")).thenReturn(cookieMap.get("c1").value());
when(request.cookieRaw("c2")).thenReturn(cookieMap.get("c2"));
when(request.cookieRaw("c3")).thenReturn(cookieMap.get("c3"));
when(request.cookieRaw("c4")).thenReturn(cookieMap.get("c4"));
Assert.assertEquals(request.cookies(), cookieMap);
Assert.assertEquals(request.cookies().size(), cookieMap.size());
Assert.assertEquals(request.cookie("c1"), "hello1");
Assert.assertTrue(request.cookieRaw("c2").httpOnly());
Assert.assertFalse(request.cookieRaw("c3").secure());
Assert.assertEquals(request.cookieRaw("c3").path(), "/");
Assert.assertEquals(request.cookieRaw("c4").domain(), "www.github.com");
Assert.assertEquals(request.cookieRaw("c4").path(), "/github");
}
Aggregations