1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.view;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.concurrent.Callable;
21
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.kuali.rice.krad.uif.component.BindingInfo;
25 import org.kuali.rice.krad.uif.component.Component;
26 import org.kuali.rice.krad.uif.control.TextControl;
27 import org.kuali.rice.krad.uif.field.InputField;
28 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
29 import org.kuali.rice.krad.uif.service.ViewHelperService;
30
31 import static org.junit.Assert.*;
32 import static org.mockito.Mockito.*;
33
34
35
36
37
38
39 public class ViewIndexTest {
40 @Before
41 public void setUp() throws Exception {
42
43 }
44
45
46
47
48
49
50
51 @Test
52 public void testClearIndexesAfterRender() throws Exception {
53
54 final InputField field = ViewLifecycle.encapsulateInitialization(new Callable<InputField>(){
55 @Override
56 public InputField call() throws Exception {
57 InputField field = new InputField();
58 BindingInfo bindingInfo = new BindingInfo();
59 bindingInfo.setBindingPath("property1");
60 field.setBindingInfo(bindingInfo);
61 String fieldId = "field1";
62 field.setId(fieldId);
63
64 List<String> refreshWhenChangedPropertyNames = field.getRefreshWhenChangedPropertyNames();
65 refreshWhenChangedPropertyNames = refreshWhenChangedPropertyNames == null ?
66 new ArrayList<String>() : new ArrayList<String>(refreshWhenChangedPropertyNames);
67 refreshWhenChangedPropertyNames.add("#lp.allDay eq true");
68 field.setRefreshWhenChangedPropertyNames(refreshWhenChangedPropertyNames);
69
70
71 TextControl textControl = new TextControl();
72 String controlId = "text1";
73 textControl.setId(controlId);
74 field.setControl(textControl);
75 return field;
76 }
77 });
78
79 final ViewIndex viewIndex = new ViewIndex();
80 View view = mock(View.class);
81 ViewHelperService helper = mock(ViewHelperService.class);
82 when(view.getViewHelperService()).thenReturn(helper);
83
84 ViewLifecycle.encapsulateLifecycle(view, null, null, null, new Runnable(){
85 @Override
86 public void run() {
87 Component[] components = {field.copy()};
88
89
90 for (Component component : components) {
91 viewIndex.indexComponent(component);
92 viewIndex.addInitialComponentStateIfNeeded(component);
93 }
94
95
96 for (Component component : components) {
97 assertNotNull(viewIndex.getComponentById(component.getId()));
98 }
99
100 viewIndex.clearIndexesAfterRender();
101
102 for (Component component : components) {
103 assertNotNull(viewIndex.getComponentById(component.getId()));
104 assertTrue(viewIndex.getInitialComponentStates().containsKey(component.getId()));
105 }
106 }});
107
108 }
109 }