1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.component;
17
18
19
20
21
22
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
28
29 import java.util.TreeMap;
30
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.kuali.rice.krad.uif.element.Action;
34 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
35 import org.kuali.rice.krad.uif.service.ViewHelperService;
36 import org.kuali.rice.krad.uif.util.CopyUtils;
37 import org.kuali.rice.krad.uif.view.View;
38
39
40
41
42 public class ComponentBaseTest {
43 private Component component;
44 private TreeMap<String, String> dataAttributes;
45
46 @Before
47 public void setUp() throws Exception {
48
49 component = new Action();
50 component.setId("action1");
51
52 dataAttributes = new TreeMap<String, String>();
53
54 dataAttributes.put("iconTemplateName", "cool-icon-%s.png");
55 dataAttributes.put("transitions", "3");
56 component.setDataAttributes(dataAttributes);
57 }
58
59 @Test
60
61
62
63 public void testGetSimpleDataAttributes() throws Exception {
64 assertNotNull(component.getSimpleDataAttributes());
65 String expected = " data-iconTemplateName=\"cool-icon-%s.png\" data-transitions=\"3\"";
66 assertEquals("simple attributes did not match", expected, component.getSimpleDataAttributes());
67 }
68
69 @Test
70
71
72
73 public void testGetSimpleDataAttributesWhenNull() throws Exception {
74 View view = mock(View.class);
75 ViewHelperService helper = mock(ViewHelperService.class);
76 when(view.getViewHelperService()).thenReturn(helper);
77 ViewLifecycle.encapsulateLifecycle(view, null, null, new Runnable(){
78 @Override
79 public void run() {
80 Component copy = CopyUtils.copy(component);
81 copy.setDataAttributes(null);
82 assertEquals("simple attributes did not match", "", copy.getSimpleDataAttributes());
83 }});
84 }
85 }