-
Notifications
You must be signed in to change notification settings - Fork 188
/
TestWrapperDelta.java
535 lines (403 loc) · 27.9 KB
/
TestWrapperDelta.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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
/*
* Copyright (c) 2010-2019 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.gui;
import com.evolveum.midpoint.gui.api.prism.ItemStatus;
import com.evolveum.midpoint.gui.api.prism.PrismContainerWrapper;
import com.evolveum.midpoint.gui.api.prism.PrismObjectWrapper;
import com.evolveum.midpoint.gui.api.util.ModelServiceLocator;
import com.evolveum.midpoint.gui.api.util.WebPrismUtil;
import com.evolveum.midpoint.gui.impl.factory.PrismObjectWrapperFactory;
import com.evolveum.midpoint.gui.impl.factory.ProfilingClassLoggerWrapperFactoryImpl;
import com.evolveum.midpoint.gui.impl.factory.WrapperContext;
import com.evolveum.midpoint.gui.impl.prism.PrismContainerValueWrapper;
import com.evolveum.midpoint.gui.impl.prism.PrismPropertyValueWrapper;
import com.evolveum.midpoint.gui.impl.prism.PrismPropertyWrapper;
import com.evolveum.midpoint.gui.test.TestMidPointSpringApplication;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.equivalence.ParameterizedEquivalenceStrategy;
import com.evolveum.midpoint.prism.impl.PrismPropertyValueImpl;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.asserter.UserAsserter;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest;
import com.evolveum.midpoint.web.component.prism.ValueStatus;
import com.evolveum.midpoint.web.page.admin.reports.dto.ReportDeleteDialogDto;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import com.evolveum.prism.xml.ns._public.types_3.ModificationTypeType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.testng.AssertJUnit;
import org.testng.annotations.Test;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import java.io.File;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import static org.testng.AssertJUnit.*;
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@ActiveProfiles("test")
@SpringBootTest(classes = TestMidPointSpringApplication.class)
public class TestWrapperDelta extends AbstractInitializedGuiIntegrationTest {
private static final String TEST_DIR = "src/test/resources/delta";
private static final File USER_ELAINE = new File(TEST_DIR, "user-elaine.xml");
private static final String USER_ELAINE_OID = "00998628-b2fd-11e5-88c0-4f82a8602266";
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
importObjectFromFile(USER_ELAINE, initTask, initResult);
}
@Test
public void test100modifyUserFullname() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
PrismObject<UserType> userElaineBefore = getUser(USER_ELAINE_OID);
WrapperContext ctx = new WrapperContext(task, result);
PrismObjectWrapper objectWrapper =createObjectWrapper(userElaineBefore, ItemStatus.NOT_CHANGED, ctx);
PrismPropertyWrapper<PolyString> fullName = objectWrapper.findProperty(UserType.F_FULL_NAME);
fullName.getValue().setRealValue(PrismTestUtil.createPolyString("Sparrow-Marley"));
//GIVEN
ObjectDelta<UserType> elaineDelta = objectWrapper.getObjectDelta();
assertModificationsSize(elaineDelta, 1);
assertModification(elaineDelta, UserType.F_FULL_NAME, ModificationTypeType.REPLACE, PrismTestUtil.createPolyString("Sparrow-Marley"));
//WHEN
executeChanges(elaineDelta, null, task, result);
//THEN
PrismObject<UserType> userElaineAfter = getUser(USER_ELAINE_OID);
UserAsserter.forUser(userElaineAfter).assertFullName("Sparrow-Marley");
}
@Test
public void test101modifyUserWeapon() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
PrismObject<UserType> userElaineBefore = getUser(USER_ELAINE_OID);
WrapperContext ctx = new WrapperContext(task, result);
PrismObjectWrapper objectWrapper =createObjectWrapper(userElaineBefore, ItemStatus.NOT_CHANGED, ctx);
PrismPropertyWrapper<String> weapon = objectWrapper.findProperty(ItemPath.create(UserType.F_EXTENSION, PIRACY_WEAPON));
for (PrismPropertyValueWrapper<String> valueWrapper : weapon.getValues()) {
valueWrapper.setRealValue(null);
}
ModelServiceLocator locator = getServiceLocator(task);
PrismPropertyValueWrapper<String> newValue = locator.createValueWrapper(weapon, new PrismPropertyValueImpl("revolver"), ValueStatus.ADDED, ctx);
weapon.getValues().add(newValue);
ObjectDelta<UserType> elaineDelta = objectWrapper.getObjectDelta();
assertModificationsSize(elaineDelta, 1);
assertModification(elaineDelta, ItemPath.create(UserType.F_EXTENSION, PIRACY_WEAPON), ModificationTypeType.ADD, "revolver");
assertModification(elaineDelta, ItemPath.create(UserType.F_EXTENSION, PIRACY_WEAPON), ModificationTypeType.DELETE, "pistol", "mouth");
executeChanges(elaineDelta, null, task, result);
PrismObject<UserType> userElaineAfter = getUser(USER_ELAINE_OID);
logger.info("ELAINE AFTER: {}", userElaineAfter.debugDump());
UserAsserter.forUser(userElaineAfter).extension().assertPropertyValuesEqual(PIRACY_WEAPON, "revolver");
}
@Test
public void test110modifyUserAddAssignment() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
PrismObject<UserType> userElaineBefore = getUser(USER_ELAINE_OID);
WrapperContext ctx = new WrapperContext(task, result);
PrismObjectWrapper objectWrapper =createObjectWrapper(userElaineBefore, ItemStatus.NOT_CHANGED, ctx);
PrismContainerValue<AssignmentType> newAssignmentClone = createDummyResourceAssignment(objectWrapper, 0, task, result);
ObjectDelta<UserType> delta = objectWrapper.getObjectDelta();
assertModificationsSize(delta, 1);
assertModification(delta, UserType.F_ASSIGNMENT, ModificationTypeType.ADD, newAssignmentClone.asContainerable());
executeChanges(delta, null, task, result);
assertSuccess(result);
PrismObject<UserType> userElaineAfter = getUser(USER_ELAINE_OID);
UserAsserter.forUser(userElaineAfter).assignments().assertAssignments(1);
PrismContainer<AssignmentType> assignmentAfter = userElaineAfter.findContainer(UserType.F_ASSIGNMENT);
List<PrismContainerValue<AssignmentType>> assignmentValues = assignmentAfter.getValues();
assertEquals("Unexpected number of assignments " + assignmentValues.size(), 1, assignmentValues.size());
PrismContainerValue<AssignmentType> assignmentValue = assignmentValues.iterator().next();
assertTrue(newAssignmentClone.equals(assignmentValue, ParameterizedEquivalenceStrategy.IGNORE_METADATA_CONSIDER_DIFFERENT_IDS));
}
@Test
public void test111modifyUserAssignemnt() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
PrismObject<UserType> userElaineBefore = getUser(USER_ELAINE_OID);
WrapperContext ctx = new WrapperContext(task, result);
PrismObjectWrapper<UserType> objectWrapper =createObjectWrapper(userElaineBefore, ItemStatus.NOT_CHANGED, ctx);
PrismContainerWrapper<AssignmentType> assignment = objectWrapper.findContainer(UserType.F_ASSIGNMENT);
assertNotNull("unexpected null assignment wrapper", assignment);
assertEquals("Unexpected values for assignment " + assignment.getValues().size(), 1, assignment.getValues().size());
PrismContainerValueWrapper<AssignmentType> assignmentValue = assignment.getValues().iterator().next();
PrismContainerWrapper<ResourceAttributeDefinitionType> resourceAttrDefWrapper = assignmentValue.findContainer(ItemPath.create(AssignmentType.F_CONSTRUCTION, ConstructionType.F_ATTRIBUTE));
assertNotNull("unexpected null assignment wrapper", resourceAttrDefWrapper);
assertEquals("Unexpected values for assignment " + resourceAttrDefWrapper.getValues().size(), 0, resourceAttrDefWrapper.getValues().size());
ModelServiceLocator locator = getServiceLocator(task);
PrismContainerValue<ResourceAttributeDefinitionType> newAttribute = resourceAttrDefWrapper.getItem().createNewValue();
PrismContainerValueWrapper<ResourceAttributeDefinitionType> resourceAttrDefValueWrapper = locator.createValueWrapper(resourceAttrDefWrapper, newAttribute, ValueStatus.ADDED, ctx);
resourceAttrDefWrapper.getValues().add(resourceAttrDefValueWrapper);
PrismPropertyWrapper<ItemPathType> attributeRefWrapper = resourceAttrDefValueWrapper.findProperty(ResourceAttributeDefinitionType.F_REF);
attributeRefWrapper.getValue().setRealValue(new ItemPathType(ItemPath.create(SchemaConstants.ICFS_NAME)));
PrismPropertyWrapper<QName> matchingRule = resourceAttrDefValueWrapper.findProperty(ResourceAttributeDefinitionType.F_MATCHING_RULE);
matchingRule.getValue().setRealValue(PrismConstants.STRING_IGNORE_CASE_MATCHING_RULE_NAME);
PrismContainerWrapper<MappingType> outbound = resourceAttrDefValueWrapper.findContainer(ResourceAttributeDefinitionType.F_OUTBOUND);
PrismContainerValueWrapper<MappingType> mapping = outbound.getValue();
MappingType mappingType = mapping.getRealValue();
mappingType.setExpression(createAsIsExpression());
ObjectDelta<UserType> delta = objectWrapper.getObjectDelta();
assertModificationsSize(delta, 1);
logger.info("Attr delta: {}", delta.debugDump());
ResourceAttributeDefinitionType expectedvalue = new ResourceAttributeDefinitionType(locator.getPrismContext());
expectedvalue.setRef(new ItemPathType(ItemPath.create(SchemaConstants.ICFS_NAME)));
expectedvalue.setMatchingRule(PrismConstants.STRING_IGNORE_CASE_MATCHING_RULE_NAME);
MappingType expectedMapping = new MappingType();
expectedMapping.setExpression(createAsIsExpression());
expectedvalue.setOutbound(expectedMapping);
assertModification(delta, resourceAttrDefValueWrapper.getPath(), ModificationTypeType.ADD, expectedvalue);
executeChanges(delta, ModelExecuteOptions.createRaw(), task, result);
assertSuccess(result);
PrismObject<UserType> userElaineAfter = getUser(USER_ELAINE_OID);
PrismContainer<AssignmentType> assignmentAfter = userElaineAfter.findContainer(UserType.F_ASSIGNMENT);
assertNotNull("Unexpected null assignment container for " + userElaineAfter, assignmentAfter);
assertEquals("Unexpected number of assignments, " + assignmentAfter.debugDump(), 1, assignmentAfter.getValues().size());
PrismContainerValue<AssignmentType> assignmentTypeAfter = assignmentAfter.getValues().iterator().next();
AssignmentType expected = new AssignmentType(locator.getPrismContext());
ConstructionType constructionType = new ConstructionType(locator.getPrismContext());
ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(resourceDummy.getOid(), ObjectTypes.RESOURCE);
ref.setRelation(SchemaConstants.ORG_DEFAULT);
constructionType.setResourceRef(ref);
constructionType.setKind(ShadowKindType.ACCOUNT);
constructionType.setIntent("default");
constructionType.getAttribute().add(expectedvalue);
expected.setConstruction(constructionType);
ActivationType activationType = new ActivationType(locator.getPrismContext());
activationType.setEffectiveStatus(ActivationStatusType.ENABLED);
expected.setActivation(activationType);
//TODO assertions after
}
@Test
public void test200createUser() throws Exception {
// Task task = getTestTask(); // TODO we don't want customized task here?
Task task = createPlainTask();
OperationResult result = task.getResult();
PrismObjectDefinition<UserType> def = getServiceLocator(task).getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
PrismObject<UserType> user = def.instantiate();
WrapperContext ctx = new WrapperContext(task, result);
PrismObjectWrapper<UserType> userWrapper = createObjectWrapper(user, ItemStatus.ADDED, ctx);
PrismPropertyWrapper<PolyString> username = userWrapper.findProperty(UserType.F_NAME);
username.getValue().setRealValue(PrismTestUtil.createPolyString("guybrush"));
PrismPropertyWrapper<PolyString> fullName = userWrapper.findProperty(UserType.F_FULL_NAME);
fullName.getValue().setRealValue(PrismTestUtil.createPolyString("Guybrush Threepwood"));
PrismPropertyWrapper<ProtectedStringType> password = userWrapper.findProperty(SchemaConstants.PATH_PASSWORD_VALUE);
ProtectedStringType pwd = new ProtectedStringType();
pwd.setClearValue("howMuchWoodWouldWoodchuckChuckIfWoodchuckCouldChuckWood");
password.getValue().setRealValue(pwd);
PrismContainerValue<AssignmentType> newAssignment = createDummyResourceAssignment(userWrapper, 0, task, result);
ObjectDelta<UserType> delta = userWrapper.getObjectDelta();
assertModificationsSize(delta, 0);
PrismObject<UserType> objectToAdd = delta.getObjectToAdd();
assertNotNull("Unexpected null object to add", objectToAdd);
assertUserProperty(objectToAdd, UserType.F_NAME, PrismTestUtil.createPolyString("guybrush"));
assertUserProperty(objectToAdd, UserType.F_FULL_NAME, PrismTestUtil.createPolyString("Guybrush Threepwood"));
UserAsserter.forUser(objectToAdd)
.assertName("guybrush")
.assertFullName("Guybrush Threepwood")
.assertAssignments(1);
PrismProperty<ProtectedStringType> passwordBeforeSave = objectToAdd.findProperty(SchemaConstants.PATH_PASSWORD_VALUE);
assertNotNull("Unexpected null password property", passwordBeforeSave);
assertEquals("Unexpected password in delta: " + passwordBeforeSave.getRealValue(), pwd, passwordBeforeSave.getRealValue());
executeChanges(delta, null, task, result);
PrismObject<UserType> userAfter = findUserByUsername("guybrush");
UserAsserter.forUser(userAfter)
.assertName("guybrush")
.assertFullName("Guybrush Threepwood")
.assertAssignments(1);
}
@Test
public void test300SaveSystemConfigWithoutChanges() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
SystemConfigurationType systemConfig = getSystemConfiguration();
WrapperContext ctx = new WrapperContext(task, result);
PrismObjectWrapper objectWrapper =createObjectWrapper(systemConfig.asPrismContainer(), ItemStatus.NOT_CHANGED, ctx);
//GIVEN
ObjectDelta<UserType> systemConfigDelta = objectWrapper.getObjectDelta();
assertModificationsSize(systemConfigDelta, 0);
}
@Test
public void test301ModifyProfilingClassLoggerOfSystemConfig() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
SystemConfigurationType systemConfigBefore = getSystemConfiguration();
WrapperContext ctx = new WrapperContext(task, result);
PrismObjectWrapper objectWrapper = createObjectWrapper(systemConfigBefore.asPrismContainer(), ItemStatus.NOT_CHANGED, ctx);
PrismContainerWrapper<LoggingConfigurationType> loggingConfig = objectWrapper.findContainer(SystemConfigurationType.F_LOGGING);
PrismContainerWrapper<Containerable> profilingClassLogger = loggingConfig.findContainer(ItemName.fromQName(ProfilingClassLoggerWrapperFactoryImpl.PROFILING_LOGGER_PATH));
PrismPropertyWrapper<LoggingLevelType> loggerLevel = profilingClassLogger.getValue().findProperty(ClassLoggerConfigurationType.F_LEVEL);
PrismPropertyWrapper<String> appenderLevel = profilingClassLogger.getValue().findProperty(ClassLoggerConfigurationType.F_APPENDER);
loggerLevel.getValue().setRealValue(LoggingLevelType.DEBUG);
appenderLevel.getValues().get(0).setRealValue("MIDPOINT_PROFILE_LOG");
//GIVEN
ObjectDelta<UserType> systemConfigDelta = objectWrapper.getObjectDelta();
assertModificationsSize(systemConfigDelta, 1);
assertModification(systemConfigDelta, ItemPath.create(SystemConfigurationType.F_LOGGING, LoggingConfigurationType.F_CLASS_LOGGER, ClassLoggerConfigurationType.F_LEVEL),
ModificationTypeType.ADD, LoggingLevelType.DEBUG);
assertModification(systemConfigDelta, ItemPath.create(SystemConfigurationType.F_LOGGING, LoggingConfigurationType.F_CLASS_LOGGER, ClassLoggerConfigurationType. F_APPENDER),
ModificationTypeType.ADD, "MIDPOINT_PROFILE_LOG");
//WHEN
executeChanges(systemConfigDelta, null, task, result);
//THEN
SystemConfigurationType systemConfigAfter = getSystemConfiguration();
loggingConfig = objectWrapper.findContainer(SystemConfigurationType.F_LOGGING);
profilingClassLogger = loggingConfig.findContainer(ItemName.fromQName(ProfilingClassLoggerWrapperFactoryImpl.PROFILING_LOGGER_PATH));
loggerLevel = profilingClassLogger.getValue().findProperty(ClassLoggerConfigurationType.F_LEVEL);
appenderLevel = profilingClassLogger.getValue().findProperty(ClassLoggerConfigurationType.F_APPENDER);
if(!loggerLevel.getValue().getRealValue().equals(LoggingLevelType.DEBUG)) {
AssertJUnit.fail("Expected value: " + LoggingLevelType.DEBUG + " after executing of changes. Values present: " + loggerLevel.getValue().getRealValue());
}
if(!appenderLevel.getValues().get(0).getRealValue().equals("MIDPOINT_PROFILE_LOG")) {
AssertJUnit.fail("Expected value: " + "MIDPOINT_PROFILE_LOG" + " after executing of changes. Values present: " + appenderLevel.getValues().get(0).getRealValue());
}
}
@Test
public void test310modifySystemConfigurationAddCollectionView() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
ModelServiceLocator locator = getServiceLocator(task);
SystemConfigurationType systemConfigBefore = getSystemConfiguration();
WrapperContext ctx = new WrapperContext(task, result);
PrismObjectWrapper objectWrapper = createObjectWrapper(systemConfigBefore.asPrismContainer(), ItemStatus.NOT_CHANGED, ctx);
ItemPath guiObjectViewPath = ItemPath.create(SystemConfigurationType.F_ADMIN_GUI_CONFIGURATION, AdminGuiConfigurationType.F_OBJECT_COLLECTION_VIEWS, GuiObjectListViewsType.F_OBJECT_COLLECTION_VIEW);
PrismContainerWrapper<GuiObjectListViewType> collections = objectWrapper.findContainer(guiObjectViewPath);
//GIVEN
PrismContainerValue<GuiObjectListViewType> newCollection = collections.getItem().createNewValue();
ctx.setShowEmpty(true);
PrismContainerValueWrapper<GuiObjectListViewType> newCollectionValueWrapper = locator.createValueWrapper(collections, newCollection, ValueStatus.ADDED, ctx);
collections.getValues().add(newCollectionValueWrapper);
PrismPropertyWrapper<QName> type = newCollectionValueWrapper.findProperty(GuiObjectListViewType.F_TYPE);
type.getValue().setRealValue(new QName("RoleType"));
PrismPropertyWrapper<String> identifier = newCollectionValueWrapper.findProperty(GuiObjectListViewType.F_IDENTIFIER);
identifier.getValue().setRealValue("my-roles-collection");
// WHEN
ObjectDelta<SystemConfigurationType> delta = objectWrapper.getObjectDelta();
GuiObjectListViewType expectedValue = new GuiObjectListViewType(prismContext);
expectedValue.setIdentifier("my-roles-collection");
expectedValue.setType(new QName("RoleType"));
assertModification(delta, guiObjectViewPath, ModificationTypeType.ADD, expectedValue);
executeChanges(delta, null, task, result);
//THEN
SystemConfigurationType systemConfigAfter = getSystemConfiguration();
AdminGuiConfigurationType adminGuiConfig = systemConfigAfter.getAdminGuiConfiguration();
assertNotNull("Unexpecteed empty admin gui configuration.", adminGuiConfig);
GuiObjectListViewsType collectionViews = adminGuiConfig.getObjectCollectionViews();
assertNotNull("Unexpected empty gui obejct collection views", collectionViews);
GuiObjectListViewType myRolesCollection = null;
for (GuiObjectListViewType collectionView : collectionViews.getObjectCollectionView()) {
if ("my-roles-collection".equals(collectionView.getIdentifier())) {
myRolesCollection = collectionView;
}
}
assertNotNull("Newly added collection view not present in system configuration, something strange", myRolesCollection);
assertFalse("c:RoleType should not be eqals to RoleType", RoleType.COMPLEX_TYPE.equals(myRolesCollection.getType()));
assertTrue("c:RoleType should match RoleType", QNameUtil.match(RoleType.COMPLEX_TYPE, myRolesCollection.getType()));
}
@Test
public void test311modifySystemConfigurationModifyCollectionType() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
ModelServiceLocator locator = getServiceLocator(task);
SystemConfigurationType systemConfigBefore = getSystemConfiguration();
WrapperContext ctx = new WrapperContext(task, result);
PrismObjectWrapper objectWrapper = createObjectWrapper(systemConfigBefore.asPrismContainer(), ItemStatus.NOT_CHANGED, ctx);
ItemPath guiObjectViewPath = ItemPath.create(SystemConfigurationType.F_ADMIN_GUI_CONFIGURATION, AdminGuiConfigurationType.F_OBJECT_COLLECTION_VIEWS, GuiObjectListViewsType.F_OBJECT_COLLECTION_VIEW);
PrismContainerWrapper<GuiObjectListViewType> collections = objectWrapper.findContainer(guiObjectViewPath);
PrismContainerValueWrapper<GuiObjectListViewType> foundCollection = null;
for (PrismContainerValueWrapper<GuiObjectListViewType> collection : collections.getValues()) {
GuiObjectListViewType collectionRealValue = collection.getRealValue();
if ("my-roles-collection".equals(collectionRealValue.getIdentifier())) {
foundCollection = collection;
break;
}
}
// GIVEN
PrismPropertyWrapper<QName> collectionType = foundCollection.findProperty(GuiObjectListViewType.F_TYPE);
collectionType.getValue().setRealValue(RoleType.COMPLEX_TYPE);
// WHEN
ObjectDelta<SystemConfigurationType> systemConfigDelta = objectWrapper.getObjectDelta();
assertTrue("Delta should be empty!", systemConfigDelta.isEmpty());
}
private PrismContainerValue<AssignmentType> createDummyResourceAssignment(PrismObjectWrapper<UserType> objectWrapper, int existingAssignments, Task task, OperationResult result) throws Exception {
PrismContainerWrapper<AssignmentType> assignment = objectWrapper.findContainer(UserType.F_ASSIGNMENT);
assertNotNull("unexpected null assignment wrapper", assignment);
assertEquals("Unexpected values for assignment " + assignment.getValues().size(), existingAssignments, assignment.getValues().size());
ModelServiceLocator locator = getServiceLocator(task);
PrismContainerValue<AssignmentType> newAssignment = assignment.getItem().createNewValue();
AssignmentType newAssignmentType = newAssignment.asContainerable();
ConstructionType constructionType = new ConstructionType(locator.getPrismContext());
constructionType.setResourceRef(ObjectTypeUtil.createObjectRef(resourceDummy, locator.getPrismContext()));
constructionType.setKind(ShadowKindType.ACCOUNT);
constructionType.setIntent("default");
newAssignmentType.setConstruction(constructionType);
PrismContainerValue<AssignmentType> newAssignmentClone = newAssignment.clone();
WrapperContext ctx = new WrapperContext(task, result);
PrismContainerValueWrapper vw = locator.createValueWrapper(assignment, newAssignment, ValueStatus.ADDED, ctx);
assignment.getValues().add(vw);
return newAssignmentClone;
}
private ExpressionType createAsIsExpression() {
ExpressionType expressionType = new ExpressionType();
ObjectFactory objectFactory = new ObjectFactory();
AsIsExpressionEvaluatorType asIsEvaluator = objectFactory.createAsIsExpressionEvaluatorType();
JAXBElement<AsIsExpressionEvaluatorType> asIsJaxb = objectFactory.createAsIs(asIsEvaluator);
expressionType.getExpressionEvaluator().add(asIsJaxb);
return expressionType;
}
private <O extends ObjectType> void assertModificationsSize(ObjectDelta<O> delta, int expectedModifications) {
assertNotNull("Unexpeted null delta", delta);
logger.trace("Delta: {}", delta.debugDump());
Collection<? extends ItemDelta<?,?>> modifications = delta.getModifications();
assertEquals("Unexpected modifications size", expectedModifications, modifications.size());
}
private <O extends ObjectType, D extends ItemDelta> void assertModification(ObjectDelta<O> delta, ItemPath itemPath, ModificationTypeType modificationType, Object... expectedValues) {
D modification = (D) delta.findItemDelta(itemPath);
assertNotNull("Unexpected null delta for " + itemPath, modification);
Collection<? extends PrismValue> modificationValues = null;
switch (modificationType) {
case ADD:
assertTrue("Expected add modification but was" + modification, modification.isAdd());
modificationValues = modification.getValuesToAdd();
break;
case REPLACE:
assertTrue("Expected replace modification but was" + modification, modification.isReplace());
modificationValues = modification.getValuesToReplace();
break;
case DELETE:
assertTrue("Expected delete modification but was" + modification, modification.isDelete());
modificationValues = modification.getValuesToDelete();
break;
}
assertEquals("Unexpected numbers of values", expectedValues.length, modificationValues.size());
List<Object> realValues = modificationValues.stream().map(v -> v.getRealValue()).collect(Collectors.toList());
for (Object expectedValue : expectedValues) {
if (!realValues.contains(expectedValue)) {
AssertJUnit.fail("Expected value: " + expectedValue + " not present in delta. Values present: " + realValues);
}
}
}
private <O extends ObjectType> PrismObjectWrapper<O> createObjectWrapper(PrismObject<O> object, ItemStatus status, WrapperContext context) throws Exception{
ModelServiceLocator locator = getServiceLocator(context.getTask());
PrismObjectWrapperFactory objectFactory = locator.findObjectWrapperFactory(object.getDefinition());
PrismObjectWrapper objectWrapper = objectFactory.createObjectWrapper(object, status, context);
return objectWrapper;
}
}