View Javadoc
1   /**
2    * Copyright 2005-2014 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.krad.uif.component.Component;
21  import org.kuali.rice.krad.uif.element.Label;
22  import org.kuali.rice.krad.uif.element.Message;
23  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
24  import org.kuali.rice.krad.uif.service.ViewHelperService;
25  import org.kuali.rice.krad.uif.view.View;
26  import org.mockito.Mockito;
27  
28  import static org.junit.Assert.assertFalse;
29  import static org.junit.Assert.assertTrue;
30  import static org.mockito.Mockito.mock;
31  import static org.mockito.Mockito.when;
32  
33  /**
34   * test various FieldBase methods
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public class FieldBaseTest {
39  
40      View view = null;
41  
42      @Before
43      public void setUp() {
44          view = Mockito.mock(View.class);
45          ViewHelperService mockViewHelperService = mock(ViewHelperService.class);
46          when(view.getViewHelperService()).thenReturn(mockViewHelperService);
47          when(view.copy()).thenReturn(view);
48      }
49  
50      @Test
51      /**
52       * Tests rendering on required messages
53       *
54       * @see KULRICE-7130
55       */
56      public void testRequiredMessageDisplay() throws Exception {
57  
58          // create mock component
59          //        View mockView =  mock(View.class);
60          //        ViewHelperService mockViewHelperService = mock(ViewHelperService.class);
61          //        when(mockView.getViewHelperService()).thenReturn(mockViewHelperService);
62          //        when(mockView.copy()).thenReturn(mockView);
63          //        when(mockView.clone()).thenReturn(mockView);
64  
65          ViewLifecycle.encapsulateLifecycle(view, null, null, null, new Runnable() {
66              @Override
67              public void run() {
68                  Object nullModel = null;
69                  Component mockComponent = mock(Component.class);
70  
71                  // build asterisk required message and mock label to test rendering
72                  Label mockLabel = new Label();
73                  Message message = new Message();
74                  message.setMessageText("*");
75                  message.setRender(true);
76  
77                  FieldBase fieldBase = new FieldBase();
78                  fieldBase.setFieldLabel(mockLabel);
79                  fieldBase.setRequired(true);
80                  fieldBase.setReadOnly(false);
81  
82                  FieldBase fieldBaseCopy = fieldBase.<FieldBase>copy();
83                  fieldBaseCopy.performFinalize(nullModel, mockComponent);
84                  assertTrue(fieldBaseCopy.getFieldLabel().isRenderRequiredIndicator());
85  
86                  // required and readonly -  do not render
87                  fieldBaseCopy = fieldBase.<FieldBase>copy();
88                  fieldBaseCopy.setReadOnly(true);
89                  fieldBaseCopy.performFinalize(nullModel, mockComponent);
90                  assertFalse(fieldBaseCopy.getFieldLabel().isRenderRequiredIndicator());
91              }
92          });
93  
94      }
95  }