View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif.field;
17  
18  import org.junit.Before;
19  import org.junit.Test;
20  import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
21  import org.kuali.rice.krad.keyvalues.KeyValuesFinderFactory;
22  import org.kuali.rice.krad.uif.UifConstants;
23  import org.kuali.rice.krad.uif.component.BindingInfo;
24  import org.kuali.rice.krad.uif.service.ViewHelperService;
25  import org.kuali.rice.krad.uif.view.View;
26  import org.mockito.Mockito;
27  
28  import static org.mockito.Mockito.*;
29  
30  import java.util.*;
31  
32  /**
33   * tests InputField object and methods
34   *
35  **/
36  public class InputFieldTest {
37  
38      View view = null;
39      TestModel model = null;
40      KeyValuesFinder optionsFinder = null;
41      BindingInfo bindingInfo = null;
42  
43  
44      @Before
45      public void setUp() {
46          view = Mockito.mock(View.class);
47          ViewHelperService mockViewHelperService = mock(ViewHelperService.class);
48          when(view.getViewHelperService()).thenReturn(mockViewHelperService);
49  
50          optionsFinder = Mockito.mock(KeyValuesFinder.class);
51          bindingInfo = Mockito.mock(BindingInfo.class);
52          model = new TestModel();
53      }
54  
55      @Test
56      public void testPerformFinalizeWithNonStringFieldOptions() throws Exception {
57          // setup options finder
58          Map<String, String> map = new HashMap<String, String>();
59          map.put("testInteger", "1");
60          optionsFinder = KeyValuesFinderFactory.fromMap(map);
61  
62          // setup preconditions (view status is final; bindinginfo return testInteger)
63          when(view.getViewStatus()).thenReturn(UifConstants.ViewStatus.FINAL);
64          when(bindingInfo.getBindingPath()).thenReturn("testInteger");
65  
66          // setup input field with binding info and readonly
67          InputField testObj = new InputField();        
68          testObj.setBindingInfo(bindingInfo);
69          testObj.setReadOnly(true);
70          testObj.setOptionsFinder(optionsFinder);
71  
72          testObj.performFinalize(view, model, testObj);
73  
74      }
75  
76      // Simple model object to return testInteger integer
77      private class TestModel {
78          public int getTestInteger() {
79              return 1;
80          }
81      }
82  }