1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.impl.common;
17
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.kuali.rice.kim.api.common.attribute.KimAttribute;
21 import org.kuali.rice.kim.api.common.attribute.KimAttributeContract;
22 import org.kuali.rice.kim.api.type.KimType;
23 import org.kuali.rice.kim.api.type.KimTypeAttributeContract;
24 import org.kuali.rice.kim.api.type.KimTypeContract;
25 import org.kuali.rice.kim.api.type.KimTypeInfoService;
26 import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo;
27 import org.kuali.rice.kim.impl.group.GroupAttributeBo;
28 import org.kuali.rice.kim.impl.type.KimTypeBo;
29
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34
35 import static org.junit.Assert.*;
36 import static org.mockito.Mockito.*;
37
38
39 public class KimAttributeDataBoTest {
40
41 private static KimTypeContract mockKimTypeContract;
42 private static KimAttributeContract mockKimAttributeContract;
43
44 private KimTypeInfoService mockInfoService;
45
46 private static KimType create() {
47 return KimType.Builder.create(mockKimTypeContract).build();
48 }
49
50 private static KimAttribute createKimAttribute() {
51 return KimAttribute.Builder.create(mockKimAttributeContract).build();
52 }
53
54 @Before
55 public void setup() throws Exception {
56
57 mockKimAttributeContract = mock(KimAttributeContract.class);
58 {
59 Long versionNumber = 1L;
60 String attributeName = "one";
61 String namespaceCode = "namespaceCode";
62 String id = "id_one";
63 when( mockKimAttributeContract.getVersionNumber()).thenReturn(versionNumber);
64 when( mockKimAttributeContract.getAttributeName()).thenReturn(attributeName);
65 when( mockKimAttributeContract.getNamespaceCode()).thenReturn(namespaceCode);
66 when( mockKimAttributeContract.getId() ).thenReturn(id);
67 }
68
69 KimTypeAttributeContract one = mock(KimTypeAttributeContract.class);
70 {
71 String id = "one";
72 Long versionNumber = 1L;
73 KimAttribute attribute = createKimAttribute();
74 when(one.getKimAttribute()).thenReturn(attribute);
75 when(one.getId()).thenReturn(id);
76 when(one.getVersionNumber()).thenReturn(versionNumber);
77 }
78
79
80 mockKimTypeContract = mock(KimTypeContract.class);
81 {
82 String id = new String("27");
83 String serviceName = "barService";
84 String namespaceCode ="NAMESPACE CODE";
85 String name = "mock Kim Type Contract";
86 Long versionNumber = 1L;
87 String objectId = "1";
88 List attributeDefinitions = new ArrayList<KimTypeAttributeContract>();
89 attributeDefinitions.add(one);
90 when(mockKimTypeContract.getId()).thenReturn(id);
91 when(mockKimTypeContract.getServiceName()).thenReturn(serviceName);
92 when(mockKimTypeContract.getNamespaceCode()).thenReturn(namespaceCode);
93 when(mockKimTypeContract.getName()).thenReturn(name);
94 when(mockKimTypeContract.getVersionNumber()).thenReturn(versionNumber);
95 when(mockKimTypeContract.getObjectId()).thenReturn(objectId);
96 when(mockKimTypeContract.getAttributeDefinitions()).thenReturn(attributeDefinitions);
97 }
98
99 KimType kimType = create();
100 mockInfoService = mock(KimTypeInfoService.class);
101 {
102 when( mockInfoService.getKimType(anyString()) ).thenReturn(kimType);
103 }
104
105 }
106
107 @Test
108 public void testKimAttributeDataBo() {
109 KimType kimType = create();
110 Map<String,String> attributes = new HashMap<String,String>();
111 attributes.put("one","one");
112
113 String kimTypeId = "27";
114
115 assertEquals(kimType.getId(), "27");
116
117 KimAttributeDataBo.setKimTypeInfoService(mockInfoService);
118
119 GroupAttributeBo groupQualifier = KimAttributeDataBo.createFrom(GroupAttributeBo.class, attributes, kimTypeId).get(0);
120
121 assertNotNull(groupQualifier.getKimType());
122 assertEquals(groupQualifier.getKimType().getId(), KimTypeBo.from(kimType).getId());
123
124 }
125
126 }