/
TestUserTemplateWithRanges.java
377 lines (316 loc) · 13.6 KB
/
TestUserTemplateWithRanges.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.model.intest;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.builder.DeltaBuilder;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;
import javax.xml.namespace.QName;
import java.io.File;
/**
* User template with "mapping range" features.
*
* @author mederly
*
*/
@ContextConfiguration(locations = {"classpath:ctx-model-intest-test-main.xml"})
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestUserTemplateWithRanges extends AbstractInitializedModelIntegrationTest {
public static final File TEST_DIR = new File("src/test/resources/object-template-ranges");
public static final QName MANAGER_ID_QNAME = new QName("http://sample.evolveum.com/xml/ns/sample-idm/extension", "managerId");
protected static final File ORG_MONKEY_ISLAND_LOCAL_FILE = new File(TEST_DIR, "org-monkey-island-local.xml");
protected static final File USER_TEMPLATE_RANGES_FILE = new File(TEST_DIR, "user-template-ranges.xml");
protected static final String USER_TEMPLATE_RANGES_OID = "f486e3a7-6970-416e-8fe2-995358f59c46";
@Override
protected boolean doAddOrgstruct() {
return false; // we use our own
}
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
repoAddObjectsFromFile(ORG_MONKEY_ISLAND_LOCAL_FILE, OrgType.class, initResult);
repoAddObjectFromFile(USER_TEMPLATE_RANGES_FILE, initResult);
setDefaultObjectTemplate(UserType.COMPLEX_TYPE, USER_TEMPLATE_RANGES_OID, initResult);
changeEmployeeIdRaw("EM100", initTask, initResult);
}
/**
* Recomputation should give Elaine a manager-type assignment to Gov office.
*/
@Test
public void test100RecomputeElaine() throws Exception {
final String TEST_NAME = "test100RecomputeElaine";
TestUtil.displayTestTitle(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestUserTemplateWithRanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
recomputeUser(USER_ELAINE_OID, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userElaine = getUser(USER_ELAINE_OID);
display("elaine after recompute", userElaine);
assertAssignedOrg(userElaine, ORG_GOVERNOR_OFFICE_OID, SchemaConstants.ORG_MANAGER);
assertHasOrg(userElaine, ORG_GOVERNOR_OFFICE_OID, SchemaConstants.ORG_MANAGER);
}
/**
* After changing manager info in Gov office org,
* recomputation should remove Elaine a manager-type assignment to Gov office.
*/
@Test
public void test110ChangeManagerAndRecomputeElaine() throws Exception {
final String TEST_NAME = "test110ChangeManagerAndRecomputeElaine";
TestUtil.displayTestTitle(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestUserTemplateWithRanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
changeManagerRaw("xxxxx", task, result);
recomputeUser(USER_ELAINE_OID, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userElaine = getUser(USER_ELAINE_OID);
display("elaine after change manager ID + recompute", userElaine);
assertNotAssignedOrg(userElaine, ORG_GOVERNOR_OFFICE_OID, SchemaConstants.ORG_MANAGER);
assertHasNoOrg(userElaine); // this is even stronger
}
/**
* After setting manager in Gov office org back to EM100,
* recomputation should add Elaine a manager-type assignment to Gov office.
* In addition, we made her a member of Gov office as a preparation for test130.
*/
@Test
public void test120RestoreManagerAndRecomputeElaineAgain() throws Exception {
final String TEST_NAME = "test120RestoreManagerAndRecomputeElaineAgain";
TestUtil.displayTestTitle(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestUserTemplateWithRanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assignOrg(USER_ELAINE_OID, ORG_GOVERNOR_OFFICE_OID, null);
// WHEN
changeManagerRaw("EM100", task, result);
recomputeUser(USER_ELAINE_OID, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userElaine = getUser(USER_ELAINE_OID);
display("elaine after restore of manager ID + recompute", userElaine);
assertAssignedOrg(userElaine, ORG_GOVERNOR_OFFICE_OID, SchemaConstants.ORG_MANAGER);
assertAssignedOrg(userElaine, ORG_GOVERNOR_OFFICE_OID, null);
assertHasOrg(userElaine, ORG_GOVERNOR_OFFICE_OID, SchemaConstants.ORG_MANAGER);
assertHasOrg(userElaine, ORG_GOVERNOR_OFFICE_OID, null);
}
/**
* After changing manager info in Gov office org again,
* recomputation should remove Elaine a manager-type assignment to Gov office.
* But it should keep her as a member.
*/
@Test
public void test140ChangeManagerAndRecomputeElaineAgain() throws Exception {
final String TEST_NAME = "test140ChangeManagerAndRecomputeElaineAgain";
TestUtil.displayTestTitle(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestUserTemplateWithRanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
changeManagerRaw("xxxxx", task, result);
recomputeUser(USER_ELAINE_OID, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userElaine = getUser(USER_ELAINE_OID);
display("elaine after change of manager ID + recompute", userElaine);
assertNotAssignedOrg(userElaine, ORG_GOVERNOR_OFFICE_OID, SchemaConstants.ORG_MANAGER);
assertAssignedOrg(userElaine, ORG_GOVERNOR_OFFICE_OID);
assertHasNoOrg(userElaine, ORG_GOVERNOR_OFFICE_OID, SchemaConstants.ORG_MANAGER);
assertHasOrg(userElaine, ORG_GOVERNOR_OFFICE_OID);
}
/*
* 2xx series: testing ranges with conditions
* ==========================================
*/
/**
* Simple add values, nothing special. (Preparing ground for next test.)
*/
@Test
public void test200SimpleOrgUnitAddition() throws Exception {
final String TEST_NAME = "test200SimpleOrgUnitAddition";
TestUtil.displayTestTitle(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestUserTemplateWithRanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
executeChanges(
(ObjectDelta) DeltaBuilder.deltaFor(UserType.class, prismContext)
.item(UserType.F_ORGANIZATIONAL_UNIT).add(
PolyString.fromOrig("U1"),
PolyString.fromOrig("U2"),
PolyString.fromOrig("U3"),
PolyString.fromOrig("U4"))
.item(UserType.F_ORGANIZATION).add(PolyString.fromOrig("O1"))
.asObjectDelta(USER_JACK_OID),
null, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("jack", userJack);
PrismAsserts.assertPropertyValue(userJack, UserType.F_ORGANIZATIONAL_UNIT,
new PolyString("U1", "u1"),
new PolyString("U2", "u2"),
new PolyString("U3", "u3"),
new PolyString("U4", "u4"));
PrismAsserts.assertPropertyValue(userJack, UserType.F_ORGANIZATION,
new PolyString("O1", "o1"),
new PolyString("OU: U1 emp1234", "ou u1 emp1234"),
new PolyString("OU: U2 emp1234", "ou u2 emp1234"),
new PolyString("OU: U3 emp1234", "ou u3 emp1234"),
new PolyString("OU: U4 emp1234", "ou u4 emp1234"));
}
/**
* OrganizationalUnit U1 disappearing + recompute. Computed value of 'OU: U1 ...' should be removed.
* Note that condition is true -> true.
*/
@Test
public void test210RemoveUnit1() throws Exception {
final String TEST_NAME = "test210RemoveUnit1";
TestUtil.displayTestTitle(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestUserTemplateWithRanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
executeChanges(
(ObjectDelta) DeltaBuilder.deltaFor(UserType.class, prismContext)
.item(UserType.F_ORGANIZATIONAL_UNIT).delete(PolyString.fromOrig("U1"))
.asObjectDelta(USER_JACK_OID),
ModelExecuteOptions.createRaw(), task, result);
recomputeUser(USER_JACK_OID, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("jack", userJack);
PrismAsserts.assertPropertyValue(userJack, UserType.F_ORGANIZATIONAL_UNIT,
new PolyString("U2", "u2"),
new PolyString("U3", "u3"),
new PolyString("U4", "u4"));
PrismAsserts.assertPropertyValue(userJack, UserType.F_ORGANIZATION,
new PolyString("O1", "o1"),
new PolyString("OU: U2 emp1234", "ou u2 emp1234"),
new PolyString("OU: U3 emp1234", "ou u3 emp1234"),
new PolyString("OU: U4 emp1234", "ou u4 emp1234"));
}
/**
* OrganizationalUnit U2 disappearing.
* Then, along with recompute we erase employeeNumber.
* Mapping 'ceases to exist' and all of its range should be deleted.
* Condition: true -> false
*/
@Test
public void test220RemoveUnit2AndNumber() throws Exception {
final String TEST_NAME = "test220RemoveUnit2AndNumber";
TestUtil.displayTestTitle(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestUserTemplateWithRanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
executeChanges(
(ObjectDelta) DeltaBuilder.deltaFor(UserType.class, prismContext)
.item(UserType.F_ORGANIZATIONAL_UNIT).delete(PolyString.fromOrig("U2"))
.asObjectDelta(USER_JACK_OID),
ModelExecuteOptions.createRaw(), task, result);
executeChanges(
(ObjectDelta) DeltaBuilder.deltaFor(UserType.class, prismContext)
.item(UserType.F_EMPLOYEE_NUMBER).replace()
.asObjectDelta(USER_JACK_OID),
null, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("jack", userJack);
PrismAsserts.assertPropertyValue(userJack, UserType.F_ORGANIZATIONAL_UNIT,
new PolyString("U3", "u3"),
new PolyString("U4", "u4"));
PrismAsserts.assertPropertyValue(userJack, UserType.F_ORGANIZATION,
new PolyString("O1", "o1"));
}
/**
* Introduced OU: nonsense.
* Restoring employeeNumber.
* All missing 'OU: *' should be re-added, 'OU: nonsense' should be removed.
* Condition: false -> true
*/
@Test
public void test230RestoreNumber() throws Exception {
final String TEST_NAME = "test230RestoreNumber";
TestUtil.displayTestTitle(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestUserTemplateWithRanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
executeChanges(
(ObjectDelta) DeltaBuilder.deltaFor(UserType.class, prismContext)
.item(UserType.F_ORGANIZATION).add(PolyString.fromOrig("OU: nonsense"))
.asObjectDelta(USER_JACK_OID),
ModelExecuteOptions.createRaw(), task, result);
executeChanges(
(ObjectDelta) DeltaBuilder.deltaFor(UserType.class, prismContext)
.item(UserType.F_EMPLOYEE_NUMBER).replace("emp1234")
.asObjectDelta(USER_JACK_OID),
null, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("jack", userJack);
PrismAsserts.assertPropertyValue(userJack, UserType.F_ORGANIZATIONAL_UNIT,
new PolyString("U3", "u3"),
new PolyString("U4", "u4"));
PrismAsserts.assertPropertyValue(userJack, UserType.F_ORGANIZATION,
new PolyString("O1", "o1"),
new PolyString("OU: U3 emp1234", "ou u3 emp1234"),
new PolyString("OU: U4 emp1234", "ou u4 emp1234"));
}
private void changeManagerRaw(String id, Task task, OperationResult result) throws CommonException {
executeChanges(
(ObjectDelta) DeltaBuilder.deltaFor(OrgType.class, prismContext)
.item(OrgType.F_EXTENSION, MANAGER_ID_QNAME).replace(id)
.asObjectDelta(ORG_GOVERNOR_OFFICE_OID),
ModelExecuteOptions.createRaw(), task, result);
}
private void changeEmployeeIdRaw(String id, Task initTask, OperationResult initResult) throws CommonException {
executeChanges(
(ObjectDelta) DeltaBuilder.deltaFor(UserType.class, prismContext)
.item(UserType.F_EMPLOYEE_NUMBER).replace(id)
.asObjectDelta(USER_ELAINE_OID),
ModelExecuteOptions.createRaw(), initTask, initResult);
}
}