public void testLoad() throws Exception {
    assertEquals(0, man.getCookieCount());
    man.addFile(findTestPath("testfiles/cookies.txt"));
    assertEquals(3, man.getCookieCount());

    int num = 0;
    assertEquals("name", man.get(num).getName());
    assertEquals("value", man.get(num).getValue());
    assertEquals("path", man.get(num).getPath());
    assertEquals("domain", man.get(num).getDomain());
    assertTrue(man.get(num).getSecure());
    assertEquals(num, man.get(num).getExpires());

    num++;
    assertEquals("name2", man.get(num).getName());
    assertEquals("value2", man.get(num).getValue());
    assertEquals("/", man.get(num).getPath());
    assertEquals("", man.get(num).getDomain());
    assertFalse(man.get(num).getSecure());
    assertEquals(0, man.get(num).getExpires());

    num++;
    assertEquals("a", man.get(num).getName());
    assertEquals("b", man.get(num).getValue());
    assertEquals("d", man.get(num).getPath());
    assertEquals("c", man.get(num).getDomain());
    assertTrue(man.get(num).getSecure());
    assertEquals(0, man.get(num).getExpires()); // Show that maxlong now saved as 0
  }
 public void testCrossDomainHandling() throws Exception {
   URL url = new URL("http://jakarta.apache.org/");
   assertEquals(0, man.getCookieCount()); // starts empty
   man.addCookieFromHeader("test=2;domain=.hc.apache.org", url);
   assertEquals(0, man.getCookieCount()); // should not be stored
   man.addCookieFromHeader("test=1;domain=.jakarta.apache.org", url);
   assertEquals(1, man.getCookieCount()); // OK
 }
 public void testRemoveCookie() throws Exception {
   man.setThreadContext(jmctx);
   Cookie c = new Cookie("id", "me", "127.0.0.1", "/", false, 0);
   man.add(c);
   assertEquals(1, man.getCookieCount());
   // This should be ignored, as there is no value
   Cookie d = new Cookie("id", "", "127.0.0.1", "/", false, 0);
   man.add(d);
   assertEquals(0, man.getCookieCount());
   man.add(c);
   man.add(c);
   assertEquals(1, man.getCookieCount());
   Cookie e = new Cookie("id", "me2", "127.0.0.1", "/", false, 0);
   man.add(e);
   assertEquals(1, man.getCookieCount());
 }
 public void testCookies2() throws Exception {
   URL url = new URL("https://a.b.c.d/testCookies2");
   man.addCookieFromHeader("test1=1;secure, test2=2;secure", url);
   assertEquals(2, man.getCookieCount());
   String s = man.getCookieHeaderForURL(url);
   assertNotNull(s);
   assertEquals("test1=1; test2=2", s);
 }
 // Test multi-cookie header handling
 public void testCookies1() throws Exception {
   URL url = new URL("http://a.b.c.d/testCookies1");
   man.addCookieFromHeader("test1=1; comment=\"how,now\", test2=2; version=1", url);
   assertEquals(2, man.getCookieCount());
   String s = man.getCookieHeaderForURL(url);
   assertNotNull(s);
   assertEquals("test1=1; test2=2", s);
 }
 // Test New cookie is returned
 public void testNewCookie() throws Exception {
   URL url = new URL("http://a.b.c/");
   man.addCookieFromHeader("test=1; expires=Mon, 01-Jan-2990 00:00:00 GMT", url);
   assertEquals(1, man.getCookieCount());
   String s = man.getCookieHeaderForURL(url);
   assertNotNull(s);
   assertEquals("test=1", s);
 }
 public void testCookieOrdering1() throws Exception {
   URL url = new URL("http://order.now/sub1/moo.html");
   man.addCookieFromHeader("test1=moo1;path=/", url);
   man.addCookieFromHeader("test2=moo2;path=/sub1", url);
   man.addCookieFromHeader("test2=moo3;path=/", url);
   assertEquals(3, man.getCookieCount());
   String s = man.getCookieHeaderForURL(url);
   assertNotNull(s);
   assertEquals("test2=moo2; test1=moo1; test2=moo3", s);
 }
 public void testCookiePolicyIgnore() throws Exception {
   man.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
   man.testStarted(); // ensure policy is picked up
   URL url = new URL("http://order.now/sub1/moo.html");
   man.addCookieFromHeader("test1=moo1;", url);
   man.addCookieFromHeader("test2=moo2;path=/sub1", url);
   man.addCookieFromHeader("test2=moo3;path=/", url);
   assertEquals(0, man.getCookieCount()); // Cookies are ignored
   Cookie cc;
   cc = new Cookie("test1", "moo1", null, "/sub1", false, 0, false, false);
   man.add(cc);
   cc = new Cookie("test2", "moo2", null, "/sub1", false, 0, true, false);
   man.add(cc);
   cc = new Cookie("test3", "moo3", null, "/", false, 0, false, false);
   man.add(cc);
   assertEquals(3, man.getCookieCount());
   assertEquals("/sub1", man.get(0).getPath());
   assertEquals("/sub1", man.get(1).getPath());
   assertEquals("/", man.get(2).getPath());
   String s = man.getCookieHeaderForURL(url);
   assertNull(s);
   org.apache.commons.httpclient.Cookie[] c = man.getCookiesForUrl(url);
   assertEquals(0, c.length); // Cookies again ignored
 }
 public void testCookieOrdering2() throws Exception {
   URL url = new URL("http://order.now/sub1/moo.html");
   man.addCookieFromHeader("test1=moo1;", url);
   man.addCookieFromHeader("test2=moo2;path=/sub1", url);
   man.addCookieFromHeader("test2=moo3;path=/", url);
   assertEquals(3, man.getCookieCount());
   assertEquals("/sub1", man.get(0).getPath()); // Defaults to caller URL
   assertEquals("/sub1", man.get(1).getPath());
   assertEquals("/", man.get(2).getPath());
   String s = man.getCookieHeaderForURL(url);
   assertNotNull(s);
   org.apache.commons.httpclient.Cookie[] c = man.getCookiesForUrl(url);
   assertEquals("/sub1", c[0].getPath());
   assertFalse(c[0].isPathAttributeSpecified());
   assertEquals("/sub1", c[1].getPath());
   assertTrue(c[1].isPathAttributeSpecified());
   assertEquals("/", c[2].getPath());
   assertEquals("test1=moo1; test2=moo2; test2=moo3", s);
 }
 public void testCookiePolicyNetscape() throws Exception {
   man.setCookiePolicy(CookiePolicy.NETSCAPE);
   man.testStarted(); // ensure policy is picked up
   URL url = new URL("http://www.order.now/sub1/moo.html");
   man.addCookieFromHeader("test1=moo1;", url);
   man.addCookieFromHeader("test2=moo2;path=/sub1", url);
   man.addCookieFromHeader("test2=moo3;path=/", url);
   assertEquals(3, man.getCookieCount());
   assertEquals("/sub1", man.get(0).getPath());
   assertEquals("/sub1", man.get(1).getPath());
   assertEquals("/", man.get(2).getPath());
   String s = man.getCookieHeaderForURL(url);
   assertNotNull(s);
   org.apache.commons.httpclient.Cookie[] c = man.getCookiesForUrl(url);
   assertEquals("/sub1", c[0].getPath());
   assertFalse(c[0].isPathAttributeSpecified());
   assertEquals("/sub1", c[1].getPath());
   assertTrue(c[1].isPathAttributeSpecified());
   assertEquals("/", c[2].getPath());
   assertTrue(c[2].isPathAttributeSpecified());
   assertEquals("test1=moo1; test2=moo2; test2=moo3", s);
 }