velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dish...@apache.org
Subject svn commit: r1358578 - in /velocity/sandbox/jsr223/velocity-engine-scripting/src: main/java/org/apache/velocity/script/ test/java/org/apache/velocity/script/test/
Date Sat, 07 Jul 2012 14:33:26 GMT
Author: dishara
Date: Sat Jul  7 14:33:25 2012
New Revision: 1358578

URL: http://svn.apache.org/viewvc?rev=1358578&view=rev
Log:
Added tests for JSR223 API coverage

Added:
    velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/ScriptEngineTest.java
    velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/VelocityScriptContextTest.java
Modified:
    velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptContext.java
    velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/AbstractScriptTest.java
    velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/ScriptEngineFactoryTest.java

Modified: velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptContext.java
URL: http://svn.apache.org/viewvc/velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptContext.java?rev=1358578&r1=1358577&r2=1358578&view=diff
==============================================================================
--- velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptContext.java
(original)
+++ velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptContext.java
Sat Jul  7 14:33:25 2012
@@ -107,7 +107,7 @@ public class VelocityScriptContext imple
          break;
 
          case GLOBAL_SCOPE:
-             globalScope=bindings;
+             globalScope = bindings;
          break;
 
          default:
@@ -242,7 +242,7 @@ public class VelocityScriptContext imple
          }
 
         if(engineScope.containsKey(s)) {
-         return getAttribute(s,ENGINE_SCOPE);
+           return getAttribute(s,ENGINE_SCOPE);
         } else if (globalScope != null && (globalScope.containsKey(s))) {
            return getAttribute(s,GLOBAL_SCOPE);
         }

Modified: velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/AbstractScriptTest.java
URL: http://svn.apache.org/viewvc/velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/AbstractScriptTest.java?rev=1358578&r1=1358577&r2=1358578&view=diff
==============================================================================
--- velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/AbstractScriptTest.java
(original)
+++ velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/AbstractScriptTest.java
Sat Jul  7 14:33:25 2012
@@ -3,10 +3,10 @@ package org.apache.velocity.script.test;
 
 import junit.framework.TestCase;
 import org.apache.velocity.script.VelocityScriptEngineFactory;
+
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineFactory;
 import javax.script.ScriptEngineManager;
-import javax.script.ScriptException;
 
 public abstract class AbstractScriptTest  extends TestCase {
     ScriptEngine engine;
@@ -15,7 +15,6 @@ public abstract class AbstractScriptTest
 
     @Override
     public void setUp() {
-        System.out.println("------- Velocity scripting test framework started --------");
         manager = new ScriptEngineManager();
     }
 
@@ -24,7 +23,7 @@ public abstract class AbstractScriptTest
         engine = manager.getEngineByName("velocity");
     }
 
-    public void setupFactory() {
+    public void setupWithDefaultFactory() {
         manager.registerEngineName("velocity", new VelocityScriptEngineFactory());
         engine = manager.getEngineByName("velocity");
         engineFactory = engine.getFactory();

Modified: velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/ScriptEngineFactoryTest.java
URL: http://svn.apache.org/viewvc/velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/ScriptEngineFactoryTest.java?rev=1358578&r1=1358577&r2=1358578&view=diff
==============================================================================
--- velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/ScriptEngineFactoryTest.java
(original)
+++ velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/ScriptEngineFactoryTest.java
Sat Jul  7 14:33:25 2012
@@ -30,10 +30,10 @@ public class ScriptEngineFactoryTest ext
 
     @Override
     public void setUp() {
+        System.out.println("------- Velocity scripting test framework started : ScriptEngineFactoryTest
--------");
         super.setUp();
         super.setupEngine(constructFactory());
     }
-
     @Test
     public void testCreateFactory() {
 
@@ -54,9 +54,9 @@ public class ScriptEngineFactoryTest ext
         assertEquals("test-language",factory.getLanguageName());
         assertEquals("2.0.0",factory.getLanguageVersion());
 
-
     }
 
+    @Test
     public void testParameters(){
 
         ScriptEngineFactory factory = engine.getFactory();

Added: velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/ScriptEngineTest.java
URL: http://svn.apache.org/viewvc/velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/ScriptEngineTest.java?rev=1358578&view=auto
==============================================================================
--- velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/ScriptEngineTest.java
(added)
+++ velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/ScriptEngineTest.java
Sat Jul  7 14:33:25 2012
@@ -0,0 +1,77 @@
+package org.apache.velocity.script.test;
+/*
+ * 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.
+ */
+
+import org.apache.velocity.script.VelocityScriptEngine;
+
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptException;
+
+public class ScriptEngineTest extends AbstractScriptTest {
+
+    @Override
+    public void setUp() {
+        System.out.println("------- Velocity scripting test framework started : VelocityScriptContextTest
--------");
+        super.setUp();
+        super.setupWithDefaultFactory();
+    }
+
+    public void testBasicOpe() {
+
+        engine.put("name1", "value1");
+        Bindings engineScope = engine.getContext().getBindings(ScriptContext.ENGINE_SCOPE);
+        assertEquals("Engine#put should have same effect as context.put ", engineScope.get("name1"),
"value1");
+
+        String val = engine.get("name1").toString();
+        assertEquals("Engine#get should have same effect as context.get ", engineScope.get("name1"),
val);
+
+
+    }
+
+
+    public void testJSR223tException(){
+       try {
+            engine.get("");
+            fail("Cannot pass empty name");
+        } catch (IllegalArgumentException n) {
+            //Success
+        }
+
+        try {
+             engine.setContext(null);
+             fail("Cannot pass null to context");
+         } catch (NullPointerException n) {
+             //Success
+         }
+
+    }
+
+    public void testEngineEvals() throws ScriptException {
+//        System.setProperty(VelocityScriptEngine.VELOCITY_PROPERTIES,  "../resources/velocity.properties")
;
+        //Comment test case
+//        Object result = engine.eval("## This is a comment ");
+//        assertTrue(Boolean.valueOf(result.toString()));
+
+    }
+
+
+
+
+}

Added: velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/VelocityScriptContextTest.java
URL: http://svn.apache.org/viewvc/velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/VelocityScriptContextTest.java?rev=1358578&view=auto
==============================================================================
--- velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/VelocityScriptContextTest.java
(added)
+++ velocity/sandbox/jsr223/velocity-engine-scripting/src/test/java/org/apache/velocity/script/test/VelocityScriptContextTest.java
Sat Jul  7 14:33:25 2012
@@ -0,0 +1,161 @@
+package org.apache.velocity.script.test;
+
+/*
+* 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.
+*/
+
+import org.apache.velocity.script.VelocityBindings;
+import javax.script.ScriptContext;
+import java.util.List;
+
+
+public class VelocityScriptContextTest extends AbstractScriptTest {
+
+    @Override
+    public void setUp() {
+        System.out.println("------- Velocity scripting test framework started : VelocityScriptContextTest
--------");
+        super.setUp();
+        super.setupWithDefaultFactory();
+    }
+
+    public void testInitialScopes() {
+        List<Integer> defaultScopes = engine.getContext().getScopes();
+        assertEquals(defaultScopes.size(), 2);
+        assertTrue(defaultScopes.contains(ScriptContext.ENGINE_SCOPE));
+        assertTrue(defaultScopes.contains(ScriptContext.GLOBAL_SCOPE));
+    }
+
+    public void testScopes() {
+
+        VelocityBindings velocityBindings = new VelocityBindings();
+        engine.getContext().setBindings(velocityBindings, ScriptContext.ENGINE_SCOPE);
+        assertNotNull(engine.getBindings(ScriptContext.ENGINE_SCOPE));
+        assertNotNull("Engines Registered through manager sets the global scope", engine.getBindings(ScriptContext.GLOBAL_SCOPE));
+    }
+
+    public void testEngineScopeAttributes() {
+
+        ScriptContext context = engine.getContext();
+        context.setAttribute("engine-prop1", "engine-value1", ScriptContext.ENGINE_SCOPE);
+
+        assertEquals(context.getAttribute("engine-prop1", ScriptContext.ENGINE_SCOPE), "engine-value1");
+        assertNull(context.getAttribute("engine-prop1", ScriptContext.GLOBAL_SCOPE));
+
+        context.removeAttribute("engine-prop1", ScriptContext.ENGINE_SCOPE);
+        assertNull(context.getAttribute("engine-prop1", ScriptContext.ENGINE_SCOPE));
+
+
+    }
+
+    public void testGlobalScopeAttributes() {
+
+        ScriptContext context = engine.getContext();
+        context.setAttribute("global-prop1", "global-value1", ScriptContext.GLOBAL_SCOPE);
+
+        assertEquals(context.getAttribute("global-prop1", ScriptContext.GLOBAL_SCOPE), "global-value1");
+        assertNull(context.getAttribute("global-prop1", ScriptContext.ENGINE_SCOPE));
+
+        context.removeAttribute("global-prop1", ScriptContext.GLOBAL_SCOPE);
+        assertNull(context.getAttribute("global-prop1", ScriptContext.GLOBAL_SCOPE));
+
+    }
+
+    public void testJSRExceptions() {
+
+        ScriptContext context = engine.getContext();
+        context.setAttribute("global-prop", "global-value", ScriptContext.GLOBAL_SCOPE);
+        int invalidScope = 99;
+
+        try {
+            context.setBindings(null, ScriptContext.ENGINE_SCOPE);
+            fail("Cannot pass null binding for engine scope");
+        } catch (NullPointerException n) {
+            //Success
+        }
+
+        try {
+            context.setBindings(new VelocityBindings(), invalidScope);
+            fail("Cannot pass invalid scope");
+        } catch (IllegalArgumentException n) {
+            //Success
+        }
+        try {
+            context.getBindings(invalidScope);
+            fail("Cannot pass invalid scope");
+        } catch (IllegalArgumentException n) {
+            //Success
+        }
+
+
+        try {
+            context.setAttribute(null, "value", ScriptContext.ENGINE_SCOPE);
+
+            fail("Name cannot be null");
+        } catch (NullPointerException n) {
+            //Success
+        }
+        try {
+            context.setAttribute("name1", "value", invalidScope);
+
+            fail("Cannot pass invalid scope");
+        } catch (IllegalArgumentException n) {
+            //Success
+        }
+
+
+
+        try {
+            context.getAttribute(null, ScriptContext.ENGINE_SCOPE);
+
+            fail("Name cannot be null");
+        } catch (NullPointerException n) {
+            //Success
+        }
+        try {
+            context.getAttribute("name1", invalidScope);
+
+            fail("Cannot pass invalid scope");
+        } catch (IllegalArgumentException n) {
+            //Success
+        }
+
+
+         try {
+            context.removeAttribute(null, ScriptContext.ENGINE_SCOPE);
+
+            fail("Name cannot be null");
+        } catch (NullPointerException n) {
+            //Success
+        }
+        try {
+            context.removeAttribute("name1", invalidScope);
+
+            fail("Cannot pass invalid scope");
+        } catch (IllegalArgumentException n) {
+            //Success
+        }
+
+
+        context.setAttribute("prop2","engine-value2",ScriptContext.ENGINE_SCOPE);
+        context.setAttribute("prop2","global-value2",ScriptContext.GLOBAL_SCOPE);
+        assertEquals("Should return lowest scope value binded value",context.getAttribute("prop2"),"engine-value2");
+
+    }
+}
+
+



Mime
View raw message