Skip to content

Commit

Permalink
Persona modification (+tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed May 4, 2017
1 parent a87b2c3 commit bae392a
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 15 deletions.
Expand Up @@ -202,7 +202,7 @@ public void after(PersonaKey key, String desc,
if (existingPersona == null) {
personaAdd(context, key, construction, task, result);
} else {
personaModify(context, key, construction, existingPersona, task, result);
personaModify(context, key, construction, existingPersona.asPrismObject(), task, result);
}
}

Expand Down Expand Up @@ -260,10 +260,11 @@ private boolean personaMatches(FocusType persona, PersonaKey key) {
return true;
}

public <F extends FocusType, T extends FocusType> void personaAdd(LensContext<F> context, PersonaKey key, PersonaConstruction<F> construction, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
LOGGER.info("PERSONA ADD: {} - {}", key, construction);

public <F extends FocusType, T extends FocusType> void personaAdd(LensContext<F> context, PersonaKey key, PersonaConstruction<F> construction,
Task task, OperationResult result)
throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
PrismObject<F> focus = context.getFocusContext().getObjectNew();
LOGGER.debug("Adding persona {} for {} using construction {}", key, focus, construction);
PersonaConstructionType constructionType = construction.getConstructionType();
ObjectReferenceType objectMappingRef = constructionType.getObjectMappingRef();
ObjectTemplateType objectMappingType = objectResolver.resolve(objectMappingRef, ObjectTemplateType.class, null, "object mapping in persona construction in "+focus, task, result);
Expand Down Expand Up @@ -299,14 +300,37 @@ public <F extends FocusType, T extends FocusType> void personaAdd(LensContext<F>
link(context, target.asObjectable(), result);
}

public <F extends FocusType> void personaModify(LensContext<F> context, PersonaKey key, PersonaConstruction<F> construction, FocusType existingPersona, Task task, OperationResult result) {
LOGGER.info("PERSONA MODIFY: {} - {}", key, construction);
// TODO: exec
public <F extends FocusType, T extends FocusType> void personaModify(LensContext<F> context, PersonaKey key, PersonaConstruction<F> construction,
PrismObject<T> existingPersona, Task task, OperationResult result)
throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, PolicyViolationException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
PrismObject<F> focus = context.getFocusContext().getObjectNew();
LOGGER.debug("Modifying persona {} for {} using construction {}", key, focus, construction);
PersonaConstructionType constructionType = construction.getConstructionType();
ObjectReferenceType objectMappingRef = constructionType.getObjectMappingRef();
ObjectTemplateType objectMappingType = objectResolver.resolve(objectMappingRef, ObjectTemplateType.class, null, "object mapping in persona construction in "+focus, task, result);

ObjectDeltaObject<F> focusOdo = context.getFocusContext().getObjectDeltaObject();
String contextDesc = "object mapping "+objectMappingType+ " for persona construction for "+focus;
XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();

Collection<ItemDelta<?, ?>> itemDeltas = objectTemplateProcessor.processObjectMapping(context, objectMappingType,
focusOdo, existingPersona, null, contextDesc, now, task, result);

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("itemDeltas:\n{}", DebugUtil.debugDump(itemDeltas));
}

ObjectDelta<T> targetDelta = existingPersona.createModifyDelta();
for (ItemDelta itemDelta: itemDeltas) {
targetDelta.addModification(itemDelta);
}

modelService.executeChanges(MiscSchemaUtil.createCollection(targetDelta), null, task, result);
}

public <F extends FocusType> void personaDelete(LensContext<F> context, PersonaKey key, FocusType existingPersona, Task task, OperationResult result) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
LOGGER.info("PERSONA DELETE: {}", existingPersona);

public <F extends FocusType> void personaDelete(LensContext<F> context, PersonaKey key, FocusType existingPersona, Task task, OperationResult result) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
PrismObject<F> focus = context.getFocusContext().getObjectOld();
LOGGER.debug("Deleting persona {} for {}: ", key, focus, existingPersona);
ObjectDelta<? extends FocusType> delta = existingPersona.asPrismObject().createDeleteDelta();
modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);

Expand Down
Expand Up @@ -114,6 +114,8 @@ public class TestPersona extends AbstractInitializedModelIntegrationTest {
protected static final File ROLE_PERSONA_ADMIN_FILE = new File(TEST_DIR, "role-persona-admin.xml");
protected static final String ROLE_PERSONA_ADMIN_OID = "16813ae6-2c0a-11e7-91fc-8333c244329e";

private static final String USER_JACK_GIVEN_NAME_NEW = "Jackie";

String userJackAdminPersonaOid;

@Override
Expand Down Expand Up @@ -149,7 +151,6 @@ public void test100AssignRolePersonaAdminToJack() throws Exception {
displayThen(TEST_NAME);
assertSuccess(result);

// Check accountRef
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User after", userAfter);
assertUserJack(userAfter);
Expand All @@ -160,18 +161,146 @@ public void test100AssignRolePersonaAdminToJack() throws Exception {
display("Persona", persona);
userJackAdminPersonaOid = persona.getOid();
// Full name is computed by using ordinary user template
assertUser(persona, userJackAdminPersonaOid, "a-"+USER_JACK_USERNAME, USER_JACK_FULL_NAME, USER_JACK_GIVEN_NAME, USER_JACK_FAMILY_NAME);
assertUser(persona, userJackAdminPersonaOid, toAdminPersonaUsername(USER_JACK_USERNAME), USER_JACK_FULL_NAME, USER_JACK_GIVEN_NAME, USER_JACK_FAMILY_NAME);
assertSubtype(persona, "admin");

assertSteadyResources();
}

// TODO: modify
@Test
public void test102RecomputeUserJack() throws Exception {
final String TEST_NAME = "test102RecomputeUserJack";
displayTestTile(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();

// WHEN
displayWhen(TEST_NAME);
recomputeUser(USER_JACK_OID, task, result);

// THEN
displayThen(TEST_NAME);
assertSuccess(result);

assertUserJack11x();
}

@Test
public void test103ReconcileUserJack() throws Exception {
final String TEST_NAME = "test103ReconcileUserJack";
displayTestTile(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();

// WHEN
displayWhen(TEST_NAME);
reconcileUser(USER_JACK_OID, task, result);

// THEN
displayThen(TEST_NAME);
assertSuccess(result);

assertUserJack11x();
}

@Test
public void test104RecomputeJackAdminPersona() throws Exception {
final String TEST_NAME = "test104RecomputeJackAdminPersona";
displayTestTile(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();

// WHEN
displayWhen(TEST_NAME);
recomputeUser(userJackAdminPersonaOid, task, result);

// THEN
displayThen(TEST_NAME);
assertSuccess(result);

assertUserJack11x();
}

@Test
public void test105ReconcileJackAdminPersona() throws Exception {
final String TEST_NAME = "test105ReconcileJackAdminPersona";
displayTestTile(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();

// WHEN
displayWhen(TEST_NAME);
reconcileUser(userJackAdminPersonaOid, task, result);

// THEN
displayThen(TEST_NAME);
assertSuccess(result);

assertUserJack11x();
}

private void assertUserJack11x() throws Exception {
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User after", userAfter);
assertUserJack(userAfter);

assertLinks(userAfter, 0);
assertPersonaLinks(userAfter, 1);
PrismObject<UserType> persona = assertLinkedPersona(userAfter, UserType.class, "admin");
display("Persona", persona);
assertUser(persona, userJackAdminPersonaOid, toAdminPersonaUsername(USER_JACK_USERNAME), USER_JACK_FULL_NAME, USER_JACK_GIVEN_NAME, USER_JACK_FAMILY_NAME);
assertSubtype(persona, "admin");

assertSteadyResources();
}

@Test
public void test120ModifyJackGivenName() throws Exception {
final String TEST_NAME = "test120ModifyJackGivenName";
displayTestTile(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();

// WHEN
displayWhen(TEST_NAME);
modifyUserReplace(USER_JACK_OID, UserType.F_GIVEN_NAME, task, result, createPolyString(USER_JACK_GIVEN_NAME_NEW));
assignRole(USER_JACK_OID, ROLE_PERSONA_ADMIN_OID, task, result);

// THEN
displayThen(TEST_NAME);
assertSuccess(result);

PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User after", userAfter);
assertUser(userAfter, USER_JACK_OID, USER_JACK_USERNAME, USER_JACK_FULL_NAME, USER_JACK_GIVEN_NAME_NEW, USER_JACK_FAMILY_NAME);

assertLinks(userAfter, 0);
assertPersonaLinks(userAfter, 1);
PrismObject<UserType> persona = assertLinkedPersona(userAfter, UserType.class, "admin");
display("Persona", persona);
// Full name mapping in ordinary user template is weak, fullname is not changed
assertUser(persona, userJackAdminPersonaOid, toAdminPersonaUsername(USER_JACK_USERNAME), USER_JACK_FULL_NAME, USER_JACK_GIVEN_NAME_NEW, USER_JACK_FAMILY_NAME);
assertSubtype(persona, "admin");

assertSteadyResources();
}

// TODO: recompute, reconcile (both user and persona)

// TODO: assign some accouts/roles to user and persona, make sure they are independent

// TODO: independent change in the persona

@Test
public void test199UnassignRolePersonaAdminFromJack() throws Exception {
final String TEST_NAME = "test199UnassignRolePersonaAdminFromJack";
Expand All @@ -189,10 +318,9 @@ public void test199UnassignRolePersonaAdminFromJack() throws Exception {
displayThen(TEST_NAME);
assertSuccess(result);

// Check accountRef
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User after", userAfter);
assertUserJack(userAfter);
assertUser(userAfter, USER_JACK_OID, USER_JACK_USERNAME, USER_JACK_FULL_NAME, USER_JACK_GIVEN_NAME_NEW, USER_JACK_FAMILY_NAME);

assertLinks(userAfter, 0);
assertPersonaLinks(userAfter, 0);
Expand All @@ -201,4 +329,9 @@ public void test199UnassignRolePersonaAdminFromJack() throws Exception {

assertSteadyResources();
}

private String toAdminPersonaUsername(String username) {
return "a-"+username;
}

}

0 comments on commit bae392a

Please sign in to comment.