test/jdk/javax/smartcardio/TerminalFactorySpiTest.java
author herrick
Wed, 27 Mar 2019 08:27:58 -0400
branchJDK-8200758-branch
changeset 57288 0be43184f52a
parent 47216 71c04702a3d5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28260
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     1
/*
44108
8de4ce18c36f 8167525: update jdk tests to remove @compile --add-modules workaround
amlu
parents: 40261
diff changeset
     2
 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
28260
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     4
 *
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     8
 *
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    13
 * accompanied this code).
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    14
 *
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    18
 *
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    21
 * questions.
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    22
 */
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    23
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    24
/*
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    25
 * @test
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    26
 * @bug 8049021
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    27
 * @summary Test if we can write new provider for smart card
44108
8de4ce18c36f 8167525: update jdk tests to remove @compile --add-modules workaround
amlu
parents: 40261
diff changeset
    28
 * @run main/othervm/java.security.policy=policy TerminalFactorySpiTest
28260
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    29
 */
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    30
import java.security.Provider;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    31
import java.security.Security;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    32
import java.util.Arrays;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    33
import javax.smartcardio.CardTerminals;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    34
import javax.smartcardio.TerminalFactory;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    35
import javax.smartcardio.TerminalFactorySpi;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    36
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    37
public class TerminalFactorySpiTest {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    38
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    39
    static boolean callMethod = false;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    40
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    42
        Provider myProvider = new MyProvider();
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    43
        Security.addProvider(myProvider);
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    44
        System.out.println(Arrays.asList(Security.getProviders()));
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    45
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    46
        TerminalFactory.getInstance("MyType", new Object()).terminals();
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    47
        if (!callMethod) {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    48
            throw new RuntimeException("Expected engineTerminals() not called");
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    49
        }
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    50
    }
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    51
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    52
    public static class MyProvider extends Provider {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    53
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    54
        MyProvider() {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    55
            super("MyProvider", 1.0d, "smart Card Example");
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    56
            put("TerminalFactory.MyType", "TerminalFactorySpiTest$MyTerminalFactorySpi");
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    57
        }
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    58
    }
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    59
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    60
    public static class MyTerminalFactorySpi extends TerminalFactorySpi {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    61
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    62
        public MyTerminalFactorySpi(Object ob) {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    63
        }
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    64
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    65
        protected CardTerminals engineTerminals() {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    66
            System.out.println("MyTerminalFactory.engineTerminals()");
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    67
            callMethod = true;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    68
            return null;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    69
        }
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    70
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    71
    }
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    72
}