use of java.net.HttpCookie in project j2objc by google.
the class CookiesTest method testCookieStoreRemoveRequiresUri.
public void testCookieStoreRemoveRequiresUri() throws URISyntaxException {
CookieStore cookieStore = new CookieManager().getCookieStore();
HttpCookie cookieA = new HttpCookie("a", "android");
cookieStore.add(new URI("http://android.com/source/"), cookieA);
assertFalse(// RI6 fails this
"Expected remove() to take the cookie URI into account.", cookieStore.remove(new URI("http://code.google.com/"), cookieA));
assertEquals(Arrays.asList(cookieA), cookieStore.getCookies());
}
use of java.net.HttpCookie in project jphp by jphp-compiler.
the class HttpClientExtension method arrayToCookie.
public static HttpCookie arrayToCookie(ArrayMemory array) {
Memory name = array.valueOfIndex("name");
if (!name.toBoolean()) {
throw new IllegalArgumentException("Cookie name is empty");
}
HttpCookie cookie = new HttpCookie(name.toString(), array.valueOfIndex("value").toString());
if (array.containsKey("domain")) {
cookie.setDomain(array.valueOfIndex("domain").toString());
}
if (array.containsKey("path")) {
cookie.setPath(array.valueOfIndex("path").toString());
}
if (array.containsKey("secure")) {
cookie.setSecure(array.valueOfIndex("secure").toBoolean());
}
if (array.containsKey("maxAge")) {
cookie.setMaxAge(array.valueOfIndex("maxAge").toLong());
}
if (array.containsKey("comment")) {
cookie.setComment(array.valueOfIndex("comment").toString());
}
if (array.containsKey("discard")) {
cookie.setDiscard(array.valueOfIndex("discard").toBoolean());
}
if (array.containsKey("ports")) {
cookie.setPortlist(array.valueOfIndex("ports").toString());
}
if (array.containsKey("version")) {
cookie.setVersion(array.valueOfIndex("version").toInteger());
}
if (array.containsKey("httpOnly")) {
cookie.setHttpOnly(array.valueOfIndex("httpOnly").toBoolean());
}
return cookie;
}
use of java.net.HttpCookie in project android-oss by kickstarter.
the class RefTagUtilsTest method testBuildCookieForRefTagAndProject_WithMalformedUrl.
@Test
public void testBuildCookieForRefTagAndProject_WithMalformedUrl() {
final Project.Urls.Web webUrls = ProjectFactory.project().urls().web().toBuilder().project("such:\\bad^<data").build();
final Project.Urls urls = ProjectFactory.project().urls().toBuilder().web(webUrls).build();
final Project project = ProjectFactory.project().toBuilder().urls(urls).build();
final RefTag refTag = RefTag.category();
final HttpCookie cookie = RefTagUtils.buildCookieWithRefTagAndProject(refTag, project);
assertNull(cookie);
}
use of java.net.HttpCookie in project android-oss by kickstarter.
the class RefTagUtilsTest method testFindRefTagCookieForProject_WhenCookieExists.
@Test
public void testFindRefTagCookieForProject_WhenCookieExists() {
final CookieManager cookieManager = new CookieManager();
final CookieStore cookieStore = cookieManager.getCookieStore();
final Project project = ProjectFactory.project();
final RefTag refTag = RefTag.recommended();
// set and retrieve the cookie
cookieStore.add(null, new HttpCookie("ref_" + project.id(), refTag.tag() + "%3F" + SystemUtils.secondsSinceEpoch()));
final HttpCookie cookie = RefTagUtils.findRefTagCookieForProject(project, cookieManager, sharedPreferences);
assertNotNull(cookie);
assertEquals(RefTagUtils.cookieNameForProject(project), cookie.getName());
assertEquals(RefTagUtils.cookieValueForRefTag(refTag), cookie.getValue());
}
use of java.net.HttpCookie in project android-oss by kickstarter.
the class RefTagUtilsTest method testBuildCookieForRefTagAndProject_WithWellFormedUrl.
@Test
public void testBuildCookieForRefTagAndProject_WithWellFormedUrl() {
final Project project = ProjectFactory.project();
final RefTag refTag = RefTag.category();
final HttpCookie cookie = RefTagUtils.buildCookieWithRefTagAndProject(refTag, project);
assertNotNull(cookie);
assertEquals(ProjectUtils.timeInSecondsUntilDeadline(project).longValue(), cookie.getMaxAge());
assertEquals("www.kickstarter.com", cookie.getDomain());
}
Aggregations