webwork/src/test/webwork/util ValueStackTestCase.java,1.4,1.5

[email protected] Mon, 31 May 2004 16:17:45 -0700
Newsgroups gmane.comp.java.open-symphony.cvs
Message-ID <[email protected]>
Update of /cvsroot/opensymphony/webwork/src/test/webwork/util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27095

Modified Files:
	ValueStackTestCase.java 
Log Message:
Added test cases for the following fixes to the value stack:
Fixed bug where stack continued searching when it found a null value
(issue WW-382 and WW-464).
Improved performance when accessing collections data.
Fixed bug where primitive arrays could not be accessed (issue WW-542).
Fixed bug where stack would try to call a method even though the
number of parameters did not even match.


Index: ValueStackTestCase.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/test/webwork/util/ValueStackTestCase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ValueStackTestCase.java	14 Mar 2004 23:30:34 -0000	1.4
+++ ValueStackTestCase.java	31 May 2004 23:17:43 -0000	1.5
@@ -11,6 +11,7 @@
 import webwork.action.Action;
 import webwork.action.ActionContext;
 import webwork.examples.Test;
+import webwork.examples.Person;
 import webwork.TestCaseSupport;
 
 import java.util.HashMap;
@@ -148,7 +149,7 @@
       // The 1.4 version could handle this case if an even number of
       // quotes were used
       assertEquals("he'll'oworld", vs.findValue("concat('he'll'o','world')"));
-      // The 1.4 version could not hande this case where an odd number of
+      // The 1.4 version could not handle this case where an odd number of
       // quotes were used
       assertEquals("hell'oworld", vs.findValue("concat('hell'o','world')"));
       // The 1.4 version could not handle parenthesis inside quotes correctly
@@ -173,6 +174,81 @@
     assertTrue(vs.test("/stringsEqual(sameString('foo'), 'bar')==false"));
   }
 
+   public void testStackSearch() {
+      Person person = new Person(null, "[email protected]");
+      vs.pushValue(person);
+      // Make sure that the value stack does not continue searching when null is found
+      assertNull(vs.findValue("name"));
+      // In this case it should find name/length because when it fails to find length
+      // on the Person object it will continue searching on the stack
+      // One might argue that it would be more logical not to continue searching, but
+      // that would probably be too big change compared to previous versions
+      assertTrue(vs.test("name/length==10"));
+      assertNull(vs.findValue("./name/length"));
+      assertEquals("HelloWorld", vs.findValue("../name"));
+      assertNull(vs.findValue("name/dummyProperty"));
+      assertNull(vs.findValue("dummyProperty"));
+      assertNull(vs.findValue("dummyMethod('foo')"));
+      assertNull(vs.findValue("name/dummyMethod('foo')"));
+      assertEquals(Boolean.TRUE, vs.findValue("ok"));
+
+      assertEquals("bar",vs.findValue("second('foo','bar')"));
+      assertNull(vs.findValue("./second('foo','bar')"));
+      assertNull(vs.findValue("second('foo',name)"));
+      assertEquals("HelloWorld",vs.findValue("second('foo',../name)"));
+
+      // Call methods with different parameter types
+      assertNull(vs.findValue("second('foo',1)"));
+      // Conversion not done in Person, continue searching in Test object
+      assertEquals(new Integer(1), vs.findValue("integer(1)"));
+      assertEquals(new Integer(1), vs.findValue("../integer('1')"));
+      // This call should be made to the Person object
+      assertEquals(new Integer(17), vs.findValue("integer('a')"));
+
+      // Try calling methods with wrong number of parameters
+      // The method calls should not even be tried by the Valuestack but it will
+      // log error messages though
+      assertNull(vs.findValue("second('foo')"));
+      assertNull(vs.findValue("second('foo','bar','test')"));
+      assertNull(vs.findValue("second()"));
+      assertNull(vs.findValue("test('foo')"));
+
+      // Call a method in Person that will throw an exception. The value stack should
+      // then be searched and another working method will be found in Test
+      assertEquals(Boolean.TRUE, vs.findValue("stringsEqual('bar','bar')"));
+      assertNull(vs.findValue("./stringsEqual('bar','bar')"));
+
+      // Do some test searching several levels up the stack
+      vs.pushValue(person);
+      assertEquals("bar",vs.findValue("second('foo','bar')"));
+      assertEquals("bar",vs.findValue("../second('foo','bar')"));
+      assertEquals("bar",vs.findValue("../../second('foo','bar')"));
+      assertNull(vs.findValue("../../second('foo', name)"));
+      assertNull(vs.findValue("../../second('foo', ../name)"));
+      assertEquals("HelloWorld", vs.findValue("../../second('foo', ../../name)"));
+      assertEquals("HelloWorld", vs.findValue("../../second('foo', /name)"));
+      assertEquals("Dick Zetterberg", vs.findValue("people[2]/name"));
+      assertEquals("Dick Zetterberg", vs.findValue("../people[2]/name"));
+      assertEquals("Dick Zetterberg", vs.findValue("/people[2]/name"));
+      assertNull(vs.findValue("./people[2]/name"));
+      vs.popValue();
+   }
+
+   public void testCollections() {
+      Person person = new Person(null, "[email protected]");
+      vs.pushValue(person);
+
+      assertEquals("Dick Zetterberg", vs.findValue("people[2]/name"));
+
+      // The 1.4 version and earlier, could not retrieve objects from
+      // primitive arrays. Test that it works now
+      assertEquals(new Integer(2), vs.findValue("integers[2]"));
+      assertEquals(new Integer(2), vs.findValue("ints[2]"));
+      assertEquals(new Long(3), vs.findValue("longObjects[3]"));
+      assertEquals(new Long(3), vs.findValue("longs[3]"));
+      assertEquals(Boolean.TRUE, vs.findValue("bools[3]"));
+   }
+
 	/**
 	 * Runs this test case.
 	 */



-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click