test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNotFound.java
author xyin
Wed, 25 Jul 2018 11:03:07 +0800
changeset 51192 499b873761d8
permissions -rw-r--r--
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/ Reviewed-by: vtewari, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51192
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
     1
/*
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
     2
 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
     4
 *
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
     8
 *
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    13
 * accompanied this code).
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    14
 *
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    18
 *
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    21
 * questions.
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    22
 */
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    23
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    24
/*
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    25
 * @test
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    26
 * @bug 8198882
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    27
 * @summary Tests that get attributes of a missing child entry results
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    28
 *          in NameNotFoundException.
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    29
 * @modules java.base/sun.security.util
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    30
 * @library ../lib/
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    31
 * @run main GetAttrsNotFound
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    32
 */
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    33
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    34
import javax.naming.NameNotFoundException;
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    35
import javax.naming.directory.Attributes;
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    36
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    37
public class GetAttrsNotFound extends GetAttrsBase {
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    38
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    39
    public GetAttrsNotFound() {
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    40
        // set new test data instead of default value
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    41
        setKey("notfound");
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    42
    }
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    43
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    44
    public static void main(String[] args) throws Exception {
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    45
        new GetAttrsNotFound().run(args);
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    46
    }
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    47
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    48
    @Override public void runTest() throws Exception {
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    49
        initContext();
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    50
        Attributes retAttrs = getAttributes();
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    51
        DNSTestUtils.debug(retAttrs);
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    52
        throw new RuntimeException(
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    53
                "Failed: getAttributes succeeded unexpectedly");
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    54
    }
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    55
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    56
    /*
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    57
     * Tests that get attributes of a missing child entry results
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    58
     * in NameNotFoundException.
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    59
     */
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    60
    @Override public Attributes getAttributes() throws Exception {
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    61
        return context().getAttributes(getKey());
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    62
    }
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    63
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    64
    @Override public boolean handleException(Exception e) {
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    65
        if (e instanceof NameNotFoundException) {
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    66
            System.out.println("Got exception as expected : " + e);
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    67
            return true;
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    68
        }
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    69
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    70
        return super.handleException(e);
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    71
    }
499b873761d8 8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff changeset
    72
}