-
Notifications
You must be signed in to change notification settings - Fork 188
/
TestSemiManual.java
339 lines (272 loc) · 12.7 KB
/
TestSemiManual.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
/*
* 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 static org.testng.AssertJUnit.assertNull;
import java.io.File;
import javax.xml.namespace.QName;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.testng.AssertJUnit;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
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.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
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.ShadowKindType;
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.PolyStringType;
/**
* @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 TestSemiManual extends AbstractDirectManualResourceTest {
private static final Trace LOGGER = TraceManager.getTrace(TestSemiManual.class);
protected static final String ATTR_DISABLED = "disabled";
protected static final QName ATTR_DISABLED_QNAME = new QName(MidPointConstants.NS_RI, ATTR_DISABLED);
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
}
@Override
protected BackingStore createBackingStore() {
return new CsvBackingStore();
}
@Override
protected String getResourceOid() {
return RESOURCE_SEMI_MANUAL_OID;
}
@Override
protected File getResourceFile() {
return RESOURCE_SEMI_MANUAL_FILE;
}
@Override
protected String getRoleOneOid() {
return ROLE_ONE_SEMI_MANUAL_OID;
}
@Override
protected File getRoleOneFile() {
return ROLE_ONE_SEMI_MANUAL_FILE;
}
@Override
protected String getRoleTwoOid() {
return ROLE_TWO_SEMI_MANUAL_OID;
}
@Override
protected File getRoleTwoFile() {
return ROLE_TWO_SEMI_MANUAL_FILE;
}
@Override
protected boolean hasMultivalueInterests() {
return false;
}
@Override
protected void assertResourceSchemaBeforeTest(Element resourceXsdSchemaElementBefore) {
AssertJUnit.assertNull("Resource schema sneaked in before test connection", resourceXsdSchemaElementBefore);
}
@Override
protected int getNumberOfAccountAttributeDefinitions() {
return 5;
}
/**
* Trying to assign an account that already exists in the backing store.
* But midPoint does not know about it.
* MID-4002
*/
@Test
public void test700AssignAccountJackExisting() throws Exception {
final String TEST_NAME = "test700AssignAccountJack";
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
if (accountJackOid != null) {
PrismObject<ShadowType> shadowRepoBefore = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
display("Repo shadow before", shadowRepoBefore);
assertPendingOperationDeltas(shadowRepoBefore, 0);
}
backingStoreAddJack();
clock.overrideDuration("PT5M");
accountJackReqestTimestampStart = clock.currentTimeXMLGregorianCalendar();
// WHEN
when(TEST_NAME);
assignAccountToUser(USER_JACK_OID, getResourceOid(), null, task, result);
// THEN
then(TEST_NAME);
display("result", result);
assertSuccess(result, 2);
assertNull("Unexpected ticket in result", result.getAsynchronousOperationReference());
accountJackReqestTimestampEnd = clock.currentTimeXMLGregorianCalendar();
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User after", userAfter);
accountJackOid = getSingleLinkOid(userAfter);
PrismObject<ShadowType> shadowRepo = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
display("Repo shadow", shadowRepo);
assertPendingOperationDeltas(shadowRepo, 0);
assertShadowExists(shadowRepo, true);
assertNoShadowPassword(shadowRepo);
PrismObject<ShadowType> shadowModel = modelService.getObject(ShadowType.class,
accountJackOid, null, task, result);
display("Model shadow", shadowModel);
ShadowType shadowTypeProvisioning = shadowModel.asObjectable();
assertShadowName(shadowModel, USER_JACK_USERNAME);
assertEquals("Wrong kind (provisioning)", ShadowKindType.ACCOUNT, shadowTypeProvisioning.getKind());
assertAttribute(shadowModel, ATTR_USERNAME_QNAME, USER_JACK_USERNAME);
assertAttribute(shadowModel, ATTR_FULLNAME_QNAME, USER_JACK_FULL_NAME);
assertShadowActivationAdministrativeStatus(shadowModel, ActivationStatusType.ENABLED);
assertShadowExists(shadowModel, true);
assertPendingOperationDeltas(shadowModel, 0);
}
/**
* MID-4002
*/
@Test
public void test710UnassignAccountJack() throws Exception {
final String TEST_NAME = "test710UnassignAccountJack";
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
clock.overrideDuration("PT5M");
accountJackReqestTimestampStart = clock.currentTimeXMLGregorianCalendar();
// WHEN
when(TEST_NAME);
unassignAccountFromUser(USER_JACK_OID, getResourceOid(), null, task, result);
// THEN
then(TEST_NAME);
display("result", result);
jackLastCaseOid = assertInProgress(result);
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User after", userAfter);
accountJackOid = getSingleLinkOid(userAfter);
accountJackReqestTimestampEnd = clock.currentTimeXMLGregorianCalendar();
PrismObject<ShadowType> shadowRepo = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
display("Repo shadow", shadowRepo);
assertPendingOperationDeltas(shadowRepo, 1);
PendingOperationType pendingOperation = findPendingOperation(shadowRepo, OperationResultStatusType.IN_PROGRESS);
assertPendingOperation(shadowRepo, pendingOperation, accountJackReqestTimestampStart, accountJackReqestTimestampEnd);
assertNotNull("No ID in pending operation", pendingOperation.getId());
PrismObject<ShadowType> shadowModel = modelService.getObject(ShadowType.class,
accountJackOid, null, task, result);
display("Model shadow", shadowModel);
ShadowType shadowTypeProvisioning = shadowModel.asObjectable();
assertShadowName(shadowModel, USER_JACK_USERNAME);
assertEquals("Wrong kind (provisioning)", ShadowKindType.ACCOUNT, shadowTypeProvisioning.getKind());
assertShadowPassword(shadowModel);
assertPendingOperationDeltas(shadowModel, 1);
pendingOperation = findPendingOperation(shadowModel, OperationResultStatusType.IN_PROGRESS);
assertPendingOperation(shadowModel, pendingOperation, accountJackReqestTimestampStart, accountJackReqestTimestampEnd);
assertUnassignedFuture(assertModelShadowFuture(accountJackOid), true);
assertCaseState(jackLastCaseOid, SchemaConstants.CASE_STATE_OPEN);
}
/**
* MID-4002
*/
@Test
public void test712CloseCaseAndRecomputeJack() throws Exception {
final String TEST_NAME = "test712CloseCaseAndRecomputeJack";
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
backingStoreDeleteJack();
closeCase(jackLastCaseOid);
accountJackCompletionTimestampStart = clock.currentTimeXMLGregorianCalendar();
// WHEN
when(TEST_NAME);
// We need reconcile and not recompute here. We need to fetch the updated case status.
reconcileUser(USER_JACK_OID, task, result);
// THEN
then(TEST_NAME);
display("result", result);
assertSuccess(result);
accountJackCompletionTimestampEnd = clock.currentTimeXMLGregorianCalendar();
ShadowAsserter<Void> shadowRepoAsserter = assertRepoShadow(accountJackOid)
.pendingOperations()
.singleOperation()
.assertRequestTimestamp(accountJackReqestTimestampStart, accountJackReqestTimestampEnd)
.assertExecutionStatus(PendingOperationExecutionStatusType.COMPLETED)
.assertResultStatus(OperationResultStatusType.SUCCESS)
.assertCompletionTimestamp(accountJackCompletionTimestampStart, accountJackCompletionTimestampEnd)
.end()
.end();
assertUnassignedShadow(shadowRepoAsserter, true, null);
ShadowAsserter<Void> shadowModelAsserter = assertModelShadow(accountJackOid)
.assertName(USER_JACK_USERNAME)
.assertKind(ShadowKindType.ACCOUNT)
.pendingOperations()
.singleOperation()
.assertRequestTimestamp(accountJackReqestTimestampStart, accountJackReqestTimestampEnd)
.assertExecutionStatus(PendingOperationExecutionStatusType.COMPLETED)
.assertResultStatus(OperationResultStatusType.SUCCESS)
.assertCompletionTimestamp(accountJackCompletionTimestampStart, accountJackCompletionTimestampEnd)
.end()
.end();
assertUnassignedShadow(shadowModelAsserter, true, ActivationStatusType.DISABLED);
assertUnassignedFuture(assertModelShadowFuture(accountJackOid), false);
assertCaseState(jackLastCaseOid, SchemaConstants.CASE_STATE_CLOSED);
}
/**
* MID-4002
*/
@Test
public void test717RecomputeJackAfter130min() throws Exception {
final String TEST_NAME = "test717RecomputeJackAfter130min";
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
clock.overrideDuration("PT130M");
// WHEN
when(TEST_NAME);
// We need reconcile and not recompute here. We need to fetch the updated case status.
reconcileUser(USER_JACK_OID, task, result);
// THEN
then(TEST_NAME);
display("result", result);
assertSuccess(result);
UserAsserter<Void> userAfterAsserter = assertUserAfter(USER_JACK_OID);
userAfterAsserter.displayWithProjections();
assertDeprovisionedTimedOutUser(userAfterAsserter, accountJackOid);
assertCaseState(jackLastCaseOid, SchemaConstants.CASE_STATE_CLOSED);
}
/**
* Put everything in a clean state so we can start over.
*/
@Test
public void test719CleanUp() throws Exception {
final String TEST_NAME = "test719CleanUp";
cleanupUser(USER_JACK_OID, USER_JACK_USERNAME, accountJackOid);
}
@Override
protected void assertShadowPassword(PrismObject<ShadowType> shadow) {
// CSV password is readable
PrismProperty<PolyStringType> passValProp = shadow.findProperty(SchemaConstants.PATH_PASSWORD_VALUE);
assertNotNull("No password value property in "+shadow+": "+passValProp, passValProp);
}
@Override
protected void assertUnassignedShadow(ShadowAsserter<?> shadowModelAsserter, boolean backingStoreUpdated, ActivationStatusType expectAlternativeActivationStatus) {
if (backingStoreUpdated) {
shadowModelAsserter.assertTombstone();
} else {
shadowModelAsserter.assertCorpse();
}
}
}