test/jdk/com/sun/jndi/dns/EnvTests/RemoveInherited.java
author xyin
Wed, 08 Aug 2018 10:21:23 +0800
changeset 51331 7939b3c4e408
permissions -rw-r--r--
8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/ Reviewed-by: vtewari, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51331
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
     1
/*
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
     2
 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
     4
 *
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
     8
 *
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    13
 * accompanied this code).
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    14
 *
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    18
 *
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    21
 * questions.
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    22
 */
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    23
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    24
/*
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    25
 * @test
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    26
 * @bug 8208279
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    27
 * @summary Tests that when we remove environment properties from a context,
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    28
 *          its changes are reflected in the environment properties of any
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    29
 *          child context derived from the context.
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    30
 * @library ../lib/
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    31
 * @modules java.base/sun.security.util
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    32
 * @run main RemoveInherited
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    33
 */
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    34
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    35
import javax.naming.Context;
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    36
import javax.naming.NamingException;
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    37
import javax.naming.directory.InitialDirContext;
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    38
import java.util.Hashtable;
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    39
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    40
public class RemoveInherited extends EnvTestBase {
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    41
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    42
    private static final String IRRELEVANT_PROPERTY_NAME = "some.irrelevant.property";
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    43
    private static final String IRRELEVANT_PROPERTY_VALUE = "somevalue";
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    44
    private static final String DNS_RECURSION_PROPERTY_NAME = "com.sun.jndi.dns.recursion";
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    45
    private static final String DNS_RECURSION_PROPERTY_VALUE = "false";
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    46
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    47
    public static void main(String[] args) throws Exception {
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    48
        new RemoveInherited().run(args);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    49
    }
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    50
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    51
    /*
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    52
     * Tests that when we remove environment properties from a context,
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    53
     * its changes are reflected in the environment properties of any
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    54
     * child context derived from the context.
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    55
     */
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    56
    @Override public void runTest() throws Exception {
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    57
        initContext();
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    58
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    59
        // some.irrelevant.property been set in initContext(), should not be null
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    60
        Object val = context().removeFromEnvironment(IRRELEVANT_PROPERTY_NAME);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    61
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    62
        if (!IRRELEVANT_PROPERTY_VALUE.equals(val)) {
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    63
            throw new RuntimeException(
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    64
                    "Failed: unexpected return value for removeFromEnvironment: "
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    65
                            + val);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    66
        }
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    67
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    68
        Context child = (Context) context().lookup(getKey());
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    69
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    70
        Hashtable envParent = context().getEnvironment();
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    71
        Hashtable envChild = child.getEnvironment();
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    72
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    73
        DNSTestUtils.debug(child);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    74
        DNSTestUtils.debug("Parent env: " + envParent);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    75
        DNSTestUtils.debug("Child env: " + envChild);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    76
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    77
        verifyEnvProperty(envParent, DNS_RECURSION_PROPERTY_NAME,
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    78
                DNS_RECURSION_PROPERTY_VALUE);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    79
        verifyEnvProperty(envParent, IRRELEVANT_PROPERTY_NAME, null);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    80
        verifyEnvProperty(envChild, DNS_RECURSION_PROPERTY_NAME,
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    81
                DNS_RECURSION_PROPERTY_VALUE);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    82
        verifyEnvProperty(envChild, IRRELEVANT_PROPERTY_NAME, null);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    83
    }
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    84
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    85
    private void initContext() throws NamingException {
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    86
        env().put(DNS_RECURSION_PROPERTY_NAME, DNS_RECURSION_PROPERTY_VALUE);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    87
        env().put(IRRELEVANT_PROPERTY_NAME, IRRELEVANT_PROPERTY_VALUE);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    88
        setContext(new InitialDirContext(env()));
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    89
    }
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    90
}