Author: sebb
Date: Wed Mar 25 02:27:59 2009
New Revision: 758131

URL: http://svn.apache.org/viewvc?rev=758131&view=rev
Log:
Add rudimentary JUnit scripting engine and tests

Added:
    
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/ScriptEngineManagerTest.java
   (with props)
    jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/
    
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngine.java
   (with props)
    
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngineFactory.java
   (with props)
Modified:
    
jakarta/bsf/trunk/bsf3/bsf-engines/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory

Added: 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/ScriptEngineManagerTest.java
URL: 
http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/ScriptEngineManagerTest.java?rev=758131&view=auto
==============================================================================
--- 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/ScriptEngineManagerTest.java
 (added)
+++ 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/ScriptEngineManagerTest.java
 Wed Mar 25 02:27:59 2009
@@ -0,0 +1,114 @@
+/*
+ * 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.bsf;
+
+import java.util.List;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+
+import org.apache.bsf.utils.TestScriptEngine;
+import org.apache.bsf.utils.TestScriptEngineFactory;
+
+import junit.framework.TestCase;
+
+public class ScriptEngineManagerTest extends TestCase {
+       private ScriptEngineManager mgr = null;
+       
+       public ScriptEngineManagerTest() {
+               super("ScriptEngineManagerTest");
+       }
+       
+       protected void setUp() throws Exception {
+               super.setUp();
+               mgr = new ScriptEngineManager();
+       }
+
+       public void testScriptEngineManager() {
+               assertNotNull(mgr);
+               List facs = mgr.getEngineFactories();
+               assertNotNull(facs);
+               assertTrue(facs.size() > 0); // need at least one
+       }
+
+       public void testGet() {
+               mgr.put("x", new Integer(1));
+               Object retValue = mgr.get("x");
+               assertEquals(new Integer(1), retValue);
+       }
+
+       public void testGetEngineByExtension() {
+               ScriptEngine engine;
+               
+               engine =  mgr.getEngineByExtension("tEst");
+               assertTrue(engine instanceof TestScriptEngine);
+               
+               engine = mgr.getEngineByExtension("teSt");
+               assertTrue(engine instanceof TestScriptEngine);
+       }
+
+       public void testGetEngineByMimeType() {
+       }
+
+       public void testGetEngineByName() {
+               ScriptEngine engine;
+               
+               engine =  mgr.getEngineByName("TestScript");
+               assertNotNull(engine);
+               assertTrue(engine instanceof TestScriptEngine);
+       }
+
+       public void testGetEngineFactories() {
+               boolean found = false;
+               List factories = mgr.getEngineFactories();
+               
+               for(int i = 0; i < factories.size(); i++) {
+                       if (factories.get(i) instanceof 
TestScriptEngineFactory) {
+                               found = true;
+                               break;
+                       }
+               }
+               
+               if (!found) {
+                       fail("ScriptEngineManager.getEngineFactories(): " +
+                                       "TestScriptEngineFactory is not present 
..");
+               }
+       }
+
+       public void testPut() {
+               //TODO Implement put().
+       }
+
+       public void testRegisterEngineExtension() {
+               //TODO Implement registerEngineExtension().
+       }
+
+       public void testRegisterEngineName() {
+               //TODO Implement registerEngineName().
+       }
+
+       public void testRegisterEngineMimeType() {
+               //TODO Implement registerEngineMimeType().
+       }
+
+       public void testSetNamespace() {
+               //TODO Implement setNamespace().
+       }
+
+}

Propchange: 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/ScriptEngineManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/ScriptEngineManagerTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngine.java
URL: 
http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngine.java?rev=758131&view=auto
==============================================================================
--- 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngine.java
 (added)
+++ 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngine.java
 Wed Mar 25 02:27:59 2009
@@ -0,0 +1,53 @@
+/*
+ * 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.bsf.utils;
+
+import java.io.Reader;
+import java.io.StringReader;
+
+import javax.script.AbstractScriptEngine;
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptException;
+
+public class TestScriptEngine extends AbstractScriptEngine {
+
+    public Bindings createBindings() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Object eval(Reader reader, ScriptContext context)
+            throws ScriptException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Object eval(String script, ScriptContext context)
+            throws ScriptException {
+        return eval(new StringReader(script), context);
+    }
+
+    public ScriptEngineFactory getFactory() {
+        return new TestScriptEngineFactory();
+    }
+
+}

Propchange: 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngine.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngine.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngineFactory.java
URL: 
http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngineFactory.java?rev=758131&view=auto
==============================================================================
--- 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngineFactory.java
 (added)
+++ 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngineFactory.java
 Wed Mar 25 02:27:59 2009
@@ -0,0 +1,90 @@
+/*
+ * 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.bsf.utils;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+
+
+public class TestScriptEngineFactory implements ScriptEngineFactory {
+       
+
+       public ScriptEngine getScriptEngine() {
+               return new TestScriptEngine();
+       }
+       
+       public String getEngineName() {
+               return "TestScriptEngine";
+       }
+       public String getEngineVersion() {
+               return "1.0";
+       }
+       public List getExtensions() {
+               return Collections.unmodifiableList(Arrays.asList(new 
String[]{"tEst","teSt"}));
+       }
+       public String getLanguageName() {
+               return "TestScript";
+       }
+       public String getLanguageVersion() {
+               return "1.0";
+       }
+       public List getMimeTypes() {
+               return Collections.unmodifiableList(Arrays.asList(new 
String[]{}));
+       }
+       
+       public Object getParameter(String key) {
+        if (key == ScriptEngine.ENGINE) {
+            return getEngineName();
+        } else if (key == ScriptEngine.ENGINE_VERSION) {
+            return getEngineVersion();
+        } else if (key == ScriptEngine.NAME) {
+            return "JUnit";
+        } else if (key == ScriptEngine.LANGUAGE) {
+            return getLanguageName();
+        } else if(key == ScriptEngine.ENGINE_VERSION) {
+            return getLanguageVersion();
+        } else if (key == "THREADING") {
+               return "MULTITHREADED"; 
+        } 
+        return null;
+       }
+
+    public String getMethodCallSyntax(String obj, String method, String[] 
args) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public List getNames() {
+        return Collections.unmodifiableList(Arrays.asList(new 
String[]{getLanguageName()}));
+    }
+
+    public String getOutputStatement(String toDisplay) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public String getProgram(String[] statements) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}

Propchange: 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngineFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngineFactory.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: 
jakarta/bsf/trunk/bsf3/bsf-engines/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory
URL: 
http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-engines/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory?rev=758131&r1=758130&r2=758131&view=diff
==============================================================================
--- 
jakarta/bsf/trunk/bsf3/bsf-engines/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory
 (original)
+++ 
jakarta/bsf/trunk/bsf3/bsf-engines/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory
 Wed Mar 25 02:27:59 2009
@@ -20,5 +20,5 @@
 com.sun.script.velocity.VelocityScriptEngineFactory
 com.sun.script.xpath.XPathScriptEngineFactory
 com.sun.script.xslt.XSLTScriptEngineFactory
-
+org.apache.bsf.utils.TestScriptEngineFactory
 



---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-dev-unsubscr...@jakarta.apache.org
For additional commands, e-mail: bsf-dev-h...@jakarta.apache.org

Reply via email to