1   /*
2    * $Id: PopulationTest.java,v 1.12 2004/06/11 09:19:43 eelco12 Exp $
3    * $Revision: 1.12 $
4    * $Date: 2004/06/11 09:19:43 $
5    *
6    * ====================================================================
7    * Copyright (c) 2003, Open Edge B.V.
8    * All rights reserved.
9    * Redistribution and use in source and binary forms, with or without 
10   * modification, are permitted provided that the following conditions are met:
11   * Redistributions of source code must retain the above copyright notice, 
12   * this list of conditions and the following disclaimer. Redistributions 
13   * in binary form must reproduce the above copyright notice, this list of 
14   * conditions and the following disclaimer in the documentation and/or other 
15   * materials provided with the distribution. Neither the name of OpenEdge B.V. 
16   * nor the names of its contributors may be used to endorse or promote products 
17   * derived from this software without specific prior written permission.
18   * 
19   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
20   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
21   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
22   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
23   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
24   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
25   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
26   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
27   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
28   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
29   * THE POSSIBILITY OF SUCH DAMAGE.
30   */
31   
32  package nl.openedge.baritus.test;
33  
34  import java.util.Calendar;
35  import java.util.Date;
36  import java.util.HashMap;
37  import java.util.List;
38  import java.util.Locale;
39  import java.util.Map;
40  
41  import javax.servlet.ServletException;
42  
43  import nl.openedge.baritus.ExecutionParams;
44  import nl.openedge.baritus.FormBeanContext;
45  import nl.openedge.baritus.FormBeanCtrlBase;
46  import nl.openedge.baritus.test.mock.MockHttpServletRequest;
47  import nl.openedge.baritus.test.mock.MockHttpServletResponse;
48  
49  import org.infohazard.maverick.flow.MaverickContext;
50  
51  import com.mockobjects.servlet.MockHttpSession;
52  import com.mockobjects.servlet.MockRequestDispatcher;
53  import com.mockobjects.servlet.MockServletConfig;
54  import com.mockobjects.servlet.MockServletContext;
55  
56  import junit.framework.TestCase;
57  
58  /***
59   * Testcase for population of form beans and interceptors.
60   * 
61   * @author Eelco Hillenius
62   * @author Sander Hofstee
63   */
64  public class PopulationTest extends TestCase
65  {
66  	
67  	private Locale dutch = new Locale("nl", "NL");
68  
69  	private MockRequestDispatcher requestDispatcher = null;
70  	private MockServletContext servletContext = null;
71  	private MockServletConfig servletConfig = null;
72  	private MockHttpSession session = null;
73  	private MockHttpServletResponse response = null;		
74  	private MockHttpServletRequest request = null;
75  
76  	/***
77  	 * construct
78  	 * @param name
79  	 */
80  	public PopulationTest(String name)
81  	{
82  		super(name);
83  	}
84  	
85  	/***
86  	 * @see junit.framework.TestCase#setUp()
87  	 */
88  	protected void setUp() throws Exception
89  	{
90  		this.requestDispatcher = new MockRequestDispatcher();
91  		this.servletContext = new MockServletContext();
92  		this.servletContext.setupGetRequestDispatcher(requestDispatcher);
93  		this.servletConfig = new MockServletConfig();
94  		this.servletConfig.setServletContext(servletContext);
95  		this.session = new MockHttpSession();
96  		this.session.setupGetAttribute(
97  			FormBeanCtrlBase.SESSION_KEY_CURRENT_LOCALE, dutch);
98  			
99  		this.session.setupServletContext(servletContext);
100 		this.response = new MockHttpServletResponse();
101 		this.request = new MockHttpServletRequest();
102 		this.request.setupGetAttribute("__formBeanContext");
103 		this.request.setSession(session);
104 		this.request.setupGetRequestDispatcher(requestDispatcher);
105 	}
106 	
107 
108 	public void testIntegerPopulationAndBeforePerformInterceptor()
109 	{
110 		TestCtrl ctrl = new TestCtrl();
111 		Map requestParams = new HashMap();
112 		requestParams.put("testInteger1", "1"); // test simple string
113 		requestParams.put("testInteger2", new String[]{"2"}); // test string array
114 		request.setupGetParameterMap(requestParams);
115 		MaverickContext mockMavCtx = new MaverickContext(
116 			null, request, response);
117 		
118 		try
119 		{
120 			ctrl.init(null);
121 			ctrl.go(mockMavCtx);
122 			TestBean bean = ctrl.getTestBean();
123 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
124 			assertNotNull(bean.getTestInteger1());
125 			assertEquals(new Integer(1), bean.getTestInteger1());
126 			assertNotNull(bean.getTestInteger2());
127 			assertEquals(new Integer(2), bean.getTestInteger2());
128 		}
129 		catch (ServletException e)
130 		{
131 			e.printStackTrace();
132 			fail(e.getMessage());
133 		}	
134 	}
135 	
136 
137 	public void testLongPopulation()
138 	{
139 		TestCtrl ctrl = new TestCtrl();
140 		Map requestParams = new HashMap();
141 		requestParams.put("testLong1", "1"); // test simple string
142 		requestParams.put("testLong2", new String[]{"2"}); // test string array
143 		request.setupGetParameterMap(requestParams);
144 		MaverickContext mockMavCtx = new MaverickContext(
145 			null, request, response);
146 		try
147 		{
148 			ctrl.init(null);
149 			ctrl.go(mockMavCtx);
150 			TestBean bean = ctrl.getTestBean();
151 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
152 			assertNotNull(bean.getTestLong1());
153 			assertEquals(new Long(1), bean.getTestLong1());
154 			assertNotNull(bean.getTestLong2());
155 			assertEquals(new Long(2), bean.getTestLong2());
156 		}
157 		catch (ServletException e)
158 		{
159 			e.printStackTrace();
160 			fail(e.getMessage());
161 		}	
162 	}
163 	
164 
165 	public void testDoublePopulationAndLocalizedDisplayProperty()
166 	{
167 		TestCtrl ctrl = new TestCtrl();
168 		Map requestParams = new HashMap();
169 		requestParams.put("testDouble1", "1,1"); // test simple string
170 		requestParams.put("testDouble2", new String[]{"1,2"}); // test string array
171 		request.setupGetParameterMap(requestParams);
172 		MaverickContext mockMavCtx = new MaverickContext(
173 			null, request, response);
174 		try
175 		{
176 			ctrl.init(null);
177 			ctrl.go(mockMavCtx);
178 			TestBean bean = ctrl.getTestBean();
179 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
180 			assertNotNull(bean.getTestDouble1());
181 			assertEquals(new Double(1.1), bean.getTestDouble1());
182 			assertNotNull(bean.getTestDouble2());
183 			assertEquals(new Double(1.2), bean.getTestDouble2());
184 			FormBeanContext formBeanContext = ctrl.getFormBeanContext();
185 			assertEquals("dutch locale should be used for formatting a double property",
186 				"1,1", formBeanContext.displayProperty("testDouble1"));
187 		}
188 		catch (ServletException e)
189 		{
190 			e.printStackTrace();
191 			fail(e.getMessage());
192 		}	
193 	}
194 	
195 	public void testDatePopulation()
196 	{
197 		TestCtrl ctrl = new TestCtrl();
198 		Map requestParams = new HashMap();
199 		requestParams.put("testDate1", "20-02-2004"); // test simple string
200 		requestParams.put("testDate2", new String[]{"21-03-2005"}); // test string array
201 		request.setupGetParameterMap(requestParams);
202 		MaverickContext mockMavCtx = new MaverickContext(
203 			null, request, response);
204 		try
205 		{
206 			ctrl.init(null);
207 			ctrl.go(mockMavCtx);
208 			TestBean bean = ctrl.getTestBean();
209 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
210 			assertNotNull(bean.getTestDate1());
211 			assertNotNull(bean.getTestDate2());
212 			
213 			Calendar cal = Calendar.getInstance();
214 			Date date = bean.getTestDate1();
215 			cal.setTime(date);
216 			assertEquals(cal.get(Calendar.YEAR), 2004);
217 			assertEquals(cal.get(Calendar.MONTH), 1);
218 			assertEquals(cal.get(Calendar.DAY_OF_MONTH), 20);
219 			
220 			date = bean.getTestDate2();
221 			cal.setTime(date);
222 			assertEquals(cal.get(Calendar.YEAR), 2005);
223 			assertEquals(cal.get(Calendar.MONTH), 2);
224 			assertEquals(cal.get(Calendar.DAY_OF_MONTH), 21);
225 		}
226 		catch (ServletException e)
227 		{
228 			e.printStackTrace();
229 			fail(e.getMessage());
230 		}	
231 	}
232 	
233 	/***
234 	 * Test the population of arrays when the parameters are in the request as 
235 	 * array = {value1, value2}
236 	 */
237 	public void testRequestStringArrayPopulation()
238 	{
239 		TestCtrl ctrl = new TestCtrl();
240 		Map requestParams = new HashMap();
241 		requestParams.put("testStringArray1", new String[] {"arrayelem0", "arrayelem1"});
242 		request.setupGetParameterMap(requestParams);
243 		MaverickContext mockMavCtx = new MaverickContext(
244 			null, request, response);
245 		try
246 		{
247 			ctrl.init(null);
248 			ctrl.go(mockMavCtx);
249 			TestBean bean = ctrl.getTestBean();
250 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
251 			String[] testStringArray1 = bean.getTestStringArray1();
252 			assertNotNull(testStringArray1);
253 			assertEquals(2, testStringArray1.length);
254 			assertEquals("arrayelem0", testStringArray1[0]);
255 			assertEquals("arrayelem1", testStringArray1[1]);
256 		}
257 		catch (ServletException e)
258 		{
259 			e.printStackTrace();
260 			fail(e.getMessage());
261 		}		
262 	}
263 	
264 	public void testStringMapPopulation()
265 	{
266 		TestCtrl ctrl = new TestCtrl();
267 		Map requestParams = new HashMap();
268 		requestParams.put("testMap['key1']", "val1");
269 		requestParams.put("testMap['key2']", "val2");
270 		request.setupGetParameterMap(requestParams);
271 		MaverickContext mockMavCtx = new MaverickContext(
272 			null, request, response);
273 		try
274 		{
275 			ctrl.init(null);
276 			ctrl.go(mockMavCtx);
277 			TestBean bean = ctrl.getTestBean();
278 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
279 			Map map = bean.getTestMap();
280 			assertNotNull(map);
281 			assertEquals(2, map.size());
282 			assertEquals("val1", map.get("key1"));
283 			assertEquals("val2", map.get("key2"));
284 		}
285 		catch (ServletException e)
286 		{
287 			e.printStackTrace();
288 			fail(e.getMessage());
289 		}	
290 	}
291 	
292 	public void testPopulationWithCustomPopulators()
293 	{
294 		TestCtrl ctrl = new TestCtrl();
295 		Map requestParams = new HashMap();
296 		requestParams.put("uppercaseTest", "this once was lower case");
297 		requestParams.put("ignore", "this should never come through");
298 		request.setupGetParameterMap(requestParams);
299 		MaverickContext mockMavCtx = new MaverickContext(
300 			null, request, response);
301 		try
302 		{
303 			ctrl.init(null);
304 			ctrl.go(mockMavCtx);
305 			TestBean bean = ctrl.getTestBean();
306 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
307 			assertEquals("THIS ONCE WAS LOWER CASE", bean.getUppercaseTest());
308 			assertEquals("unchanged", bean.getIgnore());
309 		}
310 		catch (ServletException e)
311 		{
312 			e.printStackTrace();
313 			fail(e.getMessage());
314 		}	
315 	}
316 	
317 	public void testPopulationWithCustomPopulatorByRegexMatch()
318 	{
319 		TestCtrl ctrl = new TestCtrl();
320 		Map requestParams = new HashMap();
321 		requestParams.put("ignoreByRegex", "this should never come through");
322 		request.setupGetParameterMap(requestParams);
323 		MaverickContext mockMavCtx = new MaverickContext(
324 			null, request, response);
325 		try
326 		{
327 			ctrl.init(null);
328 			ctrl.go(mockMavCtx);
329 			TestBean bean = ctrl.getTestBean();
330 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
331 			assertEquals("unchanged (regex)", bean.getIgnoreByRegex());
332 		}
333 		catch (ServletException e)
334 		{
335 			e.printStackTrace();
336 			fail(e.getMessage());
337 		}	
338 	}
339 	
340 	/***
341 	 * Test the population of indexed properties.
342 	 *
343 	 */
344 	public void testPopulationWithListProperties()
345 	{
346 		TestCtrl ctrl = new TestCtrl();
347 		Map requestParams = new HashMap();
348 		requestParams.put("listProperty[0]", "newval0");
349 		requestParams.put("listProperty[1]", "newval1");
350 		request.setupGetParameterMap(requestParams);
351 		MaverickContext mockMavCtx = new MaverickContext(
352 			null, request, response);
353 		try
354 		{
355 			ctrl.init(null);
356 			ctrl.go(mockMavCtx);
357 			TestBean bean = ctrl.getTestBean();
358 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
359 			
360 			List listProperty = bean.getListProperty();
361 			assertNotNull(listProperty);
362 			assertEquals(2, listProperty.size());
363 			assertEquals("newval0", listProperty.get(0));
364 			assertEquals("newval1", listProperty.get(1));
365 		}
366 		catch (ServletException e)
367 		{
368 			e.printStackTrace();
369 			fail(e.getMessage());
370 		}
371 	}
372 	
373 	/***
374 	 * Test the population of multidimensional mapped properties.
375 	 *
376 	 */
377 	public void testPopulationWithMultiDimensionalMappedProperties()
378 	{
379 		TestCtrl ctrl = new TestCtrl();
380 		Map requestParams = new HashMap();
381 		requestParams.put("multiDimensionalMap['one']['one']", "newval0");
382 		requestParams.put("multiDimensionalMap['one']['two']", "newval1");
383 		requestParams.put("multiDimensionalMap['one']['three']", "newval2");
384 		requestParams.put("multiDimensionalMap['two']['one']", "newval3");
385 		request.setupGetParameterMap(requestParams);
386 		MaverickContext mockMavCtx = new MaverickContext(
387 			null, request, response);
388 		try
389 		{
390 			ctrl.init(null);
391 			ctrl.go(mockMavCtx);
392 			TestBean bean = ctrl.getTestBean();
393 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
394 		
395 			Map listProperty = bean.getMultiDimensionalMap();
396 			assertNotNull(listProperty);
397 			assertEquals(2, listProperty.size());
398 			
399 			Map one = (Map)listProperty.get("one");				
400 			assertEquals(3, one.size());
401 			
402 			assertTrue(one.containsKey("one"));
403 			assertTrue(one.containsKey("two"));
404 			assertTrue(one.containsKey("three"));
405 			
406 			assertEquals("newval0", one.get("one"));
407 			assertEquals("newval1", one.get("two"));
408 			assertEquals("newval2", one.get("three"));
409 			
410 			Map two = (Map)listProperty.get("two");
411 			assertEquals(1, two.size());
412 			assertTrue(two.containsKey("one"));
413 			assertEquals("newval3", two.get("one"));
414 		}
415 		catch (ServletException e)
416 		{
417 			e.printStackTrace();
418 			fail(e.getMessage());
419 		}
420 	}
421 
422 	/***
423 	 * Test the population of multidimensional List properties. 
424 	 *
425 	 */
426 	public void testPopulationWithMultiDimensionalListProperties()
427 	{
428 		TestCtrl ctrl = new TestCtrl();
429 		Map requestParams = new HashMap();
430 		requestParams.put("multiDimensionalList[0][0]", "newval0");
431 		requestParams.put("multiDimensionalList[0][1]", "newval1");
432 		requestParams.put("multiDimensionalList[0][2]", "newval2");
433 		requestParams.put("multiDimensionalList[1][0]", "newval0");
434 		request.setupGetParameterMap(requestParams);
435 		MaverickContext mockMavCtx = new MaverickContext(
436 			null, request, response);
437 		try
438 		{
439 			ctrl.init(null);
440 			ctrl.go(mockMavCtx);
441 			TestBean bean = ctrl.getTestBean();
442 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
443 			
444 			List listProperty = bean.getMultiDimensionalList();
445 			assertNotNull(listProperty);
446 			assertEquals(2, listProperty.size());
447 			
448 			List one = (List)listProperty.get(0);
449 			assertEquals(3, one.size());
450 			
451 			List two = (List)listProperty.get(1);
452 			assertEquals(1, two.size());
453 			
454 			assertTrue(listProperty.get(0).getClass().getName() + 
455 				" with value " + listProperty.get(0)
456 				, listProperty.get(0) instanceof List);
457 			assertTrue(listProperty.get(1).getClass().getName() + 
458 				" with value " + listProperty.get(0)
459 				, listProperty.get(1) instanceof List);
460 		}
461 		catch (ServletException e)
462 		{
463 			e.printStackTrace();
464 			fail(e.getMessage());
465 		}
466 	}
467 
468 	public void testError1()
469 	{
470 		TestCtrl ctrl = new TestCtrl();
471 		Map requestParams = new HashMap();
472 		requestParams.put("testDouble1", "wrong"); // test simple string
473 		request.setupGetParameterMap(requestParams);
474 		MaverickContext mockMavCtx = new MaverickContext(
475 			null, request, response);
476 		try
477 		{
478 			ctrl.init(null);
479 			ctrl.go(mockMavCtx);
480 			TestBean bean = ctrl.getTestBean();
481 			assertEquals(FormBeanCtrlBase.ERROR, ctrl.getView());
482 			assertNull(bean.getTestDouble1());
483 
484 		}
485 		catch (ServletException e)
486 		{
487 			e.printStackTrace();
488 			fail(e.getMessage());
489 		}	
490 	}
491 	
492 	
493 //	public void testGetMultiDimProperty()
494 //	{
495 //		TestBean bean = new TestBean();
496 //		Map map1 = new HashMap();
497 //		Map map2a = new HashMap();
498 //		map2a.put("key2a-1", "value2a-1");
499 //		map2a.put("key2a-2", "value2a-2");
500 //		Map map2b = new HashMap();
501 //		map2b.put("key2b-1", "value2b-1");
502 //		map1.put("map2a", map2a);
503 //		map1.put("map2b", map2b);
504 //		bean.setMultiDimensionalMap(map1);
505 //		try
506 //		{
507 //			Object result = Ognl.getValue("multiDimensionalMap['map2a']['key2a-2']", bean);
508 //			assertEquals("value2a-2", result);
509 //			bean.setTestDate1(new Date());
510 //			result = Ognl.getValue("testDate1", bean);
511 //		}
512 //		catch (Exception e)
513 //		{
514 //			e.printStackTrace();
515 //		}
516 //	}
517 
518 	public void testObjectFromRequestAttributesPopulation()
519 	{
520 		TestCtrl ctrl = new TestCtrl();
521 
522 		Map requestParams = new HashMap();
523 		TestObject testObject = new TestObject();
524 		testObject.setTestString("a test");
525 		request.setAttribute("testObject", testObject);
526 		request.setupGetParameterMap(requestParams);
527 
528 		MaverickContext mockMavCtx = new MaverickContext(
529 			null, request, response);
530 		try
531 		{
532 			ctrl.init(null);
533 			ctrl.go(mockMavCtx);
534 			TestBean bean = ctrl.getTestBean();
535 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
536 			assertNotNull(bean.getTestObject());
537 			assertEquals("a test", bean.getTestObject().getTestString());
538 		}
539 		catch (ServletException e)
540 		{
541 			e.printStackTrace();
542 			fail(e.getMessage());
543 		}	
544 	}
545 	
546 	// OGNL!
547 	public void testStrictParsing()
548 	{
549 		TestCtrl ctrl = new TestCtrl();
550 		Map requestParams = new HashMap();
551 		requestParams.put("not-a-valid-name", "foo"); // test simple string
552 		request.setupGetParameterMap(requestParams);
553 		MaverickContext mockMavCtx = new MaverickContext(
554 			null, request, response);
555 		try
556 		{
557 			ctrl.init(null);
558 			ctrl.go(mockMavCtx);
559 			TestBean bean = ctrl.getTestBean();
560 			assertEquals(FormBeanCtrlBase.ERROR, ctrl.getView()); // should fail by default
561 		}
562 		catch (ServletException e)
563 		{
564 			e.printStackTrace();
565 			fail(e.getMessage());
566 		}	
567 	}
568 	
569 	// OGNL!
570 	public void testNonStrictParsing()
571 	{
572 		TestCtrl ctrl = new TestCtrl();
573 		ExecutionParams params = ctrl.getExecutionParams(null);
574 		params.setStrictPopulationMode(false);
575 		ctrl.fixExecutionParams(params);
576 		Map requestParams = new HashMap();
577 		requestParams.put("not-a-valid-name", "foo"); // test simple string
578 		request.setupGetParameterMap(requestParams);
579 		MaverickContext mockMavCtx = new MaverickContext(
580 			null, request, response);
581 		try
582 		{
583 			ctrl.init(null);
584 			ctrl.go(mockMavCtx);
585 			TestBean bean = ctrl.getTestBean();
586 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView()); // should be succesfull now
587 		}
588 		catch (ServletException e)
589 		{
590 			e.printStackTrace();
591 			fail(e.getMessage());
592 		}	
593 	}
594 	
595 	public void testTrimString1()
596 	{
597 		TestCtrl ctrl = new TestCtrl();
598 		Map requestParams = new HashMap();
599 		requestParams.put("testTrimString", "    tobetrimmed     ");
600 		request.setupGetParameterMap(requestParams);
601 		MaverickContext mockMavCtx = new MaverickContext(
602 			null, request, response);
603 		try
604 		{
605 			ctrl.init(null);
606 			ctrl.go(mockMavCtx);
607 			TestBean bean = ctrl.getTestBean();
608 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
609 			assertNotNull(bean.getTestTrimString());
610 			assertEquals("tobetrimmed", bean.getTestTrimString());
611 		}
612 		catch (ServletException e)
613 		{
614 			e.printStackTrace();
615 			fail(e.getMessage());
616 		}	
617 	}
618 	
619 	public void testTrimString2()
620 	{
621 		TestCtrl ctrl = new TestCtrl();
622 		Map requestParams = new HashMap();
623 		requestParams.put("testTrimStringArray[0]", "    tobetrimmed     ");
624 		request.setupGetParameterMap(requestParams);
625 		MaverickContext mockMavCtx = new MaverickContext(
626 			null, request, response);
627 		try
628 		{
629 			ctrl.init(null);
630 			ctrl.go(mockMavCtx);
631 			TestBean bean = ctrl.getTestBean();
632 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
633 			assertNotNull(bean.getTestTrimStringArray());
634 			assertNotNull(bean.getTestTrimStringArray()[0]);
635 			assertEquals("tobetrimmed", bean.getTestTrimStringArray()[0]);
636 		}
637 		catch (ServletException e)
638 		{
639 			e.printStackTrace();
640 			fail(e.getMessage());
641 		}	
642 	}
643 	
644 	public void testTrimString3()
645 	{
646 		TestCtrl ctrl = new TestCtrl();
647 		ExecutionParams params = ctrl.getExecutionParams(null);
648 		params.setTrimStringInputValues(false);
649 		ctrl.fixExecutionParams(params);
650 		Map requestParams = new HashMap();
651 		requestParams.put("testTrimString", "    notbetrimmed     ");
652 		request.setupGetParameterMap(requestParams);
653 		MaverickContext mockMavCtx = new MaverickContext(
654 			null, request, response);
655 		try
656 		{
657 			ctrl.init(null);
658 			ctrl.go(mockMavCtx);
659 			TestBean bean = ctrl.getTestBean();
660 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
661 			assertNotNull(bean.getTestTrimString());
662 			assertEquals("    notbetrimmed     ", bean.getTestTrimString());
663 		}
664 		catch (ServletException e)
665 		{
666 			e.printStackTrace();
667 			fail(e.getMessage());
668 		}	
669 	}
670 	
671 	public void testTrimString4()
672 	{
673 		TestCtrl ctrl = new TestCtrl();
674 		ExecutionParams params = ctrl.getExecutionParams(null);
675 		params.setTrimStringInputValues(false);
676 		ctrl.fixExecutionParams(params);
677 		Map requestParams = new HashMap();
678 		requestParams.put("testTrimStringArray[0]", "    notbetrimmed     ");
679 		request.setupGetParameterMap(requestParams);
680 		MaverickContext mockMavCtx = new MaverickContext(
681 			null, request, response);
682 		try
683 		{
684 			ctrl.init(null);
685 			ctrl.go(mockMavCtx);
686 			TestBean bean = ctrl.getTestBean();
687 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
688 			assertNotNull(bean.getTestTrimStringArray());
689 			assertNotNull(bean.getTestTrimStringArray()[0]);
690 			assertEquals("    notbetrimmed     ", bean.getTestTrimStringArray()[0]);
691 		}
692 		catch (ServletException e)
693 		{
694 			e.printStackTrace();
695 			fail(e.getMessage());
696 		}	
697 	}
698 	
699 	/***
700 	 * Tests that a request attribute overrides a request parameter,
701 	 * and that the population with the request parameter is never tried
702 	 * when there is an overruling parameter.
703 	 */
704 	public void testRequestParamAndRequestAttribPopulation()
705 	{
706 		TestCtrl ctrl = new TestCtrl();
707 		Map requestParams = new HashMap();
708 		requestParams.put("testInteger1", "not a number at all"); // test invalid value
709 		request.setupGetParameterMap(requestParams);
710 		request.setAttribute("testInteger1", "1"); // this is valid, and should
711 			// override the non-valid request parameter. Hence, population
712 			// should not result in errors.
713 		MaverickContext mockMavCtx = new MaverickContext(
714 			null, request, response);
715 		try
716 		{
717 			ctrl.init(null);
718 			ctrl.go(mockMavCtx);
719 			TestBean bean = ctrl.getTestBean();
720 			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());
721 			assertNotNull(bean.getTestInteger1());
722 			assertEquals(new Integer(1), bean.getTestInteger1());
723 		}
724 		catch (ServletException e)
725 		{
726 			e.printStackTrace();
727 			fail(e.getMessage());
728 		}
729 	}
730 	
731 // THIS TESTS AN OGNL BUG/ FEATURE
732 //	/***
733 //	 * Test the population of arrays when the parameters are in the request as 
734 //	 * array[0] = 1
735 //	 * array[1] = 2
736 //	 */
737 //	public void testIntegerArrayPopulation1()
738 //	{
739 //		TestCtrl ctrl = new TestCtrl();
740 //		Map requestParams = new HashMap();
741 //		requestParams.put("testIntegerArray1[0]", "1");
742 //		requestParams.put("testIntegerArray1[1]", "2");
743 //		request.setupGetParameterMap(requestParams);
744 //		MaverickContext mockMavCtx = new MaverickContext(
745 //			null, request, response);
746 //		try
747 //		{
748 //			ctrl.init(null);
749 //			ctrl.go(mockMavCtx);
750 //			TestBean bean = ctrl.getTestBean();
751 //			assertEquals(FormBeanCtrlBase.SUCCESS, ctrl.getView());			
752 //			Integer[] testIntegerArray = bean.getTestIntegerArray1();
753 //			assertNotNull(testIntegerArray);
754 //			assertEquals(2, testIntegerArray.length);
755 //			assertEquals(new Integer(1), testIntegerArray[0]);
756 //			assertEquals(new Integer(2), testIntegerArray[1]);
757 //		}
758 //		catch (ServletException e)
759 //		{
760 //			e.printStackTrace();
761 //			fail(e.getMessage());
762 //		}	
763 //	}
764 	
765 }