View Javadoc
1   /**
2    * Copyright 2005-2016 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.container;
17  
18  import static org.junit.Assert.assertTrue;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.junit.Before;
24  import org.junit.Test;
25  import org.kuali.rice.krad.uif.UifConstants;
26  import org.kuali.rice.krad.uif.component.Component;
27  import org.kuali.rice.krad.uif.control.Control;
28  import org.kuali.rice.krad.uif.control.SelectControlBase;
29  import org.kuali.rice.krad.uif.control.TextAreaControl;
30  import org.kuali.rice.krad.uif.field.InputField;
31  import org.kuali.rice.krad.uif.field.InputFieldBase;
32  
33  /**
34   * various tests for CollectionGroup
35   * 
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public class CollectionGroupTest {
39      private CollectionGroup group;
40  
41      @Before
42      public void setup() {
43          group = new CollectionGroupBase();
44          List<Component> items = new ArrayList<Component>();
45          InputField field = new InputFieldBase();
46          field.setControl(new SelectControlBase());
47          items.add(field);
48          items.add(new TextAreaControl());
49          group.setItems(items);
50      }
51  
52      /**
53       * test that the collection group is set in all nested components' contexts
54       */
55      @Test
56      public void testPushCollectionGroupToReference() {
57          group.pushCollectionGroupToReference();
58          for (Component component : group.getItems()) {
59              testForCollectionGroupInContext(component, group);
60          }
61          Control innerControl = ((InputField) group.getItems().get(0)).getControl();
62          testForCollectionGroupInContext(innerControl, group);
63      }
64  
65      /**
66       * test that the collection group is available in the component's contexts
67       * 
68       * @param component
69       */
70      private void testForCollectionGroupInContext(Component component, CollectionGroup group) {
71          assertTrue("The component does not have the collection group key in the context",
72                  component.getContext().containsKey(UifConstants.ContextVariableNames.COLLECTION_GROUP));
73          assertTrue("The collection group found is not the parent group",
74                  component.getContext().get(UifConstants.ContextVariableNames.COLLECTION_GROUP) == group);
75      }
76  
77  }