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