jakarta-bsf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@opensource.lk
Subject [PATCH]Testcase for the JPython Engine
Date Thu, 06 May 2004 06:36:10 GMT
Dear All;

Please accept the patch which is a testcase for the JPython Script Engine

Regards ..!!!

Sanka Samaranayake <sanka@opensource.lk>

************************************************************
This is the org.apache.bsf.test.engineTests.jpythonTest.java
************************************************************

package org.apache.bsf.test.engineTests;

import org.apache.bsf.BSFEngine;
import org.apache.bsf.BSFException;
import org.apache.bsf.BSFManager;
import org.apache.bsf.test.BSFEngineTestTmpl;

/**
 *
 * This is a testcase for JPython Script Engine
 *
 * @author Sanka Samaranayake <sanka@opensource.lk>
 * @author Nilupa Bandara     <nilupa@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 testInitialize() {
        }

        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 testApply() {
        }

        public void testCompileApply() {
        }

        public void testCompileExpr() {
        }

        public void testCompileScript() {
        }

        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");
        }

        public void testPropertyChange() {
        }

        public void testTerminate() {
        }

}



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


Mime
View raw message