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.core.api.util.KeyValue;
21  import org.kuali.rice.krad.keyvalues.KeyValuesBase;
22  import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
23  import org.kuali.rice.krad.keyvalues.KeyValuesFinderFactory;
24  import org.kuali.rice.krad.keyvalues.PlaceholderKeyValuesFinder;
25  import org.kuali.rice.krad.uif.UifConstants;
26  import org.kuali.rice.krad.uif.component.BindingInfo;
27  import org.kuali.rice.krad.uif.view.View;
28  import org.kuali.rice.krad.uif.view.ViewModel;
29  import org.kuali.rice.krad.web.form.UifFormBase;
30  import org.mockito.Mockito;
31  
32  import static org.mockito.Mockito.*;
33  
34  import java.util.*;
35  
36  /**
37   * tests InputField object and methods
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          optionsFinder = Mockito.mock(KeyValuesFinder.class);
52          bindingInfo = Mockito.mock(BindingInfo.class);
53          model = new TestModel();
54      }
55  
56      @Test
57      public void testPerformFinalizeWithNonStringFieldOptions() throws Exception {
58          // setup options finder
59          Map<String, String> map = new HashMap<String, String>();
60          map.put("testInteger", "1");
61          optionsFinder = KeyValuesFinderFactory.fromMap(map);
62  
63          // setup preconditions (view status is final; bindinginfo return testInteger)
64          when(view.getViewStatus()).thenReturn(UifConstants.ViewStatus.FINAL);
65          when(bindingInfo.getBindingPath()).thenReturn("testInteger");
66  
67          // setup input field with binding info and readonly
68          InputField testObj = new InputField();        
69          testObj.setBindingInfo(bindingInfo);
70          testObj.setReadOnly(true);
71          testObj.setOptionsFinder(optionsFinder);
72  
73          testObj.performFinalize(view, model, testObj);
74  
75      }
76  
77      // Simple model object to return testInteger integer
78      private class TestModel {
79          public int getTestInteger() {
80              return 1;
81          }
82      }
83  
84  }