001 /**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krad.uif.container;
017
018 import org.junit.Before;
019 import org.junit.Test;
020 import org.kuali.rice.krad.uif.UifConstants;
021 import org.kuali.rice.krad.uif.component.Component;
022 import org.kuali.rice.krad.uif.control.Control;
023 import org.kuali.rice.krad.uif.control.SelectControl;
024 import org.kuali.rice.krad.uif.control.TextAreaControl;
025 import org.kuali.rice.krad.uif.control.TextControl;
026 import org.kuali.rice.krad.uif.field.InputField;
027
028 import java.util.ArrayList;
029 import java.util.List;
030
031 import static junit.framework.Assert.assertEquals;
032 import static junit.framework.Assert.assertTrue;
033
034 /**
035 * various tests for CollectionGroup
036 *
037 * @author Kuali Rice Team (rice.collab@kuali.org)
038 */
039 public class CollectionGroupTest {
040 private CollectionGroup group;
041 private Control innerControl;
042
043 @Before
044 public void setup() {
045 group = new CollectionGroup();
046 List<Component> items = new ArrayList<Component>();
047 InputField field = new InputField();
048 innerControl = new SelectControl();
049 field.setControl(innerControl);
050 items.add(field);
051 items.add(new TextAreaControl());
052 group.setItems(items);
053 }
054
055 @Test
056 /**
057 * test that the collection group is set in all nested components' contexts
058 */
059 public void testPushCollectionGroupToReference() {
060 group.pushCollectionGroupToReference();
061 for (Component component: group.getItems()) {
062 testForCollectionGroupInContext(component);
063 }
064 testForCollectionGroupInContext(innerControl);
065
066 }
067
068 /**
069 * test that the collection group is available in the component's contexts
070 *
071 * @param component
072 */
073 private void testForCollectionGroupInContext(Component component) {
074 assertTrue("The component does not have the collection group key in the context",
075 component.getContext().containsKey(UifConstants.ContextVariableNames.COLLECTION_GROUP));
076 assertTrue("The collection group found is not the parent group",
077 component.getContext().get(UifConstants.ContextVariableNames.COLLECTION_GROUP) == group);
078 }
079 }