1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
36
37
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
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
70
71
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 }