use of com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments in project ezyhttp by youngmonkeys.
the class BlockingServlet method newRequestArguments.
protected RequestArguments newRequestArguments(HttpMethod method, String uriTemplate, HttpServletRequest request, HttpServletResponse response) {
SimpleRequestArguments arguments = new SimpleRequestArguments();
arguments.setDebug(debug);
arguments.setMethod(method);
arguments.setRequest(request);
arguments.setResponse(response);
arguments.setUriTemplate(uriTemplate);
arguments.setCookies(request.getCookies());
arguments.setObjectMapper(objectMapper);
arguments.setRedirectionAttributesFromCookie();
Enumeration<String> paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String paramName = paramNames.nextElement();
String[] paramValues = request.getParameterValues(paramName);
arguments.setParameter(paramName, paramValues);
}
Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement();
String headerValue = request.getHeader(headerName);
arguments.setHeader(headerName, headerValue);
}
return arguments;
}
use of com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments in project ezyhttp by youngmonkeys.
the class SimpleRequestArgumentsTest method setRedirectionAttributesFromCookieTest.
@Test
public void setRedirectionAttributesFromCookieTest() throws IOException {
// given
ObjectMapper objectMapper = new ObjectMapper();
SimpleRequestArguments sut = new SimpleRequestArguments();
sut.setObjectMapper(objectMapper);
sut.setResponse(mock(HttpServletResponse.class));
Map<String, Map<String, Object>> data = new HashMap<>();
data.put("hello", Collections.singletonMap("foo", true));
data.put("world", Collections.singletonMap("bar", 10));
String dataString = EzyBase64.encodeUtf(objectMapper.writeValueAsString(data));
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.assertEquals(actualAttributes, data, false);
Asserts.assertEquals(sut.getRedirectionAttribute("hello"), data.get("hello"), false);
Asserts.assertEquals(sut.getRedirectionAttribute("world", Map.class), data.get("world"), false);
Asserts.assertEquals(sut.getRedirectionAttribute("world", Map.class, Collections.emptyMap()), data.get("world"), false);
Asserts.assertEquals(sut.getRedirectionAttribute("hello", "world"), data.get("hello"), false);
Asserts.assertEquals(sut.getRedirectionAttribute("hello"), data.get("hello"), false);
Asserts.assertEquals(sut.getRedirectionAttribute("not found", true), true);
Asserts.assertEquals(sut.getRedirectionAttribute("not found", int.class, 0), 0);
sut.release();
}
use of com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments in project ezyhttp by youngmonkeys.
the class SimpleRequestArgumentsTest method getByDefaultTest.
@Test
public void getByDefaultTest() {
// given
SimpleRequestArguments sut = new SimpleRequestArguments();
// when
// then
Asserts.assertEquals("paramValue", sut.getParameter(1, "paramValue"));
Asserts.assertEquals("paramValue", sut.getParameter("key", "paramValue"));
Asserts.assertEquals("headerValue", sut.getHeader(1, "headerValue"));
Asserts.assertEquals("headerValue", sut.getHeader("key", "headerValue"));
Asserts.assertEquals("cookieValue", sut.getCookieValue(1, "cookieValue"));
Asserts.assertEquals("cookieValue", sut.getCookieValue("key", "cookieValue"));
sut.release();
}
use of com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments in project ezyhttp by youngmonkeys.
the class SimpleRequestArgumentsTest method argumentTest.
@Test
public void argumentTest() {
// given
SimpleRequestArguments sut = new SimpleRequestArguments();
// when
// then
Asserts.assertNull(sut.getArgument("unknown"));
sut.release();
}
use of com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments in project ezyhttp by youngmonkeys.
the class SimpleRequestArgumentsTest method parameterTest.
@SuppressWarnings("unchecked")
@Test
public void parameterTest() {
// given
SimpleRequestArguments sut = new SimpleRequestArguments();
sut.setParameter("hello", new String[] { "world" });
sut.setParameter("foo", new String[] { "bar" });
// when
String paramOverSize = sut.getParameter(3);
String paramByName = sut.getParameter("hello");
Map<String, String> params = sut.getParameters();
// then
Asserts.assertNull(paramOverSize);
Asserts.assertEquals("world", paramByName);
Map<String, String> expectedParams = EzyMapBuilder.mapBuilder().put("hello", "world").put("foo", "bar").build();
Asserts.assertEquals(expectedParams, params);
sut.release();
}
Aggregations