ResponseImpl extends Response { @Override public Map<String, NewCookie> getCookies() { List<Object> cookieHeaders = getMetadata().get(SET_COOKIE); if (cookieHeaders == null) { return Collections.emptyMap(); } Map<String, NewCookie> cookies = new HashMap<>(); for (Object cookieHeader : cookieHeaders) { if (cookieHeader instanceof NewCookie) { NewCookie newCookie = (NewCookie)cookieHeader; cookies.put(newCookie.getName(), newCookie); } else if (cookieHeader != null) { NewCookie newCookie = NewCookie.valueOf(getHeaderAsString(cookieHeader)); if (newCookie != null) { cookies.put(newCookie.getName(), newCookie); } } } return cookies; } protected  ResponseImpl(int status, Object entity, Annotation[] entityAnnotations, MultivaluedMap<String, Object> headers); @Override Object getEntity(); Annotation[] getEntityAnnotations(); @Override T readEntity(Class<T> entityType); @SuppressWarnings("unchecked") @Override T readEntity(GenericType<T> entityType); @Override T readEntity(Class<T> entityType, Annotation[] annotations); @SuppressWarnings("unchecked") @Override T readEntity(GenericType<T> entityType, Annotation[] annotations); @Override boolean hasEntity(); @Override boolean bufferEntity(); @Override void close(); boolean isClosed(); @Override MediaType getMediaType(); @Override Locale getLanguage(); @Override int getLength(); @Override Set<String> getAllowedMethods(); @Override Map<String, NewCookie> getCookies(); @Override EntityTag getEntityTag(); @Override Date getDate(); @Override Date getLastModified(); @Override URI getLocation(); @Override Set<Link> getLinks(); @Override boolean hasLink(String relation); @Override Link getLink(String relation); @Override Link.Builder getLinkBuilder(String relation); @Override MultivaluedMap<String, Object> getMetadata(); @Override MultivaluedMap<String, String> getStringHeaders(); @Override String getHeaderString(String name); @Override int getStatus(); @Override StatusType getStatusInfo(); @Override String toString();  }
@Test public void getsSetCookieHeader() throws Exception { MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>(); List<Object> cookiesList = newArrayList(new NewCookie("name", "andrew"), new NewCookie("company", "codenvy", "/path", "codenvy.com", 1, "comment", 300, null, true, true)); headers.put(SET_COOKIE, cookiesList); ResponseImpl response = new ResponseImpl(200, "foo", null, headers); Map<String, NewCookie> expectedCookies = ImmutableMap.of("name", new NewCookie("name", "andrew"), "company", new NewCookie("company", "codenvy", "/path", "codenvy.com", 1, "comment", 300, null, true, true)); assertEquals(expectedCookies, response.getCookies()); }
@Test public void parsesSetCookieHeader() throws Exception { MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>(); headers.put(SET_COOKIE, newArrayList("name=andrew", "company=codenvy;version=1;paTh=/path;Domain=codenvy.com;comment=\"comment\";max-age=300;HttpOnly;secure")); ResponseImpl response = new ResponseImpl(200, "foo", null, headers); Map<String, NewCookie> expectedCookies = ImmutableMap.of("name", new NewCookie("name", "andrew"), "company", new NewCookie("company", "codenvy", "/path", "codenvy.com", 1, "comment", 300, null, true, true)); assertEquals(expectedCookies, response.getCookies()); }
@Test public void getsEmptyMapIfSetCookieHeaderIsNotSet() throws Exception { MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>(); ResponseImpl response = new ResponseImpl(200, "foo", null, headers); assertEquals(newHashMap(), response.getCookies()); }