Search in sources :

Example 1 with Cookie

use of com.yahoo.jdisc.http.Cookie in project vespa by vespa-engine.

the class DiscFilterResponseTest method testAddCookie.

@Test
public void testAddCookie() {
    URI uri = URI.create("http://example.com/test");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    HttpResponse httpResp = newResponse(httpReq, 200);
    DiscFilterResponse response = new JdiscFilterResponse(httpResp);
    response.addCookie(JDiscCookieWrapper.wrap(new Cookie("name", "value")));
    List<Cookie> cookies = response.getCookies();
    Assert.assertEquals(cookies.size(), 1);
    Assert.assertEquals(cookies.get(0).getName(), "name");
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) Cookie(com.yahoo.jdisc.http.Cookie) HttpResponse(com.yahoo.jdisc.http.HttpResponse) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 2 with Cookie

use of com.yahoo.jdisc.http.Cookie in project vespa by vespa-engine.

the class DiscFilterResponseTest method testSetCookie.

@Test
public void testSetCookie() {
    URI uri = URI.create("http://example.com/test");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    HttpResponse httpResp = newResponse(httpReq, 200);
    DiscFilterResponse response = new JdiscFilterResponse(httpResp);
    response.setCookie("name", "value");
    List<Cookie> cookies = response.getCookies();
    Assert.assertEquals(cookies.size(), 1);
    Assert.assertEquals(cookies.get(0).getName(), "name");
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) Cookie(com.yahoo.jdisc.http.Cookie) HttpResponse(com.yahoo.jdisc.http.HttpResponse) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 3 with Cookie

use of com.yahoo.jdisc.http.Cookie in project vespa by vespa-engine.

the class ServletFilterRequestTest method cookies_can_be_added_and_removed.

@Test
public void cookies_can_be_added_and_removed() {
    Cookie cookie = new Cookie("name", "value");
    filterRequest.addCookie(JDiscCookieWrapper.wrap(cookie));
    assertEquals(filterRequest.getCookies(), Collections.singletonList(cookie));
    assertEquals(parentRequest.getCookies().length, 1);
    javax.servlet.http.Cookie servletCookie = parentRequest.getCookies()[0];
    assertEquals(servletCookie.getName(), cookie.getName());
    assertEquals(servletCookie.getValue(), cookie.getValue());
    filterRequest.clearCookies();
    assertTrue(filterRequest.getCookies().isEmpty());
    assertEquals(parentRequest.getCookies().length, 0);
}
Also used : Cookie(com.yahoo.jdisc.http.Cookie) Test(org.testng.annotations.Test)

Example 4 with Cookie

use of com.yahoo.jdisc.http.Cookie in project vespa by vespa-engine.

the class DiscFilterRequestTest method testRequestConstruction.

@Test
public void testRequestConstruction() {
    URI uri = URI.create("http://localhost:8080/test?param1=abc");
    HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
    httpReq.headers().add(HttpHeaders.Names.CONTENT_TYPE, "text/html;charset=UTF-8");
    httpReq.headers().add("X-Custom-Header", "custom_header");
    List<Cookie> cookies = new ArrayList<Cookie>();
    cookies.add(new Cookie("XYZ", "value"));
    cookies.add(new Cookie("ABC", "value"));
    httpReq.encodeCookieHeader(cookies);
    DiscFilterRequest request = new JdiscFilterRequest(httpReq);
    Assert.assertSame(request.getParentRequest(), httpReq);
    Assert.assertEquals(request.getHeader("X-Custom-Header"), "custom_header");
    Assert.assertEquals(request.getHeader(HttpHeaders.Names.CONTENT_TYPE), "text/html;charset=UTF-8");
    List<Cookie> c = request.getCookies();
    Assert.assertNotNull(c);
    Assert.assertEquals(c.size(), 2);
    Assert.assertEquals(request.getParameter("param1"), "abc");
    Assert.assertNull(request.getParameter("param2"));
    Assert.assertEquals(request.getVersion(), Version.HTTP_1_1);
    Assert.assertEquals(request.getProtocol(), Version.HTTP_1_1.name());
    Assert.assertNull(request.getRequestedSessionId());
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) Cookie(com.yahoo.jdisc.http.Cookie) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 5 with Cookie

use of com.yahoo.jdisc.http.Cookie in project vespa by vespa-engine.

the class JDiscCookieWrapperTest method requireThatWrapWorks.

@Test
public void requireThatWrapWorks() {
    Cookie cookie = new Cookie("name", "value");
    JDiscCookieWrapper wrapper = JDiscCookieWrapper.wrap(cookie);
    wrapper.setComment("comment");
    wrapper.setDomain("yahoo.com");
    wrapper.setMaxAge(10);
    wrapper.setPath("/path");
    wrapper.setVersion(1);
    Assert.assertEquals(wrapper.getName(), cookie.getName());
    Assert.assertEquals(wrapper.getValue(), cookie.getValue());
    Assert.assertEquals(wrapper.getDomain(), cookie.getDomain());
    Assert.assertEquals(wrapper.getComment(), cookie.getComment());
    Assert.assertEquals(wrapper.getMaxAge(), cookie.getMaxAge(TimeUnit.SECONDS));
    Assert.assertEquals(wrapper.getPath(), cookie.getPath());
    Assert.assertEquals(wrapper.getVersion(), cookie.getVersion());
    Assert.assertEquals(wrapper.getSecure(), cookie.isSecure());
}
Also used : Cookie(com.yahoo.jdisc.http.Cookie) Test(org.testng.annotations.Test)

Aggregations

Cookie (com.yahoo.jdisc.http.Cookie)9 Test (org.testng.annotations.Test)7 HttpRequest (com.yahoo.jdisc.http.HttpRequest)4 URI (java.net.URI)4 HttpResponse (com.yahoo.jdisc.http.HttpResponse)2 ArrayList (java.util.ArrayList)1