jakarta-bsf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nil...@opensource.lk
Subject [PATCH]testcase for org.apache.bsf.util.EngineUtils.java
Date Wed, 28 Apr 2004 09:31:34 GMT
Dear All,

Please accept this patch which is a testcase for
org.apache.bsf.util.EngineUtils.java

Regards !!

Nandika Jayawardana


***************************************************************
    diff for the org.apache.bsf.test.BSFTest.java
***************************************************************


--- BSFTest.java        2004-04-27 09:56:34.000000000 +0600
+++ BSFTestModified.java        2004-04-28 12:22:04.000000000 +0600
@@ -8,6 +8,7 @@
 import org.apache.bsf.BSFManager;

 import org.apache.bsf.test.engineTests.*;
+import org.apache.bsf.test.utilTests.*;

 /**
  * Primary test class and testing front end for BSF.
@@ -41,7 +42,7 @@
          * Please add testcases here as needed.
          */
         TestSuite suite = new TestSuite();
-        testNames = new String [4];
+        testNames = new String [7];

         suite.addTestSuite(BSFTest.class);
         testNames[0] = "BSFManager Base Tests";
@@ -51,7 +52,13 @@
         testNames[2] = "Rhino Engine Tests";
         suite.addTestSuite(jythonTest.class);
         testNames[3] = "Jython Engine Tests";
-
+        suite.addTestSuite(StringUtilsTest.class);
+        testNames[4] = "StringUtils Test";
+        suite.addTestSuite(IOUtilsTest.class);
+        testNames[5] = "IOUtils Test";
+        suite.addTestSuite(EngineUtilsTest.class);
+        testNames[6] = "EngineUtils Test";
+
         return suite;
     }

@@ -63,7 +70,7 @@
     }

     public void testRegisterEngine() {
-        assertTrue(bsfManager.isLanguageRegistered("fakeEngine"));
+        assertTrue(BSFManager.isLanguageRegistered("fakeEngine"));
     }

     public void testGetLangFromFileName() {










******************************************************
    testcase for org.apache.bsf.util.EngineUtils.java

******************************************************


package org.apache.bsf.test.utilTests;

import org.apache.bsf.BSFException;
import org.apache.bsf.util.EngineUtils;

import junit.framework.TestCase;

/**
 *
 * This is a testcase for org.apache.bsf.util.EngineUtils
 *
 * @author Nandika Jayawardana <jayawark@yahoo.com>
 *
 */

public class EngineUtilsTest extends TestCase {

        Object result=null;

        protected void setUp() throws Exception {
                super.setUp();
        }

        public void testCallBeanMethod() {

                Object[] args = new Object[]{new String("MoreConfirmation")};
                TestBean bean = new TestBean("TestBean");

                try{
                                result
=EngineUtils.callBeanMethod(bean,"getStringValue",null);
                }catch(BSFException bsfe){
                                fail("createBean method failed"+bsfe);
                }

                assertEquals("TestBean",(String)result);

                try{
                        EngineUtils.callBeanMethod(bean,"setValue",args);
                }catch(BSFException bsfe){
                        fail("createBean method failed"+bsfe);
                }

                assertEquals("MoreConfirmation",bean.getStringValue());

                args = new Object[]{new String("aString"),new Integer(1)};

                try{
                        EngineUtils.callBeanMethod(bean,"setValue",args);
                }catch(BSFException bsfe){
                        fail("createBean method failed"+bsfe);
                }

                assertEquals("aString",bean.getStringValue());
                assertEquals(new Integer(1),(Integer)bean.getNumericValue());

                // try to invoke a method which does not exist .. should
throw a
BSFException
                try{
                        result=
EngineUtils.callBeanMethod(bean,"nonExistentMethod",args);
                        fail();
                }catch(BSFException bsfe){
                }
        }

        public void testCreateBean() throws BSFException  {

                Object args[]= new Object[]{new String("test")};

                try{
                        result
=EngineUtils.createBean("org.apache.bsf.test.utilTests.TestBean",args);
                }catch(BSFException bsfe){
                        fail("createBean method failed"+bsfe);
                }

                assertNotNull(result);
                assertEquals("test",((TestBean)result).getStringValue());

                // try to create a bean by passing a wrong string ..
should throw a
BSFException
                try{
                        Object obj1 =
EngineUtils.createBean("nonExsitentClass",null);
                        fail();
                }catch(BSFException bsfe){
                }

        }
        public void testGetTypeSignatureString() {

                //test for a non primitive type
                Integer int1 = new Integer(10);
                Object obj =
EngineUtils.getTypeSignatureString(int1.getClass());

                assertEquals("Ljava/lang/Integer;",(String)obj);
                assertEquals("I",(String)(EngineUtils.getTypeSignatureString(int.class)));
        }
}



---------------------------------------------------------------------
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