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.Before;
19 import org.junit.Test;
20 import org.kuali.rice.core.api.membership.MemberType;
21 import org.kuali.rice.kew.api.KewApiServiceLocator;
22 import org.kuali.rice.kew.api.peopleflow.PeopleFlowDefinition;
23 import org.kuali.rice.kew.api.peopleflow.PeopleFlowMember;
24 import org.kuali.rice.kew.api.peopleflow.PeopleFlowService;
25 import org.kuali.rice.kew.test.KEWTestCase;
26 import org.kuali.rice.kim.api.group.Group;
27 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
28 import org.kuali.rice.test.BaselineTestCase;
29
30 import java.util.Iterator;
31
32 import static org.junit.Assert.*;
33
34
35
36
37
38
39 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.CLEAR_DB)
40 public class PeopleFlowServiceTest extends KEWTestCase {
41
42 private static final String NAMESPACE_CODE = "MyNamespace";
43 private static final String NAME = "MyFlow";
44
45 private static final String NAME2 = "MyFlowUpdate";
46 private static final String DESCRIPTION = "Description after update";
47
48 private PeopleFlowService peopleFlowService;
49
50 @Before
51 public void setupServiceUnderTest() {
52 setPeopleFlowService(KewApiServiceLocator.getPeopleFlowService());
53 }
54
55 protected void setPeopleFlowService(PeopleFlowService peopleFlowService) {
56 this.peopleFlowService = peopleFlowService;
57 }
58
59 protected PeopleFlowService getPeopleFlowService() {
60 return peopleFlowService;
61 }
62
63 @Test
64 public void testCRUD() throws Exception {
65
66
67 PeopleFlowDefinition.Builder builder = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, NAME);
68 PeopleFlowMember.Builder memberBuilder = PeopleFlowMember.Builder.create("admin", MemberType.PRINCIPAL);
69 memberBuilder.setPriority(1);
70 builder.getMembers().add(memberBuilder);
71 Group group = KimApiServiceLocator.getGroupService().getGroupByNamespaceCodeAndName("KR-WKFLW", "TestWorkgroup");
72 memberBuilder = PeopleFlowMember.Builder.create(group.getId(), MemberType.GROUP);
73 memberBuilder.setPriority(2);
74 builder.getMembers().add(memberBuilder);
75
76
77 PeopleFlowDefinition peopleFlow = getPeopleFlowService().createPeopleFlow(builder.build());
78 assertPeopleFlowCreate(peopleFlow, group);
79
80
81 peopleFlow = getPeopleFlowService().getPeopleFlow(peopleFlow.getId());
82 assertPeopleFlowCreate(peopleFlow, group);
83
84
85 peopleFlow = getPeopleFlowService().getPeopleFlowByName(NAMESPACE_CODE, NAME);
86 assertPeopleFlowCreate(peopleFlow, group);
87
88
89 builder = PeopleFlowDefinition.Builder.create(peopleFlow);
90 builder.setName(NAME2);
91
92 for (Iterator<PeopleFlowMember.Builder> iterator = builder.getMembers().iterator(); iterator.hasNext();) {
93 PeopleFlowMember.Builder member = iterator.next();
94 if (member.getMemberType() == MemberType.GROUP) {
95 iterator.remove();
96 }
97 }
98
99 PeopleFlowMember.Builder adminMember = builder.getMembers().get(0);
100 assertEquals(1, builder.getMembers().size());
101 memberBuilder = PeopleFlowMember.Builder.create("ewestfal", MemberType.PRINCIPAL);
102 builder.getMembers().add(memberBuilder);
103 builder.setDescription(DESCRIPTION);
104
105
106 PeopleFlowDefinition updatedPeopleFlow = getPeopleFlowService().updatePeopleFlow(builder.build());
107 updatedPeopleFlow = getPeopleFlowService().getPeopleFlow(updatedPeopleFlow.getId());
108 assertNotNull(updatedPeopleFlow);
109 assertEquals(NAME2, updatedPeopleFlow.getName());
110 assertEquals(DESCRIPTION, updatedPeopleFlow.getDescription());
111 assertEquals("Ids should be the same", peopleFlow.getId(), updatedPeopleFlow.getId());
112 assertEquals("Version number should be one higher", new Long(peopleFlow.getVersionNumber() + 1),
113 updatedPeopleFlow.getVersionNumber());
114 assertEquals("Should have 2 members", 2, updatedPeopleFlow.getMembers().size());
115
116
117 for (PeopleFlowMember member : updatedPeopleFlow.getMembers()) {
118 assertTrue("should not have any delegates", member.getDelegates().isEmpty());
119 assertEquals(MemberType.PRINCIPAL, member.getMemberType());
120 assertEquals(1, member.getPriority());
121 if (!(member.getMemberId().equals("admin") || member.getMemberId().equals("ewestfal"))) {
122 fail("Encountered a member that shouldn't exist! " + member.getMemberId());
123 }
124 }
125
126 }
127
128 private void assertPeopleFlowCreate(PeopleFlowDefinition peopleFlow, Group groupMember) {
129 assertNotNull(peopleFlow);
130 assertNotNull(peopleFlow.getId());
131 assertEquals(2, peopleFlow.getMembers().size());
132
133 for (PeopleFlowMember member : peopleFlow.getMembers()) {
134 assertTrue("should not have any delegates", member.getDelegates().isEmpty());
135 if (MemberType.PRINCIPAL == member.getMemberType()) {
136 assertEquals(1, member.getPriority());
137 assertEquals("admin", member.getMemberId());
138 } else if (MemberType.GROUP == member.getMemberType()) {
139 assertEquals(2, member.getPriority());
140 assertEquals(groupMember.getId(), member.getMemberId());
141 } else {
142 fail("Invalid member found!");
143 }
144 }
145
146 assertTrue("should have no attributes", peopleFlow.getAttributes().isEmpty());
147 assertNull("description should be null", peopleFlow.getDescription());
148 assertEquals(NAMESPACE_CODE, peopleFlow.getNamespaceCode());
149 assertEquals(NAME, peopleFlow.getName());
150 assertNull(peopleFlow.getTypeId());
151 assertTrue(peopleFlow.isActive());
152 assertNotNull("should have a non-null version number", peopleFlow.getVersionNumber());
153 }
154
155
156 }