test/jdk/com/sun/jndi/dns/EnvTests/AddOps.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 add the authoritative property to a context,
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    28
 *          that it affects subsequent context operations.
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    29
 * @library ../lib/
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    30
 * @modules java.base/sun.security.util
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    31
 * @run main AddOps
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    32
 */
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
import javax.naming.Context;
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    35
import javax.naming.NameNotFoundException;
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.Attributes;
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    38
import javax.naming.directory.InitialDirContext;
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 AddOps 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 AddOps().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 when we add the authoritative property to a context,
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    48
     * that it affects subsequent context operations.
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
    @Override public void runTest() throws Exception {
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    51
        setContext(new InitialDirContext(env()));
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    52
        addToEnvAndVerifyOldValIsNull(Context.AUTHORITATIVE, "true");
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    53
        retrieveAndVerifyAuthData();
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    54
        retrieveNonAuthData();
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
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    57
    private void retrieveAndVerifyAuthData() throws NamingException {
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    58
        // Ensure that auth data retrieval is OK
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    59
        retrieveAndVerifyData(getFqdnUrl(), new String[] { "*" });
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    60
    }
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
    private void retrieveNonAuthData() throws NamingException {
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    63
        try {
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    64
            // Ensure that nonauth data retrieval cannot be retrieved
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    65
            Attributes retAttrs = context()
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    66
                    .getAttributes(getForeignFqdnUrl(), new String[] { "*" });
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    67
            DNSTestUtils.debug(context().getEnvironment());
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    68
            DNSTestUtils.debug(retAttrs);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    69
            throw new RuntimeException(
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    70
                    "Failed: Expecting nonauth entry not found "
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    71
                            + getForeignFqdnUrl());
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
        } catch (NameNotFoundException e) {
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    74
            System.out.println("Got expected exception: " + e);
7939b3c4e408 8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/
xyin
parents:
diff changeset
    75
        }
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
}