jdk/test/java/net/CookieHandler/NullUriCookieTest.java
author mikael
Fri, 04 Dec 2015 15:08:49 -0800
changeset 35090 1f5b6aa795d0
parent 14342 8435a30053c1
permissions -rw-r--r--
8144748: Move assembler/macroAssembler inline function definitions to corresponding inline.hpp files Reviewed-by: kvn, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10698
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12192
diff changeset
     2
 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
10698
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
     4
 *
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
     8
 *
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    13
 * accompanied this code).
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    14
 *
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    18
 *
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    21
 * questions.
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    22
 */
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    23
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    24
/*
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    25
 * @test
12192
dd8301ce22b6 7045655: An empty InMemoryCookieStore should not return true for removeAll
khazra
parents: 10698
diff changeset
    26
 * @bug 6953455 7045655
10698
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    27
 * @summary CookieStore.add() cannot handle null URI parameter
12192
dd8301ce22b6 7045655: An empty InMemoryCookieStore should not return true for removeAll
khazra
parents: 10698
diff changeset
    28
 *     and An empty InMemoryCookieStore should not return true for removeAll
10698
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    29
 */
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    30
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    31
import java.net.CookieManager;
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    32
import java.net.CookieStore;
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    33
import java.net.HttpCookie;
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    34
import java.net.URI;
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    35
import java.net.URISyntaxException;
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    36
import java.util.List;
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    37
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    38
public class NullUriCookieTest {
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    39
    static boolean fail = false;
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    40
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    42
        checkCookieNullUri();
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    43
    }
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    44
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    45
    static void checkCookieNullUri() throws Exception {
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    46
        //get a cookie store implementation and add a cookie to the store with null URI
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    47
        CookieStore cookieStore = (new CookieManager()).getCookieStore();
12192
dd8301ce22b6 7045655: An empty InMemoryCookieStore should not return true for removeAll
khazra
parents: 10698
diff changeset
    48
        //Check if removeAll() retrurns false on an empty CookieStore
dd8301ce22b6 7045655: An empty InMemoryCookieStore should not return true for removeAll
khazra
parents: 10698
diff changeset
    49
        if (cookieStore.removeAll()) {
dd8301ce22b6 7045655: An empty InMemoryCookieStore should not return true for removeAll
khazra
parents: 10698
diff changeset
    50
            fail = true;
dd8301ce22b6 7045655: An empty InMemoryCookieStore should not return true for removeAll
khazra
parents: 10698
diff changeset
    51
        }
dd8301ce22b6 7045655: An empty InMemoryCookieStore should not return true for removeAll
khazra
parents: 10698
diff changeset
    52
        checkFail("removeAll on empty store should return false");
10698
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    53
        HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    54
        cookie.setDomain("foo.com");
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    55
        cookieStore.add(null, cookie);
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    56
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    57
        //Retrieve added cookie
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    58
        URI uri = new URI("http://foo.com");
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    59
        List<HttpCookie> addedCookieList = cookieStore.get(uri);
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    60
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    61
        //Verify CookieStore behaves well
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    62
        if (addedCookieList.size() != 1) {
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    63
           fail = true;
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    64
        }
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    65
        checkFail("Abnormal size of cookie jar");
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    66
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    67
        for (HttpCookie chip : addedCookieList) {
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    68
            if (!chip.equals(cookie)) {
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    69
                 fail = true;
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    70
            }
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    71
        }
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    72
        checkFail("Cookie not retrieved from Cookie Jar");
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    73
        boolean ret = cookieStore.remove(null,cookie);
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    74
        if (!ret) {
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    75
            fail = true;
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    76
        }
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    77
        checkFail("Abnormal removal behaviour from Cookie Jar");
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    78
    }
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    79
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    80
    static void checkFail(String exp) {
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    81
        if (fail) {
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    82
            throw new RuntimeException(exp);
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    83
        }
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    84
    }
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    85
}
b2da906f8080 6953455: CookieStore.add() cannot handle null URI parameter, contrary to the API
chegar
parents:
diff changeset
    86