01: package org.strecks.form.controller;
02:
03: import org.strecks.form.impl.NestedBean;
04: import org.strecks.form.impl.SimpleStrutsForm;
05: import org.testng.annotations.BeforeMethod;
06: import org.testng.annotations.Test;
07:
08: /**
09: * @author Phil Zoio
10: */
11: public class TestDelegatingForm {
12:
13: private SimpleStrutsForm form;
14: private DelegatingForm delegator;
15:
16: @BeforeMethod
17: public void readBindables() {
18: form = new SimpleStrutsForm();
19: delegator = FormTestUtils.getDelegatingForm(form);
20:
21: assert delegator.getBindConvertInfo().getBindMap().size() == 2;
22: }
23:
24: @Test
25: public void testBindingToTarget() {
26:
27: NestedBean nestedBean = new NestedBean();
28: form.setNestedBean(nestedBean);
29:
30: form.setIntegerValue("3");
31: form.setLongValue("11");
32:
33: delegator.bindInwards(null);
34:
35: assert nestedBean.getTargetIntegerValue() == 3;
36: assert form.getTargetLongValue() == 11;
37:
38: }
39:
40: @Test
41: public void testBindingToNull() {
42:
43: form.setIntegerValue("3");
44: form.setLongValue("11");
45:
46: delegator.bindInwards(null);
47: // nothing happens even though no nested bean is set
48: }
49:
50: @Test
51: public void testBindingFromTarget() {
52:
53: NestedBean nestedBean = new NestedBean();
54: form.setNestedBean(nestedBean);
55:
56: nestedBean.setTargetIntegerValue(3);
57: form.setTargetLongValue(11L);
58:
59: delegator.bindOutwards(null);
60:
61: assert form.getIntegerValue().equals("3");
62: assert form.getLongValue().equals("11");
63:
64: }
65:
66: @Test
67: public void testBindingFromNull() {
68:
69: delegator.bindOutwards(null);
70:
71: // nothing happens even though no nested bean is set
72: assert form.getIntegerValue() == null;
73: assert form.getLongValue() == null;
74:
75: }
76:
77: }
|