jdk/test/tools/launcher/MiscTests.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8783 2ea9207f2fad
child 11687 f13cadbb0bb5
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5982
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8783
diff changeset
     2
 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
5982
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     4
 *
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     8
 *
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    13
 * accompanied this code).
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    14
 *
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    18
 *
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    21
 * questions.
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    22
 */
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    23
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    24
/*
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    25
 * @test
8783
2ea9207f2fad 7027288: (launcher) remove jkernel test from MiscTests
ksrini
parents: 6522
diff changeset
    26
 * @bug 6856415
2ea9207f2fad 7027288: (launcher) remove jkernel test from MiscTests
ksrini
parents: 6522
diff changeset
    27
 * @summary Miscellaneous tests, Exceptions
6522
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    28
 * @compile -XDignore.symbol.file MiscTests.java TestHelper.java
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    29
 * @run main MiscTests
5982
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    30
 */
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    31
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    32
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    33
import java.io.File;
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    34
import java.io.FileNotFoundException;
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    35
6522
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    36
public class MiscTests {
5982
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    37
6522
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    38
    // 6856415: Checks to ensure that proper exceptions are thrown by java
5982
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    39
    static void test6856415() {
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    40
        // No pkcs library on win-x64, so we bail out.
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    41
        if (TestHelper.is64Bit && TestHelper.isWindows) {
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    42
            return;
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    43
        }
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    44
        StringBuilder sb = new StringBuilder();
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    45
        sb.append("public static void main(String... args) {\n");
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    46
        sb.append("java.security.Provider p = new sun.security.pkcs11.SunPKCS11(args[0]);\n");
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    47
        sb.append("java.security.Security.insertProviderAt(p, 1);\n");
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    48
        sb.append("}");
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    49
        File testJar = new File("Foo.jar");
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    50
        testJar.delete();
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    51
        try {
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    52
            TestHelper.createJar(testJar, sb.toString());
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    53
        } catch (FileNotFoundException fnfe) {
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    54
            throw new RuntimeException(fnfe);
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    55
        }
6522
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    56
        TestHelper.TestResult tr = TestHelper.doExec(TestHelper.javaCmd,
5982
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    57
                "-Djava.security.manager", "-jar", testJar.getName(), "foo.bak");
6522
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    58
        for (String s : tr.testOutput) {
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    59
            System.out.println(s);
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    60
    }
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    61
        if (!tr.contains("java.security.AccessControlException:" +
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    62
                " access denied (\"java.lang.RuntimePermission\"" +
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    63
                " \"accessClassInPackage.sun.security.pkcs11\")")) {
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    64
            System.out.println(tr.status);
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    65
        }
5982
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    66
    }
8783
2ea9207f2fad 7027288: (launcher) remove jkernel test from MiscTests
ksrini
parents: 6522
diff changeset
    67
5982
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    68
    public static void main(String... args) {
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    69
        test6856415();
6522
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    70
        if (TestHelper.testExitValue != 0) {
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    71
            throw new Error(TestHelper.testExitValue + " tests failed");
5982
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    72
    }
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    73
}
6522
1e468849b92c 6981001: (launcher) EnsureJREInstallation is not being called in order
ksrini
parents: 5982
diff changeset
    74
}