001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krad.uif.field;
017
018 import org.junit.Before;
019 import org.junit.Test;
020 import org.kuali.rice.core.api.util.KeyValue;
021 import org.kuali.rice.krad.keyvalues.KeyValuesBase;
022 import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
023 import org.kuali.rice.krad.keyvalues.KeyValuesFinderFactory;
024 import org.kuali.rice.krad.keyvalues.PlaceholderKeyValuesFinder;
025 import org.kuali.rice.krad.uif.UifConstants;
026 import org.kuali.rice.krad.uif.component.BindingInfo;
027 import org.kuali.rice.krad.uif.view.View;
028 import org.kuali.rice.krad.uif.view.ViewModel;
029 import org.kuali.rice.krad.web.form.UifFormBase;
030 import org.mockito.Mockito;
031
032 import static org.mockito.Mockito.*;
033
034 import java.util.*;
035
036 /**
037 * tests InputField object and methods
038 *
039 **/
040 public class InputFieldTest {
041
042 View view = null;
043 TestModel model = null;
044 KeyValuesFinder optionsFinder = null;
045 BindingInfo bindingInfo = null;
046
047
048 @Before
049 public void setUp() {
050 view = Mockito.mock(View.class);
051 optionsFinder = Mockito.mock(KeyValuesFinder.class);
052 bindingInfo = Mockito.mock(BindingInfo.class);
053 model = new TestModel();
054 }
055
056 @Test
057 public void testPerformFinalizeWithNonStringFieldOptions() throws Exception {
058 // setup options finder
059 Map<String, String> map = new HashMap<String, String>();
060 map.put("testInteger", "1");
061 optionsFinder = KeyValuesFinderFactory.fromMap(map);
062
063 // setup preconditions (view status is final; bindinginfo return testInteger)
064 when(view.getViewStatus()).thenReturn(UifConstants.ViewStatus.FINAL);
065 when(bindingInfo.getBindingPath()).thenReturn("testInteger");
066
067 // setup input field with binding info and readonly
068 InputField testObj = new InputField();
069 testObj.setBindingInfo(bindingInfo);
070 testObj.setReadOnly(true);
071 testObj.setOptionsFinder(optionsFinder);
072
073 testObj.performFinalize(view, model, testObj);
074
075 }
076
077 // Simple model object to return testInteger integer
078 private class TestModel {
079 public int getTestInteger() {
080 return 1;
081 }
082 }
083
084 }