Search in sources :

Example 6 with SimpleRequestArguments

use of com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments in project ezyhttp by youngmonkeys.

the class SimpleRequestArgumentsTest method cookieNullTest.

@Test
public void cookieNullTest() {
    // given
    SimpleRequestArguments sut = new SimpleRequestArguments();
    sut.setCookies(null);
    // when
    // then
    Asserts.assertNull(sut.getCookieValue(0));
    Asserts.assertNull(sut.getCookieValue(1));
    Asserts.assertNull(sut.getCookieValue("unknown"));
    Asserts.assertNull(sut.getCookie("unknown"));
    sut.release();
}
Also used : SimpleRequestArguments(com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments) Test(org.testng.annotations.Test)

Example 7 with SimpleRequestArguments

use of com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments in project ezyhttp by youngmonkeys.

the class SimpleRequestArgumentsTest method getByDefaultButNotNullTest.

@Test
public void getByDefaultButNotNullTest() {
    // given
    SimpleRequestArguments sut = new SimpleRequestArguments();
    sut.setParameter("key", new String[] { "paramValue0" });
    sut.setHeader("key", "headerValue0");
    sut.setCookies(new Cookie[] { new Cookie("key", "cookieValue0") });
    // when
    // then
    Asserts.assertEquals("paramValue0", sut.getParameter(0, "paramValue"));
    Asserts.assertEquals("paramValue0", sut.getParameter("key", "paramValue"));
    Asserts.assertEquals("headerValue0", sut.getHeader(0, "headerValue"));
    Asserts.assertEquals("headerValue0", sut.getHeader("key", "headerValue"));
    Asserts.assertEquals("cookieValue0", sut.getCookieValue(0, "cookieValue"));
    Asserts.assertEquals("cookieValue0", sut.getCookieValue("key", "cookieValue"));
    sut.release();
}
Also used : Cookie(javax.servlet.http.Cookie) SimpleRequestArguments(com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments) Test(org.testng.annotations.Test)

Example 8 with SimpleRequestArguments

use of com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments in project ezyhttp by youngmonkeys.

the class SimpleRequestArgumentsTest method headerTest.

@Test
public void headerTest() {
    // given
    SimpleRequestArguments sut = new SimpleRequestArguments();
    sut.setHeader("hello", "world");
    sut.setHeader("foo", "bar");
    // when
    String headerOverSize = sut.getHeader(3);
    String headerByName = sut.getHeader("hello");
    // then
    Asserts.assertNull(headerOverSize);
    Asserts.assertEquals("world", headerByName);
    sut.release();
}
Also used : SimpleRequestArguments(com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments) Test(org.testng.annotations.Test)

Example 9 with SimpleRequestArguments

use of com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments in project ezyhttp by youngmonkeys.

the class SimpleRequestArgumentsTest method cookieEmptyTest.

@Test
public void cookieEmptyTest() {
    // given
    SimpleRequestArguments sut = new SimpleRequestArguments();
    sut.setCookies(new Cookie[0]);
    // when
    // then
    Asserts.assertNull(sut.getCookieValue(0));
    Asserts.assertNull(sut.getCookieValue(1));
    Asserts.assertNull(sut.getCookieValue("unknown"));
    Asserts.assertNull(sut.getCookie("unknown"));
    sut.release();
}
Also used : SimpleRequestArguments(com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments) Test(org.testng.annotations.Test)

Example 10 with SimpleRequestArguments

use of com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments in project ezyhttp by youngmonkeys.

the class SimpleRequestArgumentsTest method pathVariableTest.

@Test
public void pathVariableTest() {
    // given
    SimpleRequestArguments sut = new SimpleRequestArguments();
    sut.setUriTemplate("/{foo}/{bar}");
    HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    when(servletRequest.getRequestURI()).thenReturn("/hello/world");
    sut.setRequest(servletRequest);
    // when
    String pathVariableByIndex = sut.getPathVariable(1);
    String pathVariableOverIndex = sut.getPathVariable(3);
    String pathVariableByName = sut.getPathVariable("foo");
    // then
    Asserts.assertNull(pathVariableOverIndex);
    Asserts.assertEquals("hello", pathVariableByName);
    Asserts.assertEquals("world", pathVariableByIndex);
    verify(servletRequest, times(1)).getRequestURI();
    sut.release();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SimpleRequestArguments(com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments) Test(org.testng.annotations.Test)

Aggregations

SimpleRequestArguments (com.tvd12.ezyhttp.server.core.request.SimpleRequestArguments)16 Test (org.testng.annotations.Test)15 Cookie (javax.servlet.http.Cookie)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 AsyncContext (javax.servlet.AsyncContext)1 ServletInputStream (javax.servlet.ServletInputStream)1