jdk/test/java/security/cert/CertPathValidatorException/ReasonTest.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 1238 6d1f4b722acd
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1238
diff changeset
     2
 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
     4
 *
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
     8
 *
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    13
 * accompanied this code).
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    14
 *
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1238
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1238
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1238
diff changeset
    21
 * questions.
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    22
 */
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    23
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    24
/*
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    25
 * @test
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    26
 * @bug 6465942
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    27
 * @summary unit test for CertPathValidatorException.Reason
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    28
 */
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    29
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    30
import java.security.cert.CertPathValidatorException;
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    31
import java.security.cert.CertPathValidatorException.BasicReason;
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    32
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    33
public class ReasonTest {
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    34
    private static volatile boolean failed = false;
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    35
    public static void main(String[] args) throws Exception {
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    36
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    37
        // check that getReason returns UNSPECIFIED if reason not specified
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    38
        CertPathValidatorException cpve = new CertPathValidatorException("abc");
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    39
        if (cpve.getReason() != BasicReason.UNSPECIFIED) {
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    40
            failed = true;
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    41
            System.err.println("FAILED: unexpected reason: " + cpve.getReason());
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    42
        }
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    43
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    44
        // check that getReason returns specified reason
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    45
        cpve = new CertPathValidatorException
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    46
            ("abc", null, null, -1, BasicReason.REVOKED);
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    47
        if (cpve.getReason() != BasicReason.REVOKED) {
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    48
            failed = true;
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    49
            System.err.println("FAILED: unexpected reason: " + cpve.getReason());
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    50
        }
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    51
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    52
        // check that ctor throws NPE when reason is null
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    53
        try {
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    54
            cpve = new CertPathValidatorException("abc", null, null, -1, null);
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    55
            failed = true;
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    56
            System.err.println("ctor did not throw NPE for null reason");
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    57
        } catch (Exception e) {
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    58
            if (!(e instanceof NullPointerException)) {
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    59
                failed = true;
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    60
                System.err.println("FAILED: unexpected exception: " + e);
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    61
            }
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    62
        }
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    63
        if (failed) {
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    64
            throw new Exception("Some tests FAILED");
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    65
        }
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    66
    }
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
diff changeset
    67
}