-
Notifications
You must be signed in to change notification settings - Fork 188
/
TestSemiManualDisable.java
296 lines (247 loc) · 11.1 KB
/
TestSemiManualDisable.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
/*
* Copyright (c) 2010-2018 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.model.intest.manual;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import java.io.File;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import com.evolveum.midpoint.prism.PrismObject;
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.asserter.ShadowAsserter;
import com.evolveum.midpoint.test.asserter.UserAsserter;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PendingOperationExecutionStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PendingOperationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.ChangeTypeType;
import com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType;
/**
* @author Radovan Semancik
*/
@ContextConfiguration(locations = {"classpath:ctx-model-intest-test-main.xml"})
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
@Listeners({ com.evolveum.midpoint.tools.testng.AlphabeticalMethodInterceptor.class })
public class TestSemiManualDisable extends TestSemiManual {
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
}
@Override
protected BackingStore createBackingStore() {
return new CsvDisablingBackingStore();
}
@Override
protected String getResourceOid() {
return RESOURCE_SEMI_MANUAL_DISABLE_OID;
}
@Override
protected File getResourceFile() {
return RESOURCE_SEMI_MANUAL_DISABLE_FILE;
}
@Override
protected String getRoleOneOid() {
return ROLE_ONE_SEMI_MANUAL_DISABLE_OID;
}
@Override
protected File getRoleOneFile() {
return ROLE_ONE_SEMI_MANUAL_DISABLE_FILE;
}
@Override
protected String getRoleTwoOid() {
return ROLE_TWO_SEMI_MANUAL_DISABLE_OID;
}
@Override
protected File getRoleTwoFile() {
return ROLE_TWO_SEMI_MANUAL_DISABLE_FILE;
}
@Override
protected boolean nativeCapabilitiesEntered() {
return true;
}
@Override
protected void assertUnassignedShadow(ShadowAsserter<?> shadowModelAsserter, boolean backingStoreUpdated, ActivationStatusType expectAlternativeActivationStatus) {
shadowModelAsserter
.assertLife()
.assertAdministrativeStatus(expectAlternativeActivationStatus);
}
@Override
protected void assertUnassignedFuture(ShadowAsserter<?> shadowModelAsserterFuture, boolean assertPassword) {
shadowModelAsserterFuture
.assertLife()
.assertAdministrativeStatus(ActivationStatusType.DISABLED);
if (assertPassword) {
assertShadowPassword(shadowModelAsserterFuture);
}
}
@Override
protected <R> void assertDeprovisionedTimedOutUser(UserAsserter<R> userAsserter, String accountOid) throws Exception {
userAsserter
.assertLinks(1);
assertModelShadow(accountOid)
.assertAdministrativeStatus(ActivationStatusType.DISABLED);
}
@Override
protected void assertWillUnassignPendingOperationExecuting(ShadowAsserter<Void> shadowRepoAsserter) {
shadowRepoAsserter
.pendingOperations()
.by()
.changeType(ChangeTypeType.MODIFY)
.item(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS)
.find()
.assertRequestTimestamp(accountWillSecondReqestTimestampStart, accountWillSecondReqestTimestampEnd)
.assertExecutionStatus(PendingOperationExecutionStatusType.EXECUTING)
.assertResultStatus(OperationResultStatusType.IN_PROGRESS)
.assertId()
.end()
.end();
}
@Override
protected void assertWillUnassignPendingOperationCompleted(ShadowAsserter<Void> shadowRepoAsserter) {
shadowRepoAsserter
.pendingOperations()
.by()
.changeType(ChangeTypeType.MODIFY)
.item(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS)
.find()
.assertRequestTimestamp(accountWillSecondReqestTimestampStart, accountWillSecondReqestTimestampEnd)
.assertExecutionStatus(PendingOperationExecutionStatusType.COMPLETED)
.assertResultStatus(OperationResultStatusType.SUCCESS)
.assertCompletionTimestamp(accountWillCompletionTimestampStart, accountWillCompletionTimestampEnd)
.assertId()
.end()
.end();
}
@Override
protected void cleanupUser(String userOid, String username, String accountOid) throws Exception {
Task task = createTask("cleanupUser");
OperationResult result = task.getResult();
backingStore.deleteAccount(username);
try {
repositoryService.deleteObject(ShadowType.class, accountOid, result);
} catch (ObjectNotFoundException e) {
// no problem
}
recomputeUser(userOid, task, result);
PrismObject<UserType> userAfter = getUser(userOid);
display("User after", userAfter);
assertLinks(userAfter, 0);
assertNoShadow(accountOid);
}
/**
* MID-4587
*/
@Test
@Override
public void test416PhoenixAccountUnassignCloseCase() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
closeCase(phoenixLastCaseOid);
// WHEN
when();
reconcileUser(USER_PHOENIX_OID, task, result);
// THEN
then();
assertSuccess(result);
// Make sure the operation will be picked up by propagation task
clockForward("PT3M");
// WHEN
when();
runPropagation();
// THEN
then();
PrismObject<UserType> userAfter = getUser(USER_PHOENIX_OID);
display("User after", userAfter);
String shadowOid = getSingleLinkOid(userAfter);
PrismObject<ShadowType> shadowModel = getShadowModel(shadowOid);
display("Shadow after", shadowModel);
// Shadow NOT dead. We are disabling instead of deleting
assertShadowNotDead(shadowModel);
assertAttribute(shadowModel, ATTR_USERNAME_QNAME, USER_PHOENIX_USERNAME);
// Semi-manual ... we still see old activationStatus value
assertActivationAdministrativeStatus(shadowModel, ActivationStatusType.ENABLED);
assertSinglePendingOperation(shadowModel, PendingOperationExecutionStatusType.COMPLETED, OperationResultStatusType.SUCCESS);
assertSteadyResources();
}
@Test
@Override
public void test418AssignPhoenixAccountAgain() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
// WHEN
when();
assignAccountToUser(USER_PHOENIX_OID, getResourceOid(), null, task, result);
// THEN
then();
phoenixLastCaseOid = assertInProgress(result);
// Make sure the operation will be picked up by propagation task
clockForward("PT3M");
// WHEN
when();
runPropagation();
// THEN
then();
PrismObject<UserType> userAfter = getUser(USER_PHOENIX_OID);
display("User after", userAfter);
String shadowOid = getSingleLinkOid(userAfter);
PrismObject<ShadowType> shadowModel = getShadowModel(shadowOid);
display("Shadow after", shadowModel);
assertShadowNotDead(shadowModel);
assertAttribute(shadowModel, ATTR_USERNAME_QNAME, USER_PHOENIX_USERNAME);
assertAttribute(shadowModel, ATTR_FULLNAME_QNAME, USER_PHOENIX_FULL_NAME);
assertPendingOperationDeltas(shadowModel, 2);
PendingOperationType disableOperation = findPendingOperation(shadowModel, OperationResultStatusType.SUCCESS, ChangeTypeType.MODIFY);
assertPendingOperation(shadowModel, disableOperation,
PendingOperationExecutionStatusType.COMPLETED, OperationResultStatusType.SUCCESS);
assertNotNull("Null completion timestamp", disableOperation.getCompletionTimestamp());
PendingOperationType enableOperation = findPendingOperation(shadowModel, PendingOperationExecutionStatusType.EXECUTING, null,
ChangeTypeType.MODIFY, SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS);
assertPendingOperation(shadowModel, enableOperation,
PendingOperationExecutionStatusType.EXECUTING, OperationResultStatusType.IN_PROGRESS);
assertSteadyResources();
}
@Override
protected void assertTest526Deltas(PrismObject<ShadowType> shadowRepo, OperationResult result) {
assertPendingOperationDeltas(shadowRepo, 3);
ObjectDeltaType deltaModify = null;
ObjectDeltaType deltaAdd = null;
ObjectDeltaType deltaDisable = null;
for (PendingOperationType pendingOperation: shadowRepo.asObjectable().getPendingOperation()) {
ObjectDeltaType delta = pendingOperation.getDelta();
if (ChangeTypeType.ADD.equals(delta.getChangeType())) {
deltaAdd = delta;
assertEquals("Wrong status in add delta", OperationResultStatusType.SUCCESS, pendingOperation.getResultStatus());
}
if (ChangeTypeType.MODIFY.equals(delta.getChangeType()) && OperationResultStatusType.SUCCESS.equals(pendingOperation.getResultStatus())) {
deltaModify = delta;
}
if (ChangeTypeType.MODIFY.equals(delta.getChangeType()) && OperationResultStatusType.IN_PROGRESS.equals(pendingOperation.getResultStatus())) {
deltaDisable = delta;
}
}
assertNotNull("No add pending delta", deltaAdd);
assertNotNull("No modify pending delta", deltaModify);
assertNotNull("No disable pending delta", deltaDisable);
}
@Override
protected void assertTest528Deltas(PrismObject<ShadowType> shadowRepo, OperationResult result) {
assertPendingOperationDeltas(shadowRepo, 3);
for (PendingOperationType pendingOperation: shadowRepo.asObjectable().getPendingOperation()) {
assertEquals("Wrong status in pending delta", OperationResultStatusType.SUCCESS, pendingOperation.getResultStatus());
}
}
}