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