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.util.CopyUtils;
26  import org.kuali.rice.krad.uif.view.View;
27  import org.mockito.Mockito;
28  
29  import static org.junit.Assert.assertFalse;
30  import static org.junit.Assert.assertTrue;
31  import static org.mockito.Mockito.mock;
32  import static org.mockito.Mockito.when;
33  
34  /**
35   * test various FieldBase methods
36   *
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  public class FieldBaseTest {
40  
41      View view = null;
42  
43      @Before
44      public void setUp() {
45          view = Mockito.mock(View.class);
46          ViewHelperService mockViewHelperService = mock(ViewHelperService.class);
47          when(view.getViewHelperService()).thenReturn(mockViewHelperService);
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, 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 = CopyUtils.copy(fieldBase);
83                  fieldBaseCopy.performFinalize(nullModel, mockComponent);
84                  assertTrue(fieldBaseCopy.getFieldLabel().isRenderRequiredIndicator());
85  
86                  // required and readonly -  do not render
87                  fieldBaseCopy = CopyUtils.copy(fieldBase);
88                  fieldBaseCopy.setReadOnly(true);
89                  fieldBaseCopy.performFinalize(nullModel, mockComponent);
90                  assertFalse(fieldBaseCopy.getFieldLabel().isRenderRequiredIndicator());
91              }
92          });
93  
94      }
95  }