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