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.kuali.rice.krad.uif.component.Component;
19  import org.kuali.rice.krad.uif.element.Label;
20  import org.kuali.rice.krad.uif.element.Message;
21  import org.kuali.rice.krad.uif.view.View;
22  
23  import org.junit.Test;
24  
25  import static junit.framework.Assert.*;
26  import static org.mockito.Mockito.*;
27  
28  /**
29   * test various FieldBase methods
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class FieldBaseTest {
33  
34      @Test
35      /**
36       * Tests rendering on required messages
37       *
38       * @see KULRICE-7130
39       */
40      public void testRequiredMessageDisplay() {
41  
42          // create mock objects for view, model, and component
43          View mockView =  mock(View.class);
44          Object nullModel = null;
45          Component mockComponent = mock(Component.class);
46  
47          // build asterisk required message and mock label to test rendering
48          Label mockLabel = mock(Label.class);
49  
50          Message requiredMessage = new Message();
51          requiredMessage.setMessageText("*");
52          requiredMessage.setRender(true);
53          when(mockLabel.getRequiredMessage()).thenReturn(requiredMessage);
54  
55          try {
56              FieldBase fieldBase = new FieldBase();
57              fieldBase.setFieldLabel(mockLabel);
58              fieldBase.setRequired(true);
59  
60              // required and not readonly - render
61              fieldBase.setReadOnly(false);
62              fieldBase.performFinalize(mockView, nullModel, mockComponent);
63              assertTrue(fieldBase.getFieldLabel().getRequiredMessage().isRender());
64  
65              // required and readonly -  do not render
66              fieldBase.setReadOnly(true);
67              fieldBase.performFinalize(mockView, nullModel, mockComponent);
68              assertFalse(fieldBase.getFieldLabel().getRequiredMessage().isRender());
69          } catch(Exception ex) {
70              fail("Unit Test Exception - " + ex.getMessage());
71          }
72      }
73  
74  }