1 12 13 package com.openedit.modules.scriptrunner; 14 15 import junit.framework.TestCase; 16 17 import com.openedit.BaseTestCase; 18 import com.openedit.WebPageRequest; 19 20 21 27 public class RhinoScriptRunnerTest extends BaseTestCase 28 { 29 public static final Script SCRIPTS = new Script( 30 "function foo() { /* do nothing */ }" + "function returnArray()\n" + "{\n" + 31 " return new Array( 2, 'hi', true, null, new Array(), new Array( 'mom' ) );\n" + 32 "}", "The wonderful amazing script"); 33 protected ScriptRunner fieldScriptRunner; 34 35 40 public RhinoScriptRunnerTest(String arg0) 41 { 42 super(arg0); 43 } 44 45 50 public void testExecFunction() throws Exception 51 { 52 fieldScriptRunner.init(); 53 54 Object result = fieldScriptRunner.execFunction("returnArray"); 55 assertNotNull(result); 56 assertTrue("returnArray() should have returned an Object[]", result instanceof Object []); 57 58 Object [] array = (Object []) result; 59 assertEquals("Array length", 6, array.length); 60 assertEquals(2, ((Number ) array[0]).intValue()); 61 assertEquals("hi", (String ) array[1]); 62 assertEquals(true, ((Boolean ) array[2]).booleanValue()); 63 assertNull(array[3]); 64 65 Object [] innerArray = (Object []) array[4]; 66 assertEquals("First inner array length", 0, innerArray.length); 67 68 innerArray = (Object []) array[5]; 69 assertEquals("Second inner array length", 1, innerArray.length); 70 assertEquals("mom", (String ) innerArray[0]); 71 } 72 73 76 protected void setUp() throws Exception 77 { 78 fieldScriptRunner = new RhinoScriptRunner(SCRIPTS); 79 } 80 81 public void testRunModule() throws Exception 82 { 83 WebPageRequest req = getFixture().createPageRequest("/script/run.html"); 84 getFixture().getEngine().executePageActions(req); 85 86 ScriptLogger logger = (ScriptLogger)req.getPageValue("log"); 87 assertEquals(logger.getLogs().size(), 1); 88 assertEquals(logger.getLogs().get(0),"debug: Hello World!"); 89 } 90 } 91 | Popular Tags |