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
54 optionsFinder = Mockito.mock(KeyValuesFinder.class);
55 bindingInfo = Mockito.mock(BindingInfo.class);
56 model = new TestModel();
57 }
58
59 @Test
60 public void testPerformFinalizeWithNonStringFieldOptions() throws Exception {
61
62 Map<String, String> map = new HashMap<String, String>();
63 map.put("testInteger", "1");
64 optionsFinder = KeyValuesFinderFactory.fromMap(map);
65
66
67 when(view.getViewStatus()).thenReturn(UifConstants.ViewStatus.FINAL);
68 when(bindingInfo.getBindingPath()).thenReturn("testInteger");
69 when(bindingInfo.clone()).thenReturn(bindingInfo);
70
71
72 final InputField testObj = new InputFieldBase();
73 testObj.setBindingInfo(bindingInfo);
74 testObj.setReadOnly(true);
75 testObj.setOptionsFinder(optionsFinder);
76
77 ViewLifecycle.encapsulateLifecycle(view, model, new ViewPostMetadata(), null, null, new Runnable(){
78 @Override
79 public void run() {
80 testObj.performFinalize(model, testObj);
81 }});
82
83 }
84
85
86 private class TestModel {
87 public int getTestInteger() {
88 return 1;
89 }
90 }
91 }