You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/07/10 16:54:00 UTC

[2/6] incubator-tinkerpop git commit: Break out sandboxed scriptengine tests to their own case.

Break out sandboxed scriptengine tests to their own case.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/927b5ef4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/927b5ef4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/927b5ef4

Branch: refs/heads/compiler-customizer
Commit: 927b5ef4966bec02e65a8fec6698ce094d05764b
Parents: c47426d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jul 10 07:43:05 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Jul 10 07:43:05 2015 -0400

----------------------------------------------------------------------
 .../gremlin/groovy/GroovyEnvironmentSuite.java  |   7 +-
 .../GremlinGroovyScriptEngineOverGraphTest.java | 136 -------------------
 ...GroovyScriptEngineSandboxedStandardTest.java | 131 ++++++++++++++++++
 3 files changed, 133 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/927b5ef4/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentSuite.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentSuite.java
index 4a775f4..c553542 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentSuite.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/GroovyEnvironmentSuite.java
@@ -23,6 +23,7 @@ import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
 import org.apache.tinkerpop.gremlin.GraphManager;
 import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutorOverGraphTest;
 import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineOverGraphTest;
+import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineSandboxedStandardTest;
 import org.apache.tinkerpop.gremlin.groovy.loaders.SugarLoader;
 import org.apache.tinkerpop.gremlin.groovy.loaders.SugarLoaderTest;
 import org.apache.tinkerpop.gremlin.groovy.util.SugarTestHelper;
@@ -32,11 +33,6 @@ import org.apache.tinkerpop.gremlin.structure.StructureStandardSuite;
 import org.junit.runners.model.InitializationError;
 import org.junit.runners.model.RunnerBuilder;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
 /**
  * The {@code GroovyEnvironmentSuite} is a JUnit test runner that executes the Gremlin Test Suite over a
  * {@link Graph} implementation.  This test suite covers ensures that a vendor implementation is compliant with
@@ -55,6 +51,7 @@ public class GroovyEnvironmentSuite extends AbstractGremlinSuite {
      */
     private static final Class<?>[] allTests = new Class<?>[]{
             GremlinGroovyScriptEngineOverGraphTest.class,
+            GremlinGroovyScriptEngineSandboxedStandardTest.class,
             GremlinExecutorOverGraphTest.class,
             SugarLoaderTest.class,
     };

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/927b5ef4/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
index c72bfd5..a8899c7 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java
@@ -239,142 +239,6 @@ public class GremlinGroovyScriptEngineOverGraphTest extends AbstractGremlinTest
 
     @Test
     @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
-    public void shouldEvalGraphTraversalSourceWithTypeChecked() throws Exception {
-        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
-            final Bindings bindings = engine.createBindings();
-            bindings.put("g", g);
-            assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
-        }
-
-        final TypeCheckedCustomizerProvider providerNoExtension = new TypeCheckedCustomizerProvider();
-        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerNoExtension)) {
-            final Bindings bindings = engine.createBindings();
-            bindings.put("g", g);
-            engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings);
-            fail("Type checking should have forced an error as 'g' is not defined");
-        } catch (Exception ex) {
-            assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
-            assertThat(ex.getMessage(), containsString("The variable [g] is undeclared."));
-        }
-
-        final TypeCheckedCustomizerProvider providerWithExtension = new TypeCheckedCustomizerProvider(
-                SandboxExtension.class.getName());
-        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerWithExtension)) {
-            final Bindings bindings = engine.createBindings();
-            bindings.put("g", g);
-            assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
-            assertEquals(g.V(convertToVertexId("marko")).out("created").count().next(), engine.eval("g.V(" + convertToVertexId("marko") + ").out(\"created\").count().next()", bindings));
-        }
-    }
-
-    @Test
-    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
-    public void shouldEvalGraphWithTypeChecked() throws Exception {
-        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
-            final Bindings bindings = engine.createBindings();
-            bindings.put("graph", graph);
-            assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
-        }
-
-        final TypeCheckedCustomizerProvider providerNoExtension = new TypeCheckedCustomizerProvider();
-        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerNoExtension)) {
-            final Bindings bindings = engine.createBindings();
-            bindings.put("graph", graph);
-            assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
-            fail("Type checking should have forced an error as 'graph' is not defined");
-        } catch (Exception ex) {
-            assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
-            assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared."));
-        }
-
-        final TypeCheckedCustomizerProvider providerWithExtension = new TypeCheckedCustomizerProvider(
-                SandboxExtension.class.getName());
-        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerWithExtension)) {
-            final Bindings bindings = engine.createBindings();
-            bindings.put("graph", graph);
-            assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
-        }
-    }
-
-    @Test
-    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
-    public void shouldEvalGraphTraversalSourceWithCompileStatic() throws Exception {
-        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
-            final Bindings bindings = engine.createBindings();
-            bindings.put("g", g);
-            assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
-        }
-
-        final CompileStaticCustomizerProvider providerNoExtension = new CompileStaticCustomizerProvider();
-        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerNoExtension)) {
-            final Bindings bindings = engine.createBindings();
-            bindings.put("g", g);
-            engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings);
-            fail("Type checking should have forced an error as 'g' is not defined");
-        } catch (Exception ex) {
-            assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
-            assertThat(ex.getMessage(), containsString("The variable [g] is undeclared."));
-        }
-
-        final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider(
-                SandboxExtension.class.getName());
-        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerWithExtension)) {
-            final Bindings bindings = engine.createBindings();
-            bindings.put("g", g);
-            assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
-            assertEquals(g.V(convertToVertexId("marko")).out("created").count().next(), engine.eval("g.V(" + convertToVertexId("marko") + ").out(\"created\").count().next()", bindings));
-        }
-    }
-
-    @Test
-    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
-    public void shouldEvalGraphWithCompileStatic() throws Exception {
-        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
-            final Bindings bindings = engine.createBindings();
-            bindings.put("graph", graph);
-            assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
-        }
-
-        final CompileStaticCustomizerProvider providerNoExtension = new CompileStaticCustomizerProvider();
-        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerNoExtension)) {
-            final Bindings bindings = engine.createBindings();
-            bindings.put("graph", graph);
-            assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
-            fail("Type checking should have forced an error as 'graph' is not defined");
-        } catch (Exception ex) {
-            assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
-            assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared."));
-        }
-
-        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerNoExtension)) {
-            final Bindings bindings = engine.createBindings();
-            bindings.put("graph", graph);
-            bindings.put("x", convertToVertexId("marko"));
-            assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(x).next()", bindings));
-            fail("Type checking should have forced an error as 'graph' is not defined");
-        } catch (Exception ex) {
-            assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
-            assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared."));
-        }
-
-        final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider(
-                SandboxExtension.class.getName());
-        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerWithExtension)) {
-            final Bindings bindings = engine.createBindings();
-            bindings.put("graph", graph);
-            assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
-        }
-
-        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(providerWithExtension)) {
-            final Bindings bindings = engine.createBindings();
-            bindings.put("graph", graph);
-            bindings.put("x", convertToVertexId("marko"));
-            assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(x).next()", bindings));
-        }
-    }
-
-    @Test
-    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
     public void shouldEvalGlobalClosuresEvenAfterEvictionOfClass() throws ScriptException {
         final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/927b5ef4/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java
new file mode 100644
index 0000000..7f55e78
--- /dev/null
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.groovy.jsr223;
+
+import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
+import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.groovy.CompileStaticCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider;
+import org.apache.tinkerpop.gremlin.groovy.TypeCheckedCustomizerProvider;
+import org.codehaus.groovy.control.MultipleCompilationErrorsException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import javax.script.Bindings;
+
+import java.util.Arrays;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+@RunWith(Parameterized.class)
+public class GremlinGroovyScriptEngineSandboxedStandardTest extends AbstractGremlinTest {
+    @Parameterized.Parameters(name = "{0}")
+    public static Iterable<Object[]> data() {
+        return Arrays.asList(new Object[][]{
+                {TypeCheckedCustomizerProvider.class.getSimpleName(), new TypeCheckedCustomizerProvider(), new TypeCheckedCustomizerProvider(SandboxExtension.class.getName())},
+                {CompileStaticCustomizerProvider.class.getSimpleName(), new CompileStaticCustomizerProvider(), new CompileStaticCustomizerProvider(SandboxExtension.class.getName())}});
+    }
+
+    @Parameterized.Parameter(value = 0)
+    public String name;
+
+    @Parameterized.Parameter(value = 1)
+    public CompilerCustomizerProvider notSandboxed;
+
+    @Parameterized.Parameter(value = 2)
+    public CompilerCustomizerProvider sandboxed;
+
+    @Test
+    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+    public void shouldEvalGraphTraversalSource() throws Exception {
+        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
+            final Bindings bindings = engine.createBindings();
+            bindings.put("g", g);
+            assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
+        }
+
+        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(notSandboxed)) {
+            final Bindings bindings = engine.createBindings();
+            bindings.put("g", g);
+            engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings);
+            fail("Type checking should have forced an error as 'g' is not defined");
+        } catch (Exception ex) {
+            assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
+            assertThat(ex.getMessage(), containsString("The variable [g] is undeclared."));
+        }
+
+        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(sandboxed)) {
+            final Bindings bindings = engine.createBindings();
+            bindings.put("g", g);
+            assertEquals(g.V(convertToVertexId("marko")).next(), engine.eval("g.V(" + convertToVertexId("marko") + ").next()", bindings));
+            assertEquals(g.V(convertToVertexId("marko")).out("created").count().next(), engine.eval("g.V(" + convertToVertexId("marko") + ").out(\"created\").count().next()", bindings));
+        }
+    }
+
+    @Test
+    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+    public void shouldEvalGraph() throws Exception {
+        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine()) {
+            final Bindings bindings = engine.createBindings();
+            bindings.put("graph", graph);
+            assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
+        }
+
+        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(notSandboxed)) {
+            final Bindings bindings = engine.createBindings();
+            bindings.put("graph", graph);
+            assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
+            fail("Type checking should have forced an error as 'graph' is not defined");
+        } catch (Exception ex) {
+            assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
+            assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared."));
+        }
+
+        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(notSandboxed)) {
+            final Bindings bindings = engine.createBindings();
+            bindings.put("graph", graph);
+            bindings.put("x", convertToVertexId("marko"));
+            assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(x).next()", bindings));
+            fail("Type checking should have forced an error as 'graph' is not defined");
+        } catch (Exception ex) {
+            assertEquals(MultipleCompilationErrorsException.class, ex.getCause().getClass());
+            assertThat(ex.getMessage(), containsString("The variable [graph] is undeclared."));
+        }
+
+        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(sandboxed)) {
+            final Bindings bindings = engine.createBindings();
+            bindings.put("graph", graph);
+            assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(" + convertToVertexId("marko") + ").next()", bindings));
+        }
+
+        try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(sandboxed)) {
+            final Bindings bindings = engine.createBindings();
+            bindings.put("graph", graph);
+            bindings.put("x", convertToVertexId("marko"));
+            assertEquals(graph.vertices(convertToVertexId("marko")).next(), engine.eval("graph.vertices(x).next()", bindings));
+        }
+    }
+}