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 org.kuali.rice.krad.uif.component.Component; 019 import org.kuali.rice.krad.uif.element.Label; 020 import org.kuali.rice.krad.uif.element.Message; 021 import org.kuali.rice.krad.uif.service.ViewHelperService; 022 import org.kuali.rice.krad.uif.view.View; 023 024 import org.junit.Test; 025 026 import static junit.framework.Assert.*; 027 import static org.mockito.Mockito.*; 028 029 /** 030 * test various FieldBase methods 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 */ 033 public class FieldBaseTest { 034 035 @Test 036 /** 037 * Tests rendering on required messages 038 * 039 * @see KULRICE-7130 040 */ 041 public void testRequiredMessageDisplay() { 042 043 // create mock objects for view, view helper service, model, and component 044 View mockView = mock(View.class); 045 ViewHelperService mockViewHelperService = mock(ViewHelperService.class); 046 when(mockView.getViewHelperService()).thenReturn(mockViewHelperService); 047 Object nullModel = null; 048 Component mockComponent = mock(Component.class); 049 050 // build asterisk required message and mock label to test rendering 051 Label mockLabel = mock(Label.class); 052 053 Message requiredMessage = new Message(); 054 requiredMessage.setMessageText("*"); 055 requiredMessage.setRender(true); 056 when(mockLabel.getRequiredMessage()).thenReturn(requiredMessage); 057 058 try { 059 FieldBase fieldBase = new FieldBase(); 060 fieldBase.setFieldLabel(mockLabel); 061 fieldBase.setRequired(true); 062 063 // required and not readonly - render 064 fieldBase.setReadOnly(false); 065 fieldBase.performFinalize(mockView, nullModel, mockComponent); 066 assertTrue(fieldBase.getFieldLabel().getRequiredMessage().isRender()); 067 068 // required and readonly - do not render 069 fieldBase.setReadOnly(true); 070 fieldBase.performFinalize(mockView, nullModel, mockComponent); 071 assertFalse(fieldBase.getFieldLabel().getRequiredMessage().isRender()); 072 } catch(Exception ex) { 073 fail("Unit Test Exception - " + ex.getMessage()); 074 } 075 } 076 }