8008729: Make sure that we can run basic jsr223 tests using jtreg

Fri, 22 Feb 2013 22:39:23 +0530

author
sundar
date
Fri, 22 Feb 2013 22:39:23 +0530
changeset 116
7f5b7c6859d7
parent 115
e42fd1640ff9
child 117
5452f82eb2ce

8008729: Make sure that we can run basic jsr223 tests using jtreg
Reviewed-by: jlaskey, hannesw, lagergren

test/TEST.ROOT file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/api/scripting/MultipleEngineTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/api/scripting/ScriptEngineSecurityTest.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java file | annotate | diff | comparison | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/TEST.ROOT	Fri Feb 22 22:39:23 2013 +0530
     1.3 @@ -0,0 +1,7 @@
     1.4 +# This file identifies the root of the test-suite hierarchy.
     1.5 +# It also contains test-suite configuration information.
     1.6 +# DO NOT EDIT without first contacting jdk-regtest@sun.com.
     1.7 +
     1.8 +# The list of keywords supported in the entire test suite
     1.9 +keys=2d dnd i18n
    1.10 +
     2.1 --- a/test/src/jdk/nashorn/api/scripting/MultipleEngineTest.java	Fri Feb 22 17:00:22 2013 +0100
     2.2 +++ b/test/src/jdk/nashorn/api/scripting/MultipleEngineTest.java	Fri Feb 22 22:39:23 2013 +0530
     2.3 @@ -33,6 +33,9 @@
     2.4  /**
     2.5   * Test that we can create multiple, independent script engines and use those
     2.6   * independently.
     2.7 + *
     2.8 + * @test
     2.9 + * @run testng jdk.nashorn.api.scripting.MultipleEngineTest
    2.10   */
    2.11  
    2.12  public class MultipleEngineTest {
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/src/jdk/nashorn/api/scripting/ScriptEngineSecurityTest.java	Fri Feb 22 22:39:23 2013 +0530
     3.3 @@ -0,0 +1,142 @@
     3.4 +/*
     3.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.  Oracle designates this
    3.11 + * particular file as subject to the "Classpath" exception as provided
    3.12 + * by Oracle in the LICENSE file that accompanied this code.
    3.13 + *
    3.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.17 + * version 2 for more details (a copy is included in the LICENSE file that
    3.18 + * accompanied this code).
    3.19 + *
    3.20 + * You should have received a copy of the GNU General Public License version
    3.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.23 + *
    3.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.25 + * or visit www.oracle.com if you need additional information or have any
    3.26 + * questions.
    3.27 + */
    3.28 +
    3.29 +package jdk.nashorn.api.scripting;
    3.30 +
    3.31 +import static org.testng.Assert.fail;
    3.32 +
    3.33 +import javax.script.ScriptEngine;
    3.34 +import javax.script.ScriptEngineManager;
    3.35 +import org.testng.annotations.Test;
    3.36 +
    3.37 +/**
    3.38 + * jsr223 tests for security access checks.
    3.39 + */
    3.40 +public class ScriptEngineSecurityTest {
    3.41 +
    3.42 +    private void log(String msg) {
    3.43 +        org.testng.Reporter.log(msg, true);
    3.44 +    }
    3.45 +
    3.46 +    @Test
    3.47 +    public void securityPackagesTest() {
    3.48 +        if (System.getSecurityManager() == null) {
    3.49 +            // pass vacuously
    3.50 +        }
    3.51 +
    3.52 +        final ScriptEngineManager m = new ScriptEngineManager();
    3.53 +        final ScriptEngine e = m.getEngineByName("nashorn");
    3.54 +        try {
    3.55 +            e.eval("var v = Packages.sun.misc.Unsafe;");
    3.56 +            fail("should have thrown SecurityException");
    3.57 +        } catch (final Exception exp) {
    3.58 +            if (exp instanceof SecurityException) {
    3.59 +                log("got " + exp + " as expected");
    3.60 +            } else {
    3.61 +                fail(exp.getMessage());
    3.62 +            }
    3.63 +        }
    3.64 +    }
    3.65 +
    3.66 +    @Test
    3.67 +    public void securityJavaTypeTest() {
    3.68 +        if (System.getSecurityManager() == null) {
    3.69 +            // pass vacuously
    3.70 +        }
    3.71 +
    3.72 +        final ScriptEngineManager m = new ScriptEngineManager();
    3.73 +        final ScriptEngine e = m.getEngineByName("nashorn");
    3.74 +        try {
    3.75 +            e.eval("var v = Java.type('sun.misc.Unsafe');");
    3.76 +            fail("should have thrown SecurityException");
    3.77 +        } catch (final Exception exp) {
    3.78 +            if (exp instanceof SecurityException) {
    3.79 +                log("got " + exp + " as expected");
    3.80 +            } else {
    3.81 +                fail(exp.getMessage());
    3.82 +            }
    3.83 +        }
    3.84 +    }
    3.85 +
    3.86 +    @Test
    3.87 +    public void securityClassForNameTest() {
    3.88 +        if (System.getSecurityManager() == null) {
    3.89 +            // pass vacuously
    3.90 +        }
    3.91 +
    3.92 +        final ScriptEngineManager m = new ScriptEngineManager();
    3.93 +        final ScriptEngine e = m.getEngineByName("nashorn");
    3.94 +        try {
    3.95 +            e.eval("var v = java.lang.Class.forName('sun.misc.Unsafe');");
    3.96 +            fail("should have thrown SecurityException");
    3.97 +        } catch (final Exception exp) {
    3.98 +            if (exp instanceof SecurityException) {
    3.99 +                log("got " + exp + " as expected");
   3.100 +            } else {
   3.101 +                fail(exp.getMessage());
   3.102 +            }
   3.103 +        }
   3.104 +    }
   3.105 +
   3.106 +    @Test
   3.107 +    public void securitySystemExit() {
   3.108 +        if (System.getSecurityManager() == null) {
   3.109 +            // pass vacuously
   3.110 +        }
   3.111 +
   3.112 +        final ScriptEngineManager m = new ScriptEngineManager();
   3.113 +        final ScriptEngine e = m.getEngineByName("nashorn");
   3.114 +        try {
   3.115 +            e.eval("java.lang.System.exit(0);");
   3.116 +            fail("should have thrown SecurityException");
   3.117 +        } catch (final Exception exp) {
   3.118 +            if (exp instanceof SecurityException) {
   3.119 +                log("got " + exp + " as expected");
   3.120 +            } else {
   3.121 +                fail(exp.getMessage());
   3.122 +            }
   3.123 +        }
   3.124 +    }
   3.125 +
   3.126 +    @Test
   3.127 +    public void securitySystemLoadLibrary() {
   3.128 +        if (System.getSecurityManager() == null) {
   3.129 +            // pass vacuously
   3.130 +        }
   3.131 +
   3.132 +        final ScriptEngineManager m = new ScriptEngineManager();
   3.133 +        final ScriptEngine e = m.getEngineByName("nashorn");
   3.134 +        try {
   3.135 +            e.eval("java.lang.System.loadLibrary('foo');");
   3.136 +            fail("should have thrown SecurityException");
   3.137 +        } catch (final Exception exp) {
   3.138 +            if (exp instanceof SecurityException) {
   3.139 +                log("got " + exp + " as expected");
   3.140 +            } else {
   3.141 +                fail(exp.getMessage());
   3.142 +            }
   3.143 +        }
   3.144 +    }
   3.145 +}
     4.1 --- a/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Fri Feb 22 17:00:22 2013 +0100
     4.2 +++ b/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Fri Feb 22 22:39:23 2013 +0530
     4.3 @@ -54,6 +54,10 @@
     4.4  
     4.5  /**
     4.6   * Tests for JSR-223 script engine for Nashorn.
     4.7 + *
     4.8 + * @test
     4.9 + * @build jdk.nashorn.api.scripting.Window jdk.nashorn.api.scripting.WindowEventHandler jdk.nashorn.api.scripting.ScriptEngineTest
    4.10 + * @run testng jdk.nashorn.api.scripting.ScriptEngineTest
    4.11   */
    4.12  public class ScriptEngineTest {
    4.13  
    4.14 @@ -656,106 +660,6 @@
    4.15      }
    4.16  
    4.17      @Test
    4.18 -    public void securityPackagesTest() {
    4.19 -        if (System.getSecurityManager() == null) {
    4.20 -            // pass vacuously
    4.21 -        }
    4.22 -
    4.23 -        final ScriptEngineManager m = new ScriptEngineManager();
    4.24 -        final ScriptEngine e = m.getEngineByName("nashorn");
    4.25 -        try {
    4.26 -            e.eval("var v = Packages.sun.misc.Unsafe;");
    4.27 -            fail("should have thrown SecurityException");
    4.28 -        } catch (final Exception exp) {
    4.29 -            if (exp instanceof SecurityException) {
    4.30 -                log("got " + exp + " as expected");
    4.31 -            } else {
    4.32 -                fail(exp.getMessage());
    4.33 -            }
    4.34 -        }
    4.35 -    }
    4.36 -
    4.37 -    @Test
    4.38 -    public void securityJavaTypeTest() {
    4.39 -        if (System.getSecurityManager() == null) {
    4.40 -            // pass vacuously
    4.41 -        }
    4.42 -
    4.43 -        final ScriptEngineManager m = new ScriptEngineManager();
    4.44 -        final ScriptEngine e = m.getEngineByName("nashorn");
    4.45 -        try {
    4.46 -            e.eval("var v = Java.type('sun.misc.Unsafe');");
    4.47 -            fail("should have thrown SecurityException");
    4.48 -        } catch (final Exception exp) {
    4.49 -            if (exp instanceof SecurityException) {
    4.50 -                log("got " + exp + " as expected");
    4.51 -            } else {
    4.52 -                fail(exp.getMessage());
    4.53 -            }
    4.54 -        }
    4.55 -    }
    4.56 -
    4.57 -    @Test
    4.58 -    public void securityClassForNameTest() {
    4.59 -        if (System.getSecurityManager() == null) {
    4.60 -            // pass vacuously
    4.61 -        }
    4.62 -
    4.63 -        final ScriptEngineManager m = new ScriptEngineManager();
    4.64 -        final ScriptEngine e = m.getEngineByName("nashorn");
    4.65 -        try {
    4.66 -            e.eval("var v = java.lang.Class.forName('sun.misc.Unsafe');");
    4.67 -            fail("should have thrown SecurityException");
    4.68 -        } catch (final Exception exp) {
    4.69 -            if (exp instanceof SecurityException) {
    4.70 -                log("got " + exp + " as expected");
    4.71 -            } else {
    4.72 -                fail(exp.getMessage());
    4.73 -            }
    4.74 -        }
    4.75 -    }
    4.76 -
    4.77 -    @Test
    4.78 -    public void securitySystemExit() {
    4.79 -        if (System.getSecurityManager() == null) {
    4.80 -            // pass vacuously
    4.81 -        }
    4.82 -
    4.83 -        final ScriptEngineManager m = new ScriptEngineManager();
    4.84 -        final ScriptEngine e = m.getEngineByName("nashorn");
    4.85 -        try {
    4.86 -            e.eval("java.lang.System.exit(0);");
    4.87 -            fail("should have thrown SecurityException");
    4.88 -        } catch (final Exception exp) {
    4.89 -            if (exp instanceof SecurityException) {
    4.90 -                log("got " + exp + " as expected");
    4.91 -            } else {
    4.92 -                fail(exp.getMessage());
    4.93 -            }
    4.94 -        }
    4.95 -    }
    4.96 -
    4.97 -    @Test
    4.98 -    public void securitySystemLoadLibrary() {
    4.99 -        if (System.getSecurityManager() == null) {
   4.100 -            // pass vacuously
   4.101 -        }
   4.102 -
   4.103 -        final ScriptEngineManager m = new ScriptEngineManager();
   4.104 -        final ScriptEngine e = m.getEngineByName("nashorn");
   4.105 -        try {
   4.106 -            e.eval("java.lang.System.loadLibrary('foo');");
   4.107 -            fail("should have thrown SecurityException");
   4.108 -        } catch (final Exception exp) {
   4.109 -            if (exp instanceof SecurityException) {
   4.110 -                log("got " + exp + " as expected");
   4.111 -            } else {
   4.112 -                fail(exp.getMessage());
   4.113 -            }
   4.114 -        }
   4.115 -    }
   4.116 -
   4.117 -    @Test
   4.118      public void jsobjectTest() {
   4.119          final ScriptEngineManager m = new ScriptEngineManager();
   4.120          final ScriptEngine e = m.getEngineByName("nashorn");

mercurial