View Javadoc
1   /**
2    * Copyright 2005-2015 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.view;
17  
18  import static org.junit.Assert.assertNotNull;
19  import static org.junit.Assert.assertTrue;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.kuali.rice.krad.uif.component.BindingInfo;
27  import org.kuali.rice.krad.uif.component.Component;
28  import org.kuali.rice.krad.uif.control.TextControl;
29  import org.kuali.rice.krad.uif.control.TextControlBase;
30  import org.kuali.rice.krad.uif.field.InputField;
31  import org.kuali.rice.krad.uif.field.InputFieldBase;
32  
33  /**
34   * ViewIndexTest has various tests for ViewIndex
35   * 
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public class ViewIndexTest {
39      @Before
40      public void setUp() throws Exception {
41  
42      }
43  
44      /**
45       * test that clear indexes after render does not clear fields with a value for
46       * refreshWhenChanged and their nested controls
47       * 
48       * @throws Exception
49       */
50      @Test
51      public void testClearIndexesAfterRender() throws Exception {
52          // create an input field
53          InputField field = new InputFieldBase();
54          BindingInfo bindingInfo = new BindingInfo();
55          bindingInfo.setBindingPath("property1");
56          field.setBindingInfo(bindingInfo);
57          String fieldId = "field1";
58          field.setId(fieldId);
59  
60          List<String> refreshWhenChangedPropertyNames = field.getRefreshWhenChangedPropertyNames();
61          refreshWhenChangedPropertyNames = refreshWhenChangedPropertyNames == null ?
62                  new ArrayList<String>() : new ArrayList<String>(refreshWhenChangedPropertyNames);
63          refreshWhenChangedPropertyNames.add("#lp.allDay eq true");
64          field.setRefreshWhenChangedPropertyNames(refreshWhenChangedPropertyNames);
65  
66          // set a control
67          TextControl textControl = new TextControlBase();
68          String controlId = "text1";
69          textControl.setId(controlId);
70          field.setControl(textControl);
71  
72          final ViewIndex viewIndex = new ViewIndex();
73  
74          Component[] components = {field};
75  
76          //add to view index
77          for (Component component : components) {
78              viewIndex.indexComponent(component);
79          }
80  
81          // verify initial view index state
82          for (Component component : components) {
83              assertNotNull(viewIndex.getComponentById(component.getId()));
84          }
85      }
86  }