01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.form.controller;
16:
17: import org.strecks.form.impl.NestedBean;
18: import org.strecks.form.impl.TestForm;
19: import org.testng.annotations.BeforeMethod;
20: import org.testng.annotations.Test;
21:
22: /**
23: * @author Phil Zoio
24: */
25: public class TestFormBinding {
26:
27: private TestForm form;
28: private DelegatingForm delegator;
29:
30: @BeforeMethod
31: public void readBindables() {
32: form = new TestForm();
33: delegator = FormTestUtils.getDelegatingForm(form);
34: }
35:
36: @Test
37: public void testBindingToTarget() {
38:
39: NestedBean nestedBean = new NestedBean();
40: form.setNestedBean(nestedBean);
41:
42: form.setIntegerValue("3");
43: form.setLongValue("11");
44:
45: delegator.bindInwards(null);
46:
47: assert nestedBean.getTargetIntegerValue() == 3;
48: assert form.getTargetLongValue() == 11;
49:
50: }
51:
52: @Test
53: public void testBindingToNull() {
54:
55: form.setIntegerValue("3");
56: form.setLongValue("11");
57:
58: delegator.bindInwards(null);
59: // nothing happens even though no nested bean is set
60: }
61:
62: @Test
63: public void testBindingFromTarget() {
64:
65: NestedBean nestedBean = new NestedBean();
66: form.setNestedBean(nestedBean);
67:
68: nestedBean.setTargetIntegerValue(3);
69: form.setTargetLongValue(11L);
70:
71: delegator.bindOutwards(null);
72:
73: assert form.getIntegerValue().equals("3");
74: assert form.getLongValue().equals("11");
75:
76: }
77:
78: @Test
79: public void testBindingFromNull() {
80:
81: delegator.bindOutwards(null);
82:
83: // nothing happens even though no nested bean is set
84: assert form.getIntegerValue() == null;
85: assert form.getLongValue() == null;
86:
87: }
88:
89: }
|