1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.impl.peopleflow;
17
18 import org.junit.Test;
19 import org.kuali.rice.core.api.delegation.DelegationType;
20 import org.kuali.rice.core.api.membership.MemberType;
21 import org.kuali.rice.kew.api.action.ActionRequestPolicy;
22 import org.kuali.rice.kew.impl.type.KewAttributeDefinitionBo;
23 import org.kuali.rice.kew.impl.type.KewTypeAttributeBo;
24 import org.kuali.rice.kew.impl.type.KewTypeBo;
25 import org.kuali.rice.kew.responsibility.service.ResponsibilityIdService;
26 import org.kuali.rice.kew.service.KEWServiceLocator;
27 import org.kuali.rice.kew.test.KEWTestCase;
28 import org.kuali.rice.krad.service.BusinessObjectService;
29 import org.kuali.rice.krad.service.KRADServiceLocator;
30
31 import java.util.HashMap;
32 import java.util.Map;
33
34 import static org.junit.Assert.*;
35 import static org.junit.Assert.assertEquals;
36
37
38
39
40 public class PeopleFlowBoTest extends KEWTestCase {
41
42 private BusinessObjectService boService;
43 private ResponsibilityIdService responsibilityIdService;
44
45 @org.junit.Before
46 public void setupBoService() {
47 boService = KRADServiceLocator.getBusinessObjectService();
48 responsibilityIdService = KEWServiceLocator.getResponsibilityIdService();
49 }
50
51 @Test
52 public void testKewTypeBoBasicPersist() {
53 KewTypeBoBuilder builder = new KewTypeBoBuilder("testType", "testNamespace");
54
55 boService.save(builder.build());
56 try {
57
58 boService.save(builder.build());
59 fail("this should violate unique constraints");
60 } catch (Exception e) {
61
62 }
63 }
64 @Test
65 public void testKewTypeBoFullPersist() {
66 KewTypeBoBuilder builder = new KewTypeBoBuilder("testType", "testNamespace").setServiceName("testService");
67 KewTypeBo kewTypeBo = builder.build();
68
69 for (int i=1; i<=3; i++) {
70 KewAttributeDefinitionBo attributeDefn = new KewAttributeDefinitionBo();
71 attributeDefn.setName("attrDef"+i);
72 attributeDefn.setDescription("this is a description of attrDef" + i);
73 attributeDefn.setComponentName("componentName" + i);
74 attributeDefn.setLabel("label" + i);
75 attributeDefn.setNamespace(kewTypeBo.getNamespace());
76
77 boService.save(attributeDefn);
78
79 KewTypeAttributeBo typeAttribute = new KewTypeAttributeBo();
80 typeAttribute.setSequenceNumber(i);
81 typeAttribute.setAttributeDefinition(attributeDefn);
82 kewTypeBo.getAttributes().add(typeAttribute);
83 }
84
85 boService.save(kewTypeBo);
86 }
87
88 @Test
89 public void testPeopleFlowPersonMembers() {
90 PeopleFlowMemberBo peopleFlowMember = new PeopleFlowMemberBo();
91 peopleFlowMember.setMemberType(MemberType.PRINCIPAL);
92 peopleFlowMember.setMemberId("admin");
93 peopleFlowMember.setPriority(1);
94 peopleFlowMember.setResponsibilityId(responsibilityIdService.getNewResponsibilityId());
95 assertNotNull(peopleFlowMember.getPerson());
96 assertEquals("admin", peopleFlowMember.getPerson().getPrincipalName());
97
98 PeopleFlowDelegateBo peopleFlowDelegate = new PeopleFlowDelegateBo();
99 peopleFlowDelegate.setMemberType(MemberType.PRINCIPAL);
100 peopleFlowDelegate.setMemberId("admin");
101 peopleFlowDelegate.setDelegationTypeCode(DelegationType.PRIMARY.getCode());
102 peopleFlowDelegate.setResponsibilityId(responsibilityIdService.getNewResponsibilityId());
103 assertNotNull(peopleFlowDelegate.getPerson());
104 assertEquals("admin", peopleFlowDelegate.getPerson().getPrincipalName());
105 }
106
107 @Test
108 public void testPeopleFlowBoPersist() {
109 testKewTypeBoFullPersist();
110
111 Map<String,String> keysMap = new HashMap<String, String>();
112 keysMap.put("name", "testType");
113 keysMap.put("namespace", "testNamespace");
114
115 KewTypeBo kewTypeBo = boService.findByPrimaryKey(KewTypeBo.class, keysMap);
116
117
118 PeopleFlowBo peopleFlowBo = new PeopleFlowBo();
119 peopleFlowBo.setDescription("description of testPeopleFlow");
120 peopleFlowBo.setName("testPeopleFlow");
121 peopleFlowBo.setNamespaceCode("testNamespace");
122 peopleFlowBo.setTypeId(kewTypeBo.getId());
123
124 boService.save(peopleFlowBo);
125
126
127 KewTypeAttributeBo attribute = kewTypeBo.getAttributes().get(0);
128
129 PeopleFlowAttributeBo peopleFlowAttr = new PeopleFlowAttributeBo();
130 peopleFlowAttr.setAttributeDefinition(attribute.getAttributeDefinition());
131 peopleFlowAttr.setPeopleFlowId(peopleFlowBo.getId());
132 peopleFlowAttr.setValue("testAttrValue");
133
134 peopleFlowBo.getAttributeBos().add(peopleFlowAttr);
135
136 PeopleFlowMemberBo peopleFlowMember = new PeopleFlowMemberBo();
137 peopleFlowMember.setMemberType(MemberType.PRINCIPAL);
138 peopleFlowMember.setMemberId("admin");
139 peopleFlowMember.setPriority(1);
140 peopleFlowMember.setResponsibilityId(responsibilityIdService.getNewResponsibilityId());
141
142 peopleFlowBo.getMembers().add(peopleFlowMember);
143
144 PeopleFlowDelegateBo peopleFlowDelegate1 = new PeopleFlowDelegateBo();
145 peopleFlowDelegate1.setMemberType(MemberType.GROUP);
146 peopleFlowDelegate1.setMemberId("1");
147 peopleFlowDelegate1.setDelegationTypeCode(DelegationType.PRIMARY.getCode());
148 peopleFlowDelegate1.setResponsibilityId(responsibilityIdService.getNewResponsibilityId());
149 peopleFlowMember.getDelegates().add(peopleFlowDelegate1);
150
151 PeopleFlowDelegateBo peopleFlowDelegate2 = new PeopleFlowDelegateBo();
152 peopleFlowDelegate2.setMemberType(MemberType.ROLE);
153 peopleFlowDelegate2.setMemberId("2");
154 peopleFlowDelegate2.setActionRequestPolicyCode(ActionRequestPolicy.FIRST.getCode());
155 peopleFlowDelegate2.setDelegationTypeCode(DelegationType.SECONDARY.getCode());
156 peopleFlowDelegate2.setResponsibilityId(responsibilityIdService.getNewResponsibilityId());
157 peopleFlowMember.getDelegates().add(peopleFlowDelegate2);
158
159 boService.save(peopleFlowBo);
160
161 assertNotNull(peopleFlowBo.getId());
162 peopleFlowBo = boService.findBySinglePrimaryKey(PeopleFlowBo.class, peopleFlowBo.getId());
163
164 assertNotNull(peopleFlowBo);
165 assertNotNull(peopleFlowBo.getId());
166 assertTrue(peopleFlowBo.getMembers().size() == 1);
167
168 PeopleFlowMemberBo memberBo = peopleFlowBo.getMembers().get(0);
169 assertNotNull(memberBo.getId());
170 assertEquals(peopleFlowBo.getId(), memberBo.getPeopleFlowId());
171 assertEquals("admin", memberBo.getMemberId());
172 assertEquals(MemberType.PRINCIPAL, memberBo.getMemberType());
173 assertNotNull(memberBo.getPerson());
174 assertEquals("admin", memberBo.getPerson().getPrincipalName());
175 assertEquals(peopleFlowMember.getResponsibilityId(), memberBo.getResponsibilityId());
176 assertSame(1, memberBo.getPriority());
177 assertTrue(memberBo.getDelegates().size() == 2);
178
179 PeopleFlowDelegateBo delegateBo1 = memberBo.getDelegates().get(0);
180 assertNotNull(delegateBo1.getId());
181 assertEquals(memberBo.getId(), delegateBo1.getPeopleFlowMemberId());
182 assertEquals("1", delegateBo1.getMemberId());
183 assertEquals(MemberType.GROUP, delegateBo1.getMemberType());
184 assertEquals(DelegationType.PRIMARY.getCode(), delegateBo1.getDelegationTypeCode());
185 assertEquals(peopleFlowDelegate1.getResponsibilityId(), delegateBo1.getResponsibilityId());
186 assertNull(delegateBo1.getActionRequestPolicyCode());
187
188 PeopleFlowDelegateBo delegateBo2 = memberBo.getDelegates().get(1);
189 assertNotNull(delegateBo2.getId());
190 assertEquals(memberBo.getId(), delegateBo2.getPeopleFlowMemberId());
191 assertEquals("2", delegateBo2.getMemberId());
192 assertEquals(MemberType.ROLE, delegateBo2.getMemberType());
193 assertEquals(DelegationType.SECONDARY.getCode(), delegateBo2.getDelegationTypeCode());
194 assertEquals(peopleFlowDelegate2.getResponsibilityId(), delegateBo2.getResponsibilityId());
195 assertEquals(ActionRequestPolicy.FIRST.getCode(), delegateBo2.getActionRequestPolicyCode());
196 }
197
198 public static KewTypeBo buildMinimalKewTypeBo() {
199 KewTypeBo kewTypeBo = new KewTypeBo();
200 kewTypeBo.setName("TestType");
201 kewTypeBo.setNamespace("TestNamespace");
202 return kewTypeBo;
203 }
204
205 private static class KewTypeBoBuilder {
206
207 private boolean active = true;
208 private String name;
209 private String namespace;
210 private String serviceName;
211
212 public KewTypeBoBuilder(String name, String namespace) {
213 this.name = name;
214 this.namespace = namespace;
215 }
216
217 public KewTypeBoBuilder setServiceName(String serviceName) {
218 this.serviceName = serviceName;
219 return this;
220 }
221
222 public KewTypeBoBuilder setName(String name) {
223 this.name = name;
224 return this;
225 }
226
227 public KewTypeBoBuilder setNamespace(String namespace) {
228 this.namespace = namespace;
229 return this;
230 }
231
232 public KewTypeBoBuilder setActive(boolean active) {
233 this.active = active;
234 return this;
235 }
236
237 public KewTypeBo build() {
238 KewTypeBo kewTypeBo = new KewTypeBo();
239 kewTypeBo.setActive(active);
240 kewTypeBo.setName(name);
241 kewTypeBo.setNamespace(namespace);
242 kewTypeBo.setServiceName(serviceName);
243 return kewTypeBo;
244 }
245 }
246
247 }