@Test public void testSecure() throws MalformedURLException { CookieJar jar = new CookieJar(); Cookie cookie = new Cookie("myname", "myvalue"); cookie.setDomain(".10gen.com"); cookie.setPath("/"); cookie.setSecure(true); jar.addCookie(new URL("https://www.10gen.com"), cookie); assertSame(cookie, jar.getActiveCookies(new URL("https://10gen.com/")).get("myname")); assertSame(0, jar.getActiveCookies(new URL("http://10gen.com/")).size()); }
@Test public void testPath() throws MalformedURLException { CookieJar jar = new CookieJar(); Cookie cookie = new Cookie("myname", "myvalue"); cookie.setDomain(".10gen.com"); cookie.setPath("/subdir"); jar.addCookie(new URL("http://www.10gen.com/subdir"), cookie); assertSame( cookie, jar.getActiveCookies(new URL("http://10gen.com/subdir/moo/baa.html")).get("myname")); assertSame(0, jar.getActiveCookies(new URL("http://10gen.com/otherdir/")).size()); }
@Test public void testSimple() throws MalformedURLException { CookieJar jar = new CookieJar(); Cookie cookie = new Cookie("myname", "myvalue"); cookie.setDomain("10gen.com"); cookie.setPath("/"); jar.addCookie(new URL("http://10gen.com/"), cookie); // make sure it was actually saved assertSame(cookie, jar.getAll().get("myname")); // make sure it would resent to the same url assertSame(cookie, jar.getActiveCookies(new URL("http://10gen.com/")).get("myname")); // make sure it won't be sent elsewhere URL otherUrl = new URL("http://someotherhost.com/with/random/path"); assertEquals(0, jar.getActiveCookies(otherUrl).size()); }