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 th...@opensource.lk on 2004/06/18 08:02:39 UTC
Reviced testcase for BSFFunctions
Can someone commit this reviced testcase for BSFFunctions class
Regards !!
Thusitha
**************************************************************
package org.apache.bsf.test.utilTests;
/**
* Testcase for BSFFunctions class
* @author thusitha perera <th...@opensource.lk>
*/
import junit.framework.TestCase;
import org.apache.bsf.*;
import org.apache.bsf.util.*;
import org.apache.bsf.engines.javascript.*;
/**
* This is the testcase which has written for test the functionality of
* functions of BSFFunctions.java
* */
public class BSFFunctionsTest extends TestCase {
protected BSFManager mgr;
protected BSFFunctions testObj ;
protected BSFEngine eng ;
Object result ;
protected void setUp() throws Exception {
super.setUp();
mgr = new BSFManager();
eng = new JavaScriptEngine();
testObj = new BSFFunctions(mgr, eng);
String string = new String("test");
testObj.registerBean("string1", string);
}
protected void tearDown() throws Exception {
super.tearDown();
mgr.terminate();
}
/**
* The addEventListener() function is used to add event listeners to any
kind of bean. To test this function,
* A Frame is used , and windowDeactiveted event is used setVisible()
method is used to fire the event.For
* assertion, During the occurence of the event " testfun()" is called
within the script. If the mehod is
* called the return value of eval method becomes 2 otherwise 1.
* <br>
* <b> parameters </b> <br> f : windows component for add the event.
here has use java.awt.Frame
<br>
window : which will define what is the type of event
<br>
windowDeactivated : event which will listen
<br>
testfun() : function which should activate due to fire of event
<br> <br> <br>
<b>Expected Result :- </b> <br>
testfun will return 2.0
<br>
<b>Actual Result :- </b> <br>
true (becase of testfun() will return 2.0 )
*
*/
final public void testAddEventListener() throws Exception {
result = mgr.eval("javascript", "script", 0, 0,"var integer = 1;"+
"f = new java.awt.Frame (\"Test Frame\");"+
"bsf.addEventListener (f, \"window\", \"windowDeactivated\",
\"testfun()\");"+
"function testfun () {" +
"integer += 1;"+
"}" +
"f.setVisible(true);"+"f.setVisible(false);"+"integer ;");
assertEquals(true,Double.parseDouble(result.toString())==
2.0 );
}
/**
* Using "registerBean()" method in BSFManager class register one of
bean (here take string as a bean).
* The name of that bean is 'string1'. After that using 'LookupBean()'
method search the value for that
* particular bean.
* */
final public void testLookupBean() {
assertEquals("test", mgr.lookupBean("string1"));
}
/**
* Using "registerBean()" method in BSFManager class register one of
bean (here take string as a bean)
* the name of that bean is 'string1'. After that using 'lookupBean()'
method search the value for that
* particular bean.
* */
final public void testRegisterBean() {
assertEquals("test", mgr.lookupBean("string1"));
}
/**
* using "registerBean()" method in BSFManager class register one of
bean (here take string as a bean) the
* name of that bean is 'string2'. After that using 'UnregisterBean()'
unregistered. So now the value of
* string2 bean should be "null".
* */
final public void testUnregisterBean() {
String str = new String("unregister");
testObj.registerBean("string2", str);
testObj.unregisterBean("string2");
assertEquals(null, mgr.lookupBean("string2"));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-dev-help@jakarta.apache.org