-
Notifications
You must be signed in to change notification settings - Fork 188
/
TestNullAttribute.java
301 lines (223 loc) · 12.4 KB
/
TestNullAttribute.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
/*
* Copyright (c) 2016-2019 mythoss, 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.testing.story;
import java.io.File;
import java.util.Collection;
import javax.xml.namespace.QName;
import com.evolveum.midpoint.prism.*;
import org.springframework.beans.factory.annotation.Autowired;
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 com.evolveum.icf.dummy.resource.DummyObjectClass;
import com.evolveum.icf.dummy.resource.DummyResource;
import com.evolveum.midpoint.model.impl.sync.ReconciliationTaskHandler;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.util.MidPointTestConstants;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentPolicyEnforcementType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
@ContextConfiguration(locations = { "classpath:ctx-story-test-main.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestNullAttribute extends AbstractStoryTest {
public static final File TEST_DIR = new File(MidPointTestConstants.TEST_RESOURCES_DIR, "nullattribute");
public static final File OBJECT_TEMPLATE_USER_FILE = new File(TEST_DIR, "object-template-user.xml");
public static final String OBJECT_TEMPLATE_USER_OID = "10000000-0000-0000-0000-000000002222";
protected static final File RESOURCE_DUMMY_FILE = new File(TEST_DIR, "resource-dummy.xml");
//see
protected static final String RESOURCE_DUMMY_ID = "DUMMY";
protected static final String RESOURCE_DUMMY_OID = "10000000-0000-0000-0000-000000000001";
protected static final String RESOURCE_DUMMY_NAMESPACE = MidPointConstants.NS_RI;
private static final String DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME = "fullname";
private static final String DUMMY_ACCOUNT_ATTRIBUTE_SHIP = "ship";
private static final String DUMMY_ACCOUNT_ATTRIBUTE_WEAPON = "weapon";
public static final File ORG_TOP_FILE = new File(TEST_DIR, "org-top.xml");
public static final String ORG_TOP_OID = "00000000-8888-6666-0000-100000000001";
public static final File ROLE_ACCOUNTONLY_FILE = new File(TEST_DIR, "role-accountonly.xml");
public static final String ROLE_ACCOUNTONLY_OID = "10000000-0000-0000-0000-000000000601";
public static final File ROLE_SHIPNWEAPON_FILE = new File(TEST_DIR, "role-shipnweapon.xml");
public static final String ROLE_SHIPNWEAPON_OID = "10000000-0000-0000-0000-000000000602";
public static final File USER_SMACK_FILE = new File(TEST_DIR, "user-smack.xml");
public static final String USER_SMACK_OID = "c0c010c0-d34d-b33f-f00d-111111111112";
@Autowired private ReconciliationTaskHandler reconciliationTaskHandler;
protected static DummyResource dummyResource;
protected static DummyResourceContoller dummyResourceCtl;
protected ResourceType resourceDummyType;
protected PrismObject<ResourceType> resourceDummy;
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
// Resources
//default instance, no instance id
//when id is set it is required to be present in resource.xml (I guess)
dummyResourceCtl = DummyResourceContoller.create(null, resourceDummy);
DummyObjectClass dummyAdAccountObjectClass = dummyResourceCtl.getDummyResource().getAccountObjectClass();
//attributes
dummyResourceCtl.addAttrDef(dummyAdAccountObjectClass, DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME, String.class, false, false);
dummyResourceCtl.addAttrDef(dummyAdAccountObjectClass, DUMMY_ACCOUNT_ATTRIBUTE_SHIP, String.class, false, false);
dummyResourceCtl.addAttrDef(dummyAdAccountObjectClass, DUMMY_ACCOUNT_ATTRIBUTE_WEAPON, String.class, false, false);
dummyResource = dummyResourceCtl.getDummyResource();
resourceDummy = importAndGetObjectFromFile(ResourceType.class, RESOURCE_DUMMY_FILE,
RESOURCE_DUMMY_OID, initTask, initResult);
dummyResourceCtl.setResource(resourceDummy);
// dummyResource.setSyncStyle(DummySyncStyle.SMART);
//
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
// Object Templates
importObjectFromFile(OBJECT_TEMPLATE_USER_FILE, initResult);
setDefaultUserTemplate(OBJECT_TEMPLATE_USER_OID);
// Role
importObjectFromFile(ROLE_ACCOUNTONLY_FILE, initResult);
importObjectFromFile(ROLE_SHIPNWEAPON_FILE, initResult);
PrismObject<RoleType> rolesw = getRole(ROLE_SHIPNWEAPON_OID);
display("role shipNWeapon initial", rolesw);
//User
importObjectFromFile(USER_SMACK_FILE, initResult);
}
@Test
public void test000Sanity() throws Exception {
final String TEST_NAME = "test000Sanity";
displayTestTitle(TEST_NAME);
Task task = taskManager.createTaskInstance(TestNullAttribute.class.getName() + "." + TEST_NAME);
OperationResult testResult = modelService.testResource(RESOURCE_DUMMY_OID, task);
TestUtil.assertSuccess(testResult);
PrismObjectDefinition<UserType> userDefinition = getUserDefinition();
PrismContainerDefinition<?> userExtensionDef = userDefinition.getExtensionDefinition();
display("User extension definition", userExtensionDef);
PrismAsserts.assertPropertyDefinition(userExtensionDef,
new QName(NS_PIRACY, "ship"), DOMUtil.XSD_STRING, 0, 1);
}
/**
* assign role "account only"
* role should be assigned and fullname should be set in resource account
*/
@Test
public void test010UserSmackAssignAccountOnlyRole() throws Exception {
final String TEST_NAME = "test010UserSmackAssignAccountOnlyRole";
displayTestTitle(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
// WHEN
assignRole(USER_SMACK_OID, ROLE_ACCOUNTONLY_OID, task, result);
// THEN
assertSuccess(result);
PrismObject<UserType> user = getUser(USER_SMACK_OID);
//display("User jack after role account only assignment", user);
assertAssignedRole(user, ROLE_ACCOUNTONLY_OID);
assertNotAssignedRole(user, ROLE_SHIPNWEAPON_OID);
String accountOid = getLinkRefOid(user, RESOURCE_DUMMY_OID);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
display("accountShadow smack after role account only assignment", accountShadow);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
display("accountModel jack after role account only assignment", accountModel);
PrismAsserts.assertPropertyValue(accountModel, dummyResourceCtl.getAttributePath( DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME),"Smack Sparrow");
PrismAsserts.assertNoItem(accountModel, dummyResourceCtl.getAttributePath(DUMMY_ACCOUNT_ATTRIBUTE_SHIP));
PrismAsserts.assertNoItem(accountModel, dummyResourceCtl.getAttributePath(DUMMY_ACCOUNT_ATTRIBUTE_WEAPON));
}
/**
* set extension/ship
* role ShipNWeapon should be assigned (beacause of objecttemplate)
* in resource account values for fullname, ship and weapon should exist
*/
@Test
public void test020UserSmackSetAttribute() throws Exception {
final String TEST_NAME = "test020UserSmackSetAttribute";
displayTestTitle(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
PrismObject<UserType> smack = getUser(USER_SMACK_OID);
display("smack initial: "+smack.debugDump());
// WHEN
@SuppressWarnings("unchecked, raw")
Collection<ObjectDelta<? extends ObjectType>> deltas =
(Collection) prismContext.deltaFor(UserType.class)
.item(UserType.F_EXTENSION, new QName(NS_PIRACY, "ship")).add("Black Pearl")
.asObjectDeltas(USER_SMACK_OID);
modelService.executeChanges(deltas, null, task, result);
// THEN
assertSuccess(result);
PrismObject<UserType> user = getUser(USER_SMACK_OID);
display("User smack after setting attribute piracy:ship", user);
assertAssignedRole(user, ROLE_ACCOUNTONLY_OID);
assertAssignedRole(user, ROLE_SHIPNWEAPON_OID);
String accountOid = getLinkRefOid(user, RESOURCE_DUMMY_OID);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
display("accountShadow smack after role shipnweapon assignment", accountShadow);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
display("accountModel jack after role shipnweapon assignment", accountModel);
PrismAsserts.assertPropertyValue(accountModel, dummyResourceCtl.getAttributePath( DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME),"Smack Sparrow");
PrismAsserts.assertPropertyValue(accountModel, dummyResourceCtl.getAttributePath( DUMMY_ACCOUNT_ATTRIBUTE_SHIP),"Black Pearl");
// weapon is not in user's extension (MID-3326)
//PrismAsserts.assertPropertyValue(accountModel, dummyResourceCtl.getAttributePath(DUMMY_ACCOUNT_ATTRIBUTE_WEAPON),"pistol");
}
/**
* remove extension/ship
* role ShipNWeapon should be unassigned (beacause of objecttemplate)
* in resource account only value for fullname should still exist, ship and weapon should have been removed
* MID-3325
*/
@Test // MID-3325
public void test030UserSmackRemoveAttribute() throws Exception {
final String TEST_NAME = "test030UserSmackRemoveAttribute";
displayTestTitle(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
//TODO: best way to set extension properties?
PrismObject<UserType> userBefore = getUser(USER_SMACK_OID);
display("User before", userBefore);
PrismObject<UserType> userNewPrism = userBefore.clone();
prismContext.adopt(userNewPrism);
if (userNewPrism.getExtension()==null)userNewPrism.createExtension();
PrismContainer<?> ext = userNewPrism.getExtension();
ext.setPropertyRealValue(PIRACY_SHIP_QNAME, null);
ObjectDelta<UserType> delta = userBefore.diff(userNewPrism);
display("Modifying user with delta", delta);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(delta);
// WHEN
displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
displayThen(TEST_NAME);
assertSuccess(result);
PrismObject<UserType> userAfter = getUser(USER_SMACK_OID);
display("User smack after deleting attribute piracy:ship", userAfter);
assertAssignedRole(userAfter, ROLE_ACCOUNTONLY_OID);
assertNotAssignedRole(userAfter, ROLE_SHIPNWEAPON_OID);
String accountOid = getLinkRefOid(userAfter, RESOURCE_DUMMY_OID);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
display("accountShadow smack after attribute deletion", accountShadow);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
display("accountModel jack after attribute deletion", accountModel);
PrismAsserts.assertPropertyValue(accountModel, dummyResourceCtl.getAttributePath( DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME),"Smack Sparrow");
PrismAsserts.assertNoItem(accountModel, dummyResourceCtl.getAttributePath(DUMMY_ACCOUNT_ATTRIBUTE_WEAPON));
PrismAsserts.assertNoItem(accountModel, dummyResourceCtl.getAttributePath(DUMMY_ACCOUNT_ATTRIBUTE_SHIP));
}
}