001 /** 002 * Copyright 2005-2014 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 static org.mockito.Mockito.mock; 019 import static org.mockito.Mockito.when; 020 021 import java.util.HashMap; 022 import java.util.Map; 023 024 import org.junit.Before; 025 import org.junit.Test; 026 import org.kuali.rice.krad.keyvalues.KeyValuesFinder; 027 import org.kuali.rice.krad.keyvalues.KeyValuesFinderFactory; 028 import org.kuali.rice.krad.uif.UifConstants; 029 import org.kuali.rice.krad.uif.component.BindingInfo; 030 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle; 031 import org.kuali.rice.krad.uif.lifecycle.ViewPostMetadata; 032 import org.kuali.rice.krad.uif.service.ViewHelperService; 033 import org.kuali.rice.krad.uif.view.View; 034 import org.mockito.Mockito; 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 ViewHelperService mockViewHelperService = mock(ViewHelperService.class); 052 when(view.getViewHelperService()).thenReturn(mockViewHelperService); 053 054 optionsFinder = Mockito.mock(KeyValuesFinder.class); 055 bindingInfo = Mockito.mock(BindingInfo.class); 056 model = new TestModel(); 057 } 058 059 @Test 060 public void testPerformFinalizeWithNonStringFieldOptions() throws Exception { 061 // setup options finder 062 Map<String, String> map = new HashMap<String, String>(); 063 map.put("testInteger", "1"); 064 optionsFinder = KeyValuesFinderFactory.fromMap(map); 065 066 // setup preconditions (view status is final; bindinginfo return testInteger) 067 when(view.getViewStatus()).thenReturn(UifConstants.ViewStatus.FINAL); 068 when(bindingInfo.getBindingPath()).thenReturn("testInteger"); 069 when(bindingInfo.clone()).thenReturn(bindingInfo); 070 071 // setup input field with binding info and readonly 072 final InputField testObj = new InputFieldBase(); 073 testObj.setBindingInfo(bindingInfo); 074 testObj.setReadOnly(true); 075 testObj.setOptionsFinder(optionsFinder); 076 077 ViewLifecycle.encapsulateLifecycle(view, model, new ViewPostMetadata(), null, null, null, new Runnable(){ 078 @Override 079 public void run() { 080 testObj.performFinalize(model, testObj); 081 }}); 082 083 } 084 085 // Simple model object to return testInteger integer 086 private class TestModel { 087 public int getTestInteger() { 088 return 1; 089 } 090 } 091 }