changeset 16260:3318a14ac7cb

8008729: Make sure that we can run basic jsr223 tests using jtreg Reviewed-by: jlaskey, hannesw, lagergren
author sundar
date Fri, 22 Feb 2013 22:39:23 +0530
parents bb504280c322
children c37fd274b194
files nashorn/test/TEST.ROOT nashorn/test/src/jdk/nashorn/api/scripting/MultipleEngineTest.java nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineSecurityTest.java nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java
diffstat 4 files changed, 156 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/TEST.ROOT	Fri Feb 22 22:39:23 2013 +0530
@@ -0,0 +1,7 @@
+# This file identifies the root of the test-suite hierarchy.
+# It also contains test-suite configuration information.
+# DO NOT EDIT without first contacting jdk-regtest@sun.com.
+
+# The list of keywords supported in the entire test suite
+keys=2d dnd i18n
+
--- a/nashorn/test/src/jdk/nashorn/api/scripting/MultipleEngineTest.java	Fri Feb 22 17:00:22 2013 +0100
+++ b/nashorn/test/src/jdk/nashorn/api/scripting/MultipleEngineTest.java	Fri Feb 22 22:39:23 2013 +0530
@@ -33,6 +33,9 @@
 /**
  * Test that we can create multiple, independent script engines and use those
  * independently.
+ *
+ * @test
+ * @run testng jdk.nashorn.api.scripting.MultipleEngineTest
  */
 
 public class MultipleEngineTest {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineSecurityTest.java	Fri Feb 22 22:39:23 2013 +0530
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.nashorn.api.scripting;
+
+import static org.testng.Assert.fail;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import org.testng.annotations.Test;
+
+/**
+ * jsr223 tests for security access checks.
+ */
+public class ScriptEngineSecurityTest {
+
+    private void log(String msg) {
+        org.testng.Reporter.log(msg, true);
+    }
+
+    @Test
+    public void securityPackagesTest() {
+        if (System.getSecurityManager() == null) {
+            // pass vacuously
+        }
+
+        final ScriptEngineManager m = new ScriptEngineManager();
+        final ScriptEngine e = m.getEngineByName("nashorn");
+        try {
+            e.eval("var v = Packages.sun.misc.Unsafe;");
+            fail("should have thrown SecurityException");
+        } catch (final Exception exp) {
+            if (exp instanceof SecurityException) {
+                log("got " + exp + " as expected");
+            } else {
+                fail(exp.getMessage());
+            }
+        }
+    }
+
+    @Test
+    public void securityJavaTypeTest() {
+        if (System.getSecurityManager() == null) {
+            // pass vacuously
+        }
+
+        final ScriptEngineManager m = new ScriptEngineManager();
+        final ScriptEngine e = m.getEngineByName("nashorn");
+        try {
+            e.eval("var v = Java.type('sun.misc.Unsafe');");
+            fail("should have thrown SecurityException");
+        } catch (final Exception exp) {
+            if (exp instanceof SecurityException) {
+                log("got " + exp + " as expected");
+            } else {
+                fail(exp.getMessage());
+            }
+        }
+    }
+
+    @Test
+    public void securityClassForNameTest() {
+        if (System.getSecurityManager() == null) {
+            // pass vacuously
+        }
+
+        final ScriptEngineManager m = new ScriptEngineManager();
+        final ScriptEngine e = m.getEngineByName("nashorn");
+        try {
+            e.eval("var v = java.lang.Class.forName('sun.misc.Unsafe');");
+            fail("should have thrown SecurityException");
+        } catch (final Exception exp) {
+            if (exp instanceof SecurityException) {
+                log("got " + exp + " as expected");
+            } else {
+                fail(exp.getMessage());
+            }
+        }
+    }
+
+    @Test
+    public void securitySystemExit() {
+        if (System.getSecurityManager() == null) {
+            // pass vacuously
+        }
+
+        final ScriptEngineManager m = new ScriptEngineManager();
+        final ScriptEngine e = m.getEngineByName("nashorn");
+        try {
+            e.eval("java.lang.System.exit(0);");
+            fail("should have thrown SecurityException");
+        } catch (final Exception exp) {
+            if (exp instanceof SecurityException) {
+                log("got " + exp + " as expected");
+            } else {
+                fail(exp.getMessage());
+            }
+        }
+    }
+
+    @Test
+    public void securitySystemLoadLibrary() {
+        if (System.getSecurityManager() == null) {
+            // pass vacuously
+        }
+
+        final ScriptEngineManager m = new ScriptEngineManager();
+        final ScriptEngine e = m.getEngineByName("nashorn");
+        try {
+            e.eval("java.lang.System.loadLibrary('foo');");
+            fail("should have thrown SecurityException");
+        } catch (final Exception exp) {
+            if (exp instanceof SecurityException) {
+                log("got " + exp + " as expected");
+            } else {
+                fail(exp.getMessage());
+            }
+        }
+    }
+}
--- a/nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Fri Feb 22 17:00:22 2013 +0100
+++ b/nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Fri Feb 22 22:39:23 2013 +0530
@@ -54,6 +54,10 @@
 
 /**
  * Tests for JSR-223 script engine for Nashorn.
+ *
+ * @test
+ * @build jdk.nashorn.api.scripting.Window jdk.nashorn.api.scripting.WindowEventHandler jdk.nashorn.api.scripting.ScriptEngineTest
+ * @run testng jdk.nashorn.api.scripting.ScriptEngineTest
  */
 public class ScriptEngineTest {
 
@@ -656,106 +660,6 @@
     }
 
     @Test
-    public void securityPackagesTest() {
-        if (System.getSecurityManager() == null) {
-            // pass vacuously
-        }
-
-        final ScriptEngineManager m = new ScriptEngineManager();
-        final ScriptEngine e = m.getEngineByName("nashorn");
-        try {
-            e.eval("var v = Packages.sun.misc.Unsafe;");
-            fail("should have thrown SecurityException");
-        } catch (final Exception exp) {
-            if (exp instanceof SecurityException) {
-                log("got " + exp + " as expected");
-            } else {
-                fail(exp.getMessage());
-            }
-        }
-    }
-
-    @Test
-    public void securityJavaTypeTest() {
-        if (System.getSecurityManager() == null) {
-            // pass vacuously
-        }
-
-        final ScriptEngineManager m = new ScriptEngineManager();
-        final ScriptEngine e = m.getEngineByName("nashorn");
-        try {
-            e.eval("var v = Java.type('sun.misc.Unsafe');");
-            fail("should have thrown SecurityException");
-        } catch (final Exception exp) {
-            if (exp instanceof SecurityException) {
-                log("got " + exp + " as expected");
-            } else {
-                fail(exp.getMessage());
-            }
-        }
-    }
-
-    @Test
-    public void securityClassForNameTest() {
-        if (System.getSecurityManager() == null) {
-            // pass vacuously
-        }
-
-        final ScriptEngineManager m = new ScriptEngineManager();
-        final ScriptEngine e = m.getEngineByName("nashorn");
-        try {
-            e.eval("var v = java.lang.Class.forName('sun.misc.Unsafe');");
-            fail("should have thrown SecurityException");
-        } catch (final Exception exp) {
-            if (exp instanceof SecurityException) {
-                log("got " + exp + " as expected");
-            } else {
-                fail(exp.getMessage());
-            }
-        }
-    }
-
-    @Test
-    public void securitySystemExit() {
-        if (System.getSecurityManager() == null) {
-            // pass vacuously
-        }
-
-        final ScriptEngineManager m = new ScriptEngineManager();
-        final ScriptEngine e = m.getEngineByName("nashorn");
-        try {
-            e.eval("java.lang.System.exit(0);");
-            fail("should have thrown SecurityException");
-        } catch (final Exception exp) {
-            if (exp instanceof SecurityException) {
-                log("got " + exp + " as expected");
-            } else {
-                fail(exp.getMessage());
-            }
-        }
-    }
-
-    @Test
-    public void securitySystemLoadLibrary() {
-        if (System.getSecurityManager() == null) {
-            // pass vacuously
-        }
-
-        final ScriptEngineManager m = new ScriptEngineManager();
-        final ScriptEngine e = m.getEngineByName("nashorn");
-        try {
-            e.eval("java.lang.System.loadLibrary('foo');");
-            fail("should have thrown SecurityException");
-        } catch (final Exception exp) {
-            if (exp instanceof SecurityException) {
-                log("got " + exp + " as expected");
-            } else {
-                fail(exp.getMessage());
-            }
-        }
-    }
-
-    @Test
     public void jsobjectTest() {
         final ScriptEngineManager m = new ScriptEngineManager();
         final ScriptEngine e = m.getEngineByName("nashorn");