1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.field;
17
18 import static org.mockito.Mockito.mock;
19 import static org.mockito.Mockito.when;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
27 import org.kuali.rice.krad.keyvalues.KeyValuesFinderFactory;
28 import org.kuali.rice.krad.uif.UifConstants;
29 import org.kuali.rice.krad.uif.component.BindingInfo;
30 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
31 import org.kuali.rice.krad.uif.lifecycle.ViewPostMetadata;
32 import org.kuali.rice.krad.uif.service.ViewHelperService;
33 import org.kuali.rice.krad.uif.view.View;
34 import org.mockito.Mockito;
35
36
37
38
39
40 public class InputFieldTest {
41
42 View view = null;
43 TestModel model = null;
44 KeyValuesFinder optionsFinder = null;
45 BindingInfo bindingInfo = null;
46
47
48 @Before
49 public void setUp() {
50 view = Mockito.mock(View.class);
51 ViewHelperService mockViewHelperService = mock(ViewHelperService.class);
52 when(view.getViewHelperService()).thenReturn(mockViewHelperService);
53 when(view.copy()).thenReturn(view);
54
55 optionsFinder = Mockito.mock(KeyValuesFinder.class);
56 bindingInfo = Mockito.mock(BindingInfo.class);
57 model = new TestModel();
58 }
59
60 @Test
61 public void testPerformFinalizeWithNonStringFieldOptions() throws Exception {
62
63 Map<String, String> map = new HashMap<String, String>();
64 map.put("testInteger", "1");
65 optionsFinder = KeyValuesFinderFactory.fromMap(map);
66
67
68 when(view.getViewStatus()).thenReturn(UifConstants.ViewStatus.FINAL);
69 when(bindingInfo.getBindingPath()).thenReturn("testInteger");
70 when(bindingInfo.copy()).thenReturn(bindingInfo);
71 when(bindingInfo.clone()).thenReturn(bindingInfo);
72
73
74 final InputField testObj = new InputFieldBase();
75 testObj.setBindingInfo(bindingInfo);
76 testObj.setReadOnly(true);
77 testObj.setOptionsFinder(optionsFinder);
78
79 ViewLifecycle.encapsulateLifecycle(view, model, new ViewPostMetadata(), null, null, null, new Runnable(){
80 @Override
81 public void run() {
82 testObj.performFinalize(model, testObj);
83 }});
84
85 }
86
87
88 private class TestModel {
89 public int getTestInteger() {
90 return 1;
91 }
92 }
93 }