use of com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments in project ezyhttp by youngmonkeys.
the class SimpleRequestArgumentsTest method setParameterEmpty.
@Test
public void setParameterEmpty() {
// given
SimpleRequestArguments sut = new SimpleRequestArguments();
sut.setParameter("key", new String[0]);
// when
// then
Asserts.assertEquals("", sut.getParameter(0, "paramValue"));
Asserts.assertEquals("", sut.getParameter("key", "paramValue"));
sut.release();
}
use of com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments in project ezyhttp by youngmonkeys.
the class SimpleRequestArgumentsTest method test.
@Test
public void test() throws Exception {
// given
SimpleRequestArguments sut = new SimpleRequestArguments();
sut.setMethod(HttpMethod.HEAD);
sut.setArgument("arg1", "argValue1");
sut.setUriTemplate("/");
ServletInputStream inputStream = mock(ServletInputStream.class);
HttpServletRequest servletRequest = mock(HttpServletRequest.class);
when(servletRequest.getInputStream()).thenReturn(inputStream);
when(servletRequest.getRequestURI()).thenReturn("/");
when(servletRequest.getContentType()).thenReturn(ContentTypes.TEXT_HTML_UTF8);
sut.setRequest(servletRequest);
AsyncContext asyncContext = mock(AsyncContext.class);
when(servletRequest.getAsyncContext()).thenReturn(asyncContext);
HttpServletResponse servletResponse = mock(HttpServletResponse.class);
sut.setResponse(servletResponse);
// when
String arg1 = sut.getArgument("arg1");
// then
Asserts.assertEquals("argValue1", arg1);
Asserts.assertNull(sut.getArgument("unknown"));
Asserts.assertNull(sut.getParameter(0));
Asserts.assertNull(sut.getParameter("unknown"));
Asserts.assertNull(sut.getHeader(0));
Asserts.assertNull(sut.getHeader("unknown"));
Asserts.assertNull(sut.getPathVariable(0));
Asserts.assertNull(sut.getPathVariable("unknown"));
Asserts.assertEquals(0, sut.getContentLength());
Asserts.assertEquals(ContentTypes.TEXT_HTML, sut.getContentType());
Asserts.assertEquals(ContentTypes.TEXT_HTML_UTF8, sut.getRequestContentType());
Asserts.assertEquals(inputStream, sut.getInputStream());
Asserts.assertNull(sut.getCookie("unknown"));
Asserts.assertNull(sut.getCookieValue(0));
Asserts.assertNull(sut.getCookieValue("unknown"));
Asserts.assertEquals(HttpMethod.HEAD, sut.getMethod());
Asserts.assertEquals(sut.getAsyncContext(), asyncContext);
Asserts.assertFalse(sut.isAsyncStarted());
Asserts.assertEquals(sut.getUriTemplate(), "/");
verify(servletRequest, times(1)).getRequestURI();
verify(servletRequest, times(1)).getInputStream();
sut.release();
}
use of com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments in project ezyhttp by youngmonkeys.
the class SimpleRequestArgumentsTest method setRedirectionAttributesFromCookieExceptionTest.
@Test
public void setRedirectionAttributesFromCookieExceptionTest() {
// given
ObjectMapper objectMapper = new ObjectMapper();
SimpleRequestArguments sut = new SimpleRequestArguments();
sut.setObjectMapper(objectMapper);
sut.setResponse(mock(HttpServletResponse.class));
String dataString = EzyBase64.encodeUtf("hello world");
Cookie cookie = new Cookie(CoreConstants.COOKIE_REDIRECT_ATTRIBUTES_NAME, dataString);
sut.setCookies(new Cookie[] { cookie });
// when
sut.setRedirectionAttributesFromCookie();
// then
Map<String, Object> actualAttributes = sut.getRedirectionAttributes();
Asserts.assertNull(actualAttributes);
Asserts.assertNull(sut.getRedirectionAttribute("hello"));
Asserts.assertNull(sut.getRedirectionAttribute("hello", Map.class));
}
use of com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments in project ezyhttp by youngmonkeys.
the class SimpleRequestArgumentsTest method cookieTest.
@Test
public void cookieTest() {
// given
SimpleRequestArguments sut = new SimpleRequestArguments();
sut.setCookies(new Cookie[] { new Cookie("hello", ""), new Cookie("hello", "world"), new Cookie("hello", "") });
// when
// then
Asserts.assertNull(sut.getCookieValue(3));
Asserts.assertEquals("world", sut.getCookieValue(0));
Asserts.assertEquals("world", sut.getCookie("hello").getValue());
Asserts.assertEquals("world", sut.getCookieValue("hello"));
Asserts.assertNull(sut.getCookie("unknown"));
sut.release();
}
use of com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments in project ezyhttp by youngmonkeys.
the class SimpleRequestArgumentsTest method argumentButDebugTest.
@Test
public void argumentButDebugTest() {
// given
SimpleRequestArguments sut = new SimpleRequestArguments();
sut.setDebug(true);
// when
Throwable e = Asserts.assertThrows(() -> sut.getArgument("unknown"));
// then
Asserts.assertEqualsType(e, NullPointerException.class);
sut.release();
}
Aggregations