-
Notifications
You must be signed in to change notification settings - Fork 188
/
TestReconScript.java
213 lines (158 loc) · 9.78 KB
/
TestReconScript.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
/*
* 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.model.impl.lens;
import static com.evolveum.midpoint.schema.constants.SchemaConstants.PATH_MODEL_EXTENSION_DRY_RUN;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
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.Test;
import com.evolveum.icf.dummy.resource.ScriptHistoryEntry;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.polystring.PolyString;
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.util.QNameUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
@ContextConfiguration(locations = { "classpath:ctx-model-test-main.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestReconScript extends AbstractInternalModelIntegrationTest {
private static final String TASK_RECON_DUMMY_FILENAME = "src/test/resources/common/task-reconcile-dummy.xml";
private static final String TASK_RECON_DUMMY_OID = "10000000-0000-0000-5656-565600000004";
private static final String ACCOUNT_BEFORE_SCRIPT_FILENAME = "src/test/resources/lens/account-before-script.xml";
private static final String ACCOUNT_BEFORE_SCRIPT_OID = "acc00000-0000-0000-0000-000000001234";
@Test
public void text001testReconcileScriptsWhenProvisioning() throws Exception {
Task task = getTestTask();
OperationResult parentResult = createOperationResult();
ObjectDelta<UserType> delta = createModifyUserAddAccount(USER_JACK_OID, getDummyResourceObject());
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
deltas.add(delta);
task.setChannel(QNameUtil.qNameToUri(SchemaConstants.CHANGE_CHANNEL_RECON));
modelService.executeChanges(deltas, ModelExecuteOptions.createReconcile(), task, parentResult);
delta = createModifyUserReplaceDelta(USER_JACK_OID, UserType.F_FULL_NAME, new PolyString("tralala"));
deltas = new ArrayList<>();
deltas.add(delta);
modelService.executeChanges(deltas, ModelExecuteOptions.createReconcile(), task, parentResult);
delta = createModifyUserReplaceDelta(USER_BARBOSSA_OID, UserType.F_FULL_NAME, new PolyString("tralala"));
deltas = new ArrayList<>();
deltas.add(delta);
modelService.executeChanges(deltas, ModelExecuteOptions.createReconcile(), task, parentResult);
for (ScriptHistoryEntry script : getDummyResource().getScriptHistory()) {
String userName = (String) script.getParams().get("midpoint_usercn");
String idPath = (String) script.getParams().get("midpoint_idpath");
String tempPath = (String) script.getParams().get("midpoint_temppath");
logger.trace("userName {} idPath {} tempPath {}", userName, idPath, tempPath);
if (!idPath.contains(userName)) {
AssertJUnit.fail("Expected that idPath will contain userName [idPath: " + idPath + ", userName " + userName + "]");
}
if (!tempPath.contains(userName)) {
AssertJUnit.fail("Expected that tempPath will contain userName [idPath: " + idPath + ", userName " + userName + "]");
}
}
}
@Test
public void test002testReconcileScriptsWhenReconciling() throws Exception {
getDummyResource().getScriptHistory().clear();
importObjectFromFile(new File(TASK_RECON_DUMMY_FILENAME));
waitForTaskStart(TASK_RECON_DUMMY_OID, false, DEFAULT_TASK_WAIT_TIMEOUT);
waitForTaskNextRunAssertSuccess(TASK_RECON_DUMMY_OID, false, DEFAULT_TASK_WAIT_TIMEOUT);
waitForTaskFinish(TASK_RECON_DUMMY_OID, false);
for (ScriptHistoryEntry script : getDummyResource().getScriptHistory()) {
String userName = (String) script.getParams().get("midpoint_usercn");
String idPath = (String) script.getParams().get("midpoint_idpath");
String tempPath = (String) script.getParams().get("midpoint_temppath");
logger.trace("userName {} idPath {} tempPath {}", userName, idPath, tempPath);
if (!idPath.contains(userName)) {
AssertJUnit.fail("Expected that idPath will contain userName [idPath: " + idPath + ", userName " + userName + "]");
}
if (!tempPath.contains(userName)) {
AssertJUnit.fail("Expected that tempPath will contain userName [idPath: " + idPath + ", userName " + userName + "]");
}
}
}
@Test
public void test003testReconcileScriptsAddUserAction() throws Exception {
Task task = getTestTask();
OperationResult parentResult = createOperationResult();
ShadowType shadow = parseObjectType(new File(ACCOUNT_BEFORE_SCRIPT_FILENAME), ShadowType.class);
provisioningService.addObject(shadow.asPrismObject(), null, null, task, parentResult);
getDummyResource().getScriptHistory().clear();
waitForTaskStart(TASK_RECON_DUMMY_OID, false, DEFAULT_TASK_WAIT_TIMEOUT);
waitForTaskNextRunAssertSuccess(TASK_RECON_DUMMY_OID, false, DEFAULT_TASK_WAIT_TIMEOUT);
waitForTaskFinish(TASK_RECON_DUMMY_OID, true);
PrismObject<ShadowType> afterRecon = repositoryService.getObject(ShadowType.class, ACCOUNT_BEFORE_SCRIPT_OID, null, parentResult);
AssertJUnit.assertNotNull(afterRecon);
afterRecon.asObjectable();
PrismObject<FocusType> user = repositoryService.searchShadowOwner(ACCOUNT_BEFORE_SCRIPT_OID, null, parentResult);
AssertJUnit.assertNotNull("Owner for account " + shadow.asPrismObject() + " not found. Some probelm in recon occured.", user);
for (ScriptHistoryEntry script : getDummyResource().getScriptHistory()) {
String userName = (String) script.getParams().get("midpoint_usercn");
String idPath = (String) script.getParams().get("midpoint_idpath");
String tempPath = (String) script.getParams().get("midpoint_temppath");
logger.trace("userName {} idPath {} tempPath {}", userName, idPath, tempPath);
if (!idPath.contains(userName)) {
AssertJUnit.fail("Expected that idPath will contain userName [idPath: " + idPath + ", userName " + userName + "]");
}
if (!tempPath.contains(userName)) {
AssertJUnit.fail("Expected that tempPath will contain userName [idPath: " + idPath + ", userName " + userName + "]");
}
}
}
@Test
public void test005TestDryRunDelete() throws Exception {
PrismObject<TaskType> task = getTask(TASK_RECON_DUMMY_OID);
OperationResult parentResult = createOperationResult();
PropertyDelta<?> dryRunDelta =
prismContext.deltaFactory().property().createModificationReplaceProperty(
PATH_MODEL_EXTENSION_DRY_RUN, task.getDefinition(), true);
Collection<PropertyDelta<?>> modifications = new ArrayList<>();
modifications.add(dryRunDelta);
repositoryService.modifyObject(TaskType.class, TASK_RECON_DUMMY_OID, modifications, parentResult);
getDummyResource().deleteAccountByName("beforeScript");
waitForTaskStart(TASK_RECON_DUMMY_OID, false);
waitForTaskNextRunAssertSuccess(TASK_RECON_DUMMY_OID, false);
waitForTaskFinish(TASK_RECON_DUMMY_OID, false);
PrismObject<ShadowType> shadow = repositoryService.getObject(ShadowType.class, ACCOUNT_BEFORE_SCRIPT_OID, null, parentResult);
AssertJUnit.assertNotNull(shadow);
PrismObject<FocusType> user = repositoryService.searchShadowOwner(ACCOUNT_BEFORE_SCRIPT_OID, null, parentResult);
AssertJUnit.assertNotNull("Owner for account " + shadow + " not found. Some probelm in dry run occured.", user);
}
@Test
public void test006TestReconDelete() throws Exception {
PrismObject<TaskType> task = getTask(TASK_RECON_DUMMY_OID);
OperationResult parentResult = createOperationResult();
PropertyDelta<Boolean> dryRunDelta = prismContext.deltaFactory().property().createModificationReplaceProperty(
PATH_MODEL_EXTENSION_DRY_RUN, task.getDefinition(), false);
Collection<PropertyDelta<?>> modifications = new ArrayList<>();
modifications.add(dryRunDelta);
repositoryService.modifyObject(TaskType.class, TASK_RECON_DUMMY_OID, modifications, parentResult);
// WHEN
when();
waitForTaskStart(TASK_RECON_DUMMY_OID, false);
waitForTaskNextRunAssertSuccess(TASK_RECON_DUMMY_OID, false);
waitForTaskFinish(TASK_RECON_DUMMY_OID, false);
// THEN
then();
PrismObject<ShadowType> shadow = repositoryService.getObject(ShadowType.class, ACCOUNT_BEFORE_SCRIPT_OID, null, parentResult);
ShadowAsserter.forShadow(shadow)
.assertDead()
.assertIsNotExists();
PrismObject<FocusType> user = repositoryService.searchShadowOwner(ACCOUNT_BEFORE_SCRIPT_OID, null, parentResult);
display("Account owner", user);
AssertJUnit.assertNotNull("Owner for account " + ACCOUNT_BEFORE_SCRIPT_OID + " was not found", user);
}
}