test/jdk/com/sun/jndi/dns/EnvTests/GetEnv.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 we can get the environment properties of a DNS context
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    28
 *          and its derived context, and check that they contain relevant and
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    29
 *          irrelevant properties.
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 GetEnv
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 GetEnv 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
    public static void main(String[] args) throws Exception {
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    43
        new GetEnv().run(args);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    44
    }
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    45
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
     * Tests that we can get the environment properties of a DNS context
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    48
     * and its derived context, and check that they contain relevant and
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    49
     * irrelevant properties.
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
    @Override public void runTest() throws Exception {
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    52
        initContext();
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    53
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    54
        Context child = (Context) context().lookup(getKey());
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
        Hashtable envParent = context().getEnvironment();
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    57
        Hashtable envChild = child.getEnvironment();
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
        DNSTestUtils.debug(child);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    60
        DNSTestUtils.debug("Parent env: " + envParent);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    61
        DNSTestUtils.debug("Child env: " + envChild);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    62
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    63
        verifyEnvProperty(envParent, "com.sun.jndi.dns.recursion", "false");
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    64
        verifyEnvProperty(envParent, "some.irrelevant.property", "somevalue");
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    65
        verifyEnvProperty(envChild, "com.sun.jndi.dns.recursion", "false");
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    66
        verifyEnvProperty(envChild, "some.irrelevant.property", "somevalue");
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
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    69
    private void initContext() throws NamingException {
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    70
        env().put("com.sun.jndi.dns.recursion", "false");
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    71
        env().put("some.irrelevant.property", "somevalue");
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    72
        setContext(new InitialDirContext(env()));
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    73
    }
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    74
}