You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bsf-dev@jakarta.apache.org by se...@apache.org on 2009/03/25 21:21:10 UTC
svn commit: r758429 - in
/jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils:
TestCompiledScript.java TestScriptEngine.java
Author: sebb
Date: Wed Mar 25 20:21:05 2009
New Revision: 758429
URL: http://svn.apache.org/viewvc?rev=758429&view=rev
Log:
Support Compilable testing
Added:
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestCompiledScript.java (with props)
Modified:
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/TestCompiledScript.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestCompiledScript.java?rev=758429&view=auto
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestCompiledScript.java (added)
+++ jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestCompiledScript.java Wed Mar 25 20:21:05 2009
@@ -0,0 +1,47 @@
+/*
+ * 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 javax.script.CompiledScript;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+
+/**
+ * Minimal CompiledScript implementation.
+ */
+public class TestCompiledScript extends CompiledScript {
+
+ private final ScriptEngine engine;
+ private final String compiled;
+
+ public TestCompiledScript(TestScriptEngine testScriptEngine, String script) {
+ engine = testScriptEngine;
+ compiled = script;
+ }
+
+ public Object eval(ScriptContext context) throws ScriptException {
+ return compiled;
+ }
+
+ public ScriptEngine getEngine() {
+ return engine;
+ }
+
+}
Propchange: jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestCompiledScript.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestCompiledScript.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: 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=758429&r1=758428&r2=758429&view=diff
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngine.java (original)
+++ jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngine.java Wed Mar 25 20:21:05 2009
@@ -23,6 +23,9 @@
import javax.script.AbstractScriptEngine;
import javax.script.Bindings;
+import javax.script.Compilable;
+import javax.script.CompiledScript;
+import javax.script.Invocable;
import javax.script.ScriptContext;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptException;
@@ -31,7 +34,7 @@
/**
* Minimal Script engine used for JUnit tests.
*/
-public class TestScriptEngine extends AbstractScriptEngine {
+public class TestScriptEngine extends AbstractScriptEngine implements Compilable, Invocable {
public TestScriptEngine() {
super();
@@ -52,6 +55,15 @@
public Object eval(Reader reader, ScriptContext context)
throws ScriptException {
+ return eval(readerToString(reader), context);
+ }
+
+ /**
+ * @param reader
+ * @return
+ * @throws ScriptException
+ */
+ private String readerToString(Reader reader) throws ScriptException {
StringBuffer sb = new StringBuffer();
char cbuf[] = new char[1024];
try {
@@ -61,7 +73,7 @@
} catch (IOException e) {
throw new ScriptException(e);
}
- return eval(sb.toString(), context);
+ return sb.toString();
}
public Object eval(String script, ScriptContext context)
@@ -73,4 +85,39 @@
return new TestScriptEngineFactory();
}
+ // Compilable methods
+
+ public CompiledScript compile(String script) throws ScriptException {
+ return new TestCompiledScript(this, script);
+ }
+
+ public CompiledScript compile(Reader reader) throws ScriptException {
+ String script = readerToString(reader);
+ return new TestCompiledScript(this, script);
+ }
+
+ // Invokable methods
+
+ public Object getInterface(Class clasz) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getInterface(Object thiz, Class clasz) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object invokeFunction(String name, Object[] args)
+ throws ScriptException, NoSuchMethodException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object invokeMethod(Object thiz, String name, Object[] args)
+ throws ScriptException, NoSuchMethodException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-dev-help@jakarta.apache.org