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 sa...@opensource.lk on 2004/05/10 06:47:20 UTC
[PATCH]Updated testcase for JPython Script Engine
Dear All,
Please accept this patch which is an updated testcase for the JPython
script engine
Regards !!
Sanka Samaranayake <sa...@opensource.lk>
**********************************************************************
**********************************************************************
package org.apache.bsf.test.engineTests;
import org.apache.bsf.BSFEngine;
import org.apache.bsf.BSFException;
import org.apache.bsf.test.BSFEngineTestTmpl;
/**
*
* This is a testcase for JPython Script Engine
*
* @author Sanka Samaranayake <sa...@opensource.lk>
* @author Nilupa Bandara <ni...@opensource.lk>
*
*/
public class jpythonTest extends BSFEngineTestTmpl {
private BSFEngine jpythonEngine;
private String lineSeparatorStr = System.getProperty("line.separator");
public jpythonTest(String name) {
super(name);
}
public void setUp() {
super.setUp();
//bsfManager = new BSFManager();
try{
jpythonEngine = bsfManager.loadScriptingEngine("jpython");
}catch(Exception ex){
fail(failMessage("fail while attempting to load jpython", ex));
}
}
public void tearDown() {
super.tearDown();
}
public void testDeclareBean() {
Integer foo = new Integer(0);
Integer bar = null;
try{
bsfManager.declareBean("foo", foo, Integer.class);
bar = new Integer((jpythonEngine.eval("Test.py", 0, 0,
"foo + 1")).toString());
}catch(Exception ex){
fail(failMessage("declareBean() test failed", ex));
}
assertEquals(bar, new Integer(1));
}
public void testExec() {
try{
jpythonEngine.exec("Test.py", 0, 0,
"print \"PASSED\"");
}catch(Exception ex){
fail(failMessage("exec() test failed", ex));
}
assertEquals("PASSED"+lineSeparatorStr, getTmpOutStr());
}
public void testIexec(){
try{
jpythonEngine.iexec("Test.py", 0, 0,
"print \"PASSED\"");
}catch(BSFException bsfe){
fail(failMessage("iexec() test failed", bsfe));
}
assertEquals("PASSED"+lineSeparatorStr, getTmpOutStr());
}
public void testUndeclareBean() {
Integer foo = new Integer(0);
Object bar = null;
try{
bsfManager.declareBean("foo", foo, Integer.class);
bsfManager.undeclareBean("foo");
bar = bsfManager.lookupBean("foo");
}catch(BSFException bsfe){
fail(failMessage("undeclaredBean() test failed", bsfe));
}
assertNull(bar);
}
public void testRegisterBean(){
Integer foo = new Integer(0);
Integer bar = null;
try{
bsfManager.registerBean("foo", foo);
bar = new Integer((jpythonEngine.eval("Test.py", 0, 0,
"bsf.lookupBean(\"foo\")")).toString());
}catch(BSFException bsfe){
fail(failMessage("registerBean() test failed", bsfe));
}
assertEquals(bar, foo);
}
public void testCall() {
Object[] args = {new Integer(0)};
Integer result = null;
try{
jpythonEngine.exec("Test.py", 0, 0,
"def addOne(x):\n\t return x+1\n");
result = new Integer((jpythonEngine.call(
null, "addOne", args)).toString());
}catch(BSFException bsfe){
fail(failMessage("call() test failed", bsfe));
}
assertEquals(result, new Integer(1));
}
public void testEval() {
Integer retVal=null;
try{
retVal = new Integer((jpythonEngine.eval("Test.py", 0, 0,
"1 + (-1)")).toString());
}catch(BSFException bsfe){
fail(failMessage("eval() test fail", bsfe));
}
assertEquals(new Integer(0), retVal);
}
public void testUntegisterBean() {
Integer foo = new Integer(0);
Object bar = null;
try{
bsfManager.registerBean("foo", foo);
bsfManager.unregisterBean("foo");
bar = jpythonEngine.eval("Test.py", 0, 0,
"bsf.lookupBean(\"foo\")");
}catch(BSFException bsfe){
fail(failMessage("unregisterBean() test fail", bsfe));
}
assertEquals(bar.toString(), "None");
}
public void testBSFManagerEval() {
Integer retval = null;
try {
retval = new Integer((bsfManager.eval("jython", "Test.py", 0, 0,
"1 + (-1)")).toString());
}
catch (Exception e) {
fail(failMessage("BSFManager eval() test failed", e));
}
assertEquals(new Integer(0), retval);
}
public void testBSFManagerAvailability() {
Object result = null;
try{
result = jpythonEngine.eval("Test.py", 0, 0,
"bsf.lookupBean(\"foo\")");
}catch(BSFException bsfe){
fail(failMessage("BSF Manager availability failed", bsfe));
}
assertEquals(result.toString(), "None");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-dev-help@jakarta.apache.org