jdk/test/javax/smartcardio/TerminalFactorySpiTest.java
author vromero
Thu, 05 Jan 2017 11:16:39 -0800
changeset 43033 c37b643739a7
parent 40261 86a49ba76f52
child 44108 8de4ce18c36f
permissions -rw-r--r--
8148100: Convert lambda most specific positive tests to check runtime behavior Reviewed-by: mcimadamore Contributed-by: bsrbnd@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28260
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     1
/*
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
     2
 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
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
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 39041
diff changeset
    28
 * @compile --add-modules=java.smartcardio TerminalFactorySpiTest.java
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 39041
diff changeset
    29
 * @run main/othervm/java.security.policy=policy --add-modules=java.smartcardio TerminalFactorySpiTest
28260
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    30
 */
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    31
import java.security.Provider;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    32
import java.security.Security;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    33
import java.util.Arrays;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    34
import javax.smartcardio.CardTerminals;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    35
import javax.smartcardio.TerminalFactory;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    36
import javax.smartcardio.TerminalFactorySpi;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    37
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    38
public class TerminalFactorySpiTest {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    39
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    40
    static boolean callMethod = false;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    41
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    42
    public static void main(String[] args) throws Exception {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    43
        Provider myProvider = new MyProvider();
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    44
        Security.addProvider(myProvider);
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    45
        System.out.println(Arrays.asList(Security.getProviders()));
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    46
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    47
        TerminalFactory.getInstance("MyType", new Object()).terminals();
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    48
        if (!callMethod) {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    49
            throw new RuntimeException("Expected engineTerminals() not called");
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
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    53
    public static class MyProvider extends Provider {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    54
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    55
        MyProvider() {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    56
            super("MyProvider", 1.0d, "smart Card Example");
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    57
            put("TerminalFactory.MyType", "TerminalFactorySpiTest$MyTerminalFactorySpi");
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
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    61
    public static class MyTerminalFactorySpi extends TerminalFactorySpi {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    62
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    63
        public MyTerminalFactorySpi(Object ob) {
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
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    66
        protected CardTerminals engineTerminals() {
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    67
            System.out.println("MyTerminalFactory.engineTerminals()");
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    68
            callMethod = true;
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    69
            return null;
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
    }
b826987f5179 8049021: Add smartcardio tests with APDU buffer
valeriep
parents:
diff changeset
    73
}