jdk/test/sun/security/pkcs11/Provider/ConfigShortPath.java
changeset 9270 499a73f29347
parent 9261 efb29ab3324e
child 17478 2cd7d026396c
equal deleted inserted replaced
9269:f66626469aa8 9270:499a73f29347
    27  * @author Valerie Peng
    27  * @author Valerie Peng
    28  */
    28  */
    29 
    29 
    30 import java.security.*;
    30 import java.security.*;
    31 import java.io.*;
    31 import java.io.*;
       
    32 import java.lang.reflect.*;
    32 
    33 
    33 public class ConfigShortPath {
    34 public class ConfigShortPath {
    34 
    35 
    35     private static final String[] configNames = { "csp.cfg", "cspPlus.cfg" };
    36     private static final String[] configNames = { "csp.cfg", "cspPlus.cfg" };
    36 
    37 
    37     public static void main(String[] args) {
    38     public static void main(String[] args) throws Exception {
       
    39         Constructor cons = null;
       
    40         try {
       
    41             Class clazz = Class.forName("sun.security.pkcs11.SunPKCS11");
       
    42             cons = clazz.getConstructor(String.class);
       
    43         } catch (Exception ex) {
       
    44             System.out.println("Skipping test - no PKCS11 provider available");
       
    45             return;
       
    46         }
    38         String testSrc = System.getProperty("test.src", ".");
    47         String testSrc = System.getProperty("test.src", ".");
    39         for (int i = 0; i < configNames.length; i++) {
    48         for (int i = 0; i < configNames.length; i++) {
    40             String configFile = testSrc + File.separator + configNames[i];
    49             String configFile = testSrc + File.separator + configNames[i];
       
    50 
    41             System.out.println("Testing against " + configFile);
    51             System.out.println("Testing against " + configFile);
    42             try {
    52             try {
    43                 Provider p = new sun.security.pkcs11.SunPKCS11(configFile);
    53                 Object obj = cons.newInstance(configFile);
    44             } catch (ProviderException pe) {
    54             } catch (InvocationTargetException ite) {
    45                 String cause = pe.getCause().getMessage();
    55                 Throwable cause = ite.getCause();
    46                 if (cause.indexOf("Unexpected token") != -1) {
    56                 if (cause instanceof ProviderException) {
    47                     // re-throw to indicate test failure
    57                     String causeMsg = cause.getCause().getMessage();
    48                     throw pe;
    58                     // Indicate failure if due to parsing config
       
    59                     if (causeMsg.indexOf("Unexpected token") != -1) {
       
    60                         throw (ProviderException) cause;
       
    61                     }
    49                 }
    62                 }
    50             }
    63             }
    51         }
    64         }
    52     }
    65     }
    53 }
    66 }