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 */ 016package org.kuali.rice.krad.uif.container; 017 018import static org.junit.Assert.assertTrue; 019 020import java.util.ArrayList; 021import java.util.List; 022 023import org.junit.Before; 024import org.junit.Test; 025import org.kuali.rice.krad.uif.UifConstants; 026import org.kuali.rice.krad.uif.component.Component; 027import org.kuali.rice.krad.uif.control.Control; 028import org.kuali.rice.krad.uif.control.SelectControlBase; 029import org.kuali.rice.krad.uif.control.TextAreaControl; 030import org.kuali.rice.krad.uif.field.InputField; 031import org.kuali.rice.krad.uif.field.InputFieldBase; 032 033/** 034 * various tests for CollectionGroup 035 * 036 * @author Kuali Rice Team (rice.collab@kuali.org) 037 */ 038public class CollectionGroupTest { 039 private CollectionGroup group; 040 041 @Before 042 public void setup() { 043 group = new CollectionGroupBase(); 044 List<Component> items = new ArrayList<Component>(); 045 InputField field = new InputFieldBase(); 046 field.setControl(new SelectControlBase()); 047 items.add(field); 048 items.add(new TextAreaControl()); 049 group.setItems(items); 050 } 051 052 /** 053 * test that the collection group is set in all nested components' contexts 054 */ 055 @Test 056 public void testPushCollectionGroupToReference() { 057 group.pushCollectionGroupToReference(); 058 for (Component component : group.getItems()) { 059 testForCollectionGroupInContext(component, group); 060 } 061 Control innerControl = ((InputField) group.getItems().get(0)).getControl(); 062 testForCollectionGroupInContext(innerControl, group); 063 } 064 065 /** 066 * test that the collection group is available in the component's contexts 067 * 068 * @param component 069 */ 070 private void testForCollectionGroupInContext(Component component, CollectionGroup group) { 071 assertTrue("The component does not have the collection group key in the context", 072 component.getContext().containsKey(UifConstants.ContextVariableNames.COLLECTION_GROUP)); 073 assertTrue("The collection group found is not the parent group", 074 component.getContext().get(UifConstants.ContextVariableNames.COLLECTION_GROUP) == group); 075 } 076 077}