Skip to content

Commit

Permalink
Improve TestPreviewChangesCoD
Browse files Browse the repository at this point in the history
Simulation-mode scenarios were added. Test200 was converted
to the simulated execution mode and partially fixed.
  • Loading branch information
mederly committed Dec 6, 2022
1 parent 4192214 commit ac6b074
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void test110SimpleCreateOnDemandSimulation() throws Exception {

Map<Class<? extends ObjectType>, Integer> counts = collectCounts(task, result);

given("simple parent-less child ADD delta");
given("simple orphan ADD delta");
ObjectDelta<OrgType> delta = ORG_CHILD.getObject().clone().createAddDelta();

when("executeChanges is called in simulation mode");
Expand All @@ -165,79 +165,121 @@ public void test110SimpleCreateOnDemandSimulation() throws Exception {
List<ObjectDelta<?>> simulatedDeltas = simResult.getSimulatedDeltas();
displayCollection("simulated deltas", simulatedDeltas);
// TODO some asserts here
// TODO currently, the "parentOfChild-1" is (in simulation) created here twice, because the projector runs twice
// for the child. Shouldn't we really create focus objects with some "simulated" flag turned on?

and("there should be some secondary deltas in model context");
ModelContext<?> context = simResult.getLastModelContext(); // TODO - which one is this? the original or the embedded one
AssertJUnit.assertNotNull(context);
displayDumpable("context", context); // TODO assert the deltas
}

/**
* More advanced "create on demand" scenario for `ORG_CHILD`:
*
* - `parentIdentifier` is "parentOfChild-1" -> a parent organization with this name should be created (and assigned)
* - metarole `role-meta-assignment-search` is present -> a role "Role: child org-Read" should be created (and assigned)
*/
@Test
public void test150OrgNotProvisionedWithMetarole() throws Exception {
given();

public void test150CreateOnDemandForOrgAndRole() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();

Map<Class<? extends ObjectType>, Integer> counts = collectCounts(task, result);

when("preview for create org, that should search/createOnDemand parent org. Also role should be searched/createOnDemand for this new org via metarole");

PrismObject<OrgType> orgChild = ORG_CHILD.getObject().clone();
// we'll add assignment to meta role
orgChild.asObjectable().getAssignment().add(new AssignmentType().targetRef(ROLE_META_ASSIGNMENT_SEARCH.oid, RoleType.COMPLEX_TYPE));
ObjectDelta<OrgType> delta = orgChild.createAddDelta();

ModelContext<OrgType> context = modelInteractionService.previewChanges(Collections.singletonList(delta), ModelExecuteOptions.create(), task, result);
given("org ADD delta");
ObjectDelta<OrgType> delta = createAddDeltaForOrgWithRoleAssignment();

then();
when("previewChanges is invoked");
ModelContext<OrgType> context =
modelInteractionService.previewChanges(
List.of(delta), ModelExecuteOptions.create(), task, result);

then("no new objects are created");
AssertJUnit.assertNotNull(context);
assertCollectedCounts(counts, task, result);

// TODO some asserts here
}

@Test(enabled = false,
description = "Test currently fails since previewChanges doesn't handle associationTargetSearch properly (projector instead of whole clockwork is running)")
public void test200ComplexCase() throws Exception {
given();
private ObjectDelta<OrgType> createAddDeltaForOrgWithRoleAssignment() {
PrismObject<OrgType> orgChild = ORG_CHILD.getObject().clone();
addMetaroleAssignment(orgChild);
return orgChild.createAddDelta();
}

private void addMetaroleAssignment(PrismObject<OrgType> orgChild) {
orgChild.asObjectable().getAssignment().add(
new AssignmentType()
.targetRef(ROLE_META_ASSIGNMENT_SEARCH.oid, RoleType.COMPLEX_TYPE));
}

/**
* As {@link #test150CreateOnDemandForOrgAndRole()} but using `executeChanges` with "no persistent effects" execution mode.
*/
@Test
public void test160CreateOnDemandForOrgAndRoleSimulated() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();

Map<Class<? extends ObjectType>, Integer> counts = collectCounts(task, result);

when("preview for add user bob, org and parent org should be created as well as groups on resource + bob'account should be added to group on resource");
given("org ADD delta");
ObjectDelta<OrgType> delta = createAddDeltaForOrgWithRoleAssignment();

PrismObject<UserType> orgChild = USER_BOB.getObject().clone();
ObjectDelta<UserType> delta = orgChild.createAddDelta();
when("executeChanges is called in simulation mode");
SimulationResult simResult = traced(() -> executeInSimulationMode(List.of(delta), task, result));

ModelContext<UserType> context = modelInteractionService.previewChanges(Collections.singletonList(delta), ModelExecuteOptions.create(), task, result);
then("No extra objects should be created");
assertCollectedCounts(counts, task, result);

then();
and("there are simulation deltas");
simResult.assertNoExecutedDeltas();
List<ObjectDelta<?>> simulatedDeltas = simResult.getSimulatedDeltas();
displayCollection("simulated deltas", simulatedDeltas);
// TODO some asserts here

and("there should be some secondary deltas in model context");
ModelContext<?> context = simResult.getLastModelContext(); // TODO - which one is this? the original or the embedded one
AssertJUnit.assertNotNull(context);
assertCollectedCounts(counts, task, result);
displayDumpable("context", context); // TODO assert the deltas
}

// @Test
// public void test300ReferenceTargetSearch() throws Exception {
// // todo find example
// given();
//
// Task task = getTestTask();
// OperationResult result = task.getResult();
//
// Map<Class<? extends ObjectType>, Integer> counts = collectCounts(task, result);
//
// when();
//
// then();
//
// AssertJUnit.assertNotNull(context);
// assertCollectedCounts(counts, task, result);
// }
/**
* User `bob` has `organization` of "parent:child" which means that he should be in `child` org (CoD)
* that should be in `parent` org (CoD again).
*
* The "no-provisioning" flag is not set, so (simulated) groups and group memberships should be created for the orgs
* and for bob.
*
* Test currently fails because the model tries to link simulated account to simulated user (deep in the CoD chain).
* We'll create simpler tests first, then return to this one.
*/
@Test(enabled = false)
public void test200CreateOnDemandWithProvisioning() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();

Map<Class<? extends ObjectType>, Integer> counts = collectCounts(task, result);

given("user bob ADD delta");
ObjectDelta<UserType> delta = USER_BOB.getObject().clone().createAddDelta();

when("executeChanges is called in simulation mode");
SimulationResult simResult = traced(() -> executeInSimulationMode(List.of(delta), task, result));

then("No extra objects should be created");
assertCollectedCounts(counts, task, result);

and("there are simulation deltas");
simResult.assertNoExecutedDeltas();
List<ObjectDelta<?>> simulatedDeltas = simResult.getSimulatedDeltas();
displayCollection("simulated deltas", simulatedDeltas);
// TODO some asserts here

and("there should be some secondary deltas in model context");
ModelContext<?> context = simResult.getLastModelContext(); // TODO - which one is this? the original or the embedded one
AssertJUnit.assertNotNull(context);
displayDumpable("context", context); // TODO assert the deltas
}

/**
* MID-6166
Expand Down Expand Up @@ -287,7 +329,7 @@ public void test400MultiThreadSupportForCreateOnDemand() throws Exception {

then();

exceptions.forEach(ex -> LOGGER.error("Error occured ", ex));
exceptions.forEach(ex -> LOGGER.error("Error occurred ", ex));

int orgCount = repositoryService.countObjects(OrgType.class, null, null, result);
AssertJUnit.assertEquals("Two org should be present", 2, orgCount);
Expand All @@ -314,14 +356,13 @@ private Callable<Exception> createMultithreadedTask(int id, Task task) {

ObjectDelta<UserType> delta = bob.createAddDelta();

modelService.executeChanges(Collections.singletonList(delta), ModelExecuteOptions.create(), task, result);
modelService.executeChanges(List.of(delta), ModelExecuteOptions.create(), task, result);
return null;
} catch (Exception ex) {
return ex;
} finally {
result.computeStatusIfUnknown();
}

return null;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<name>Org object template</name>

<mapping>
<documentation>Creates a name from identifier</documentation>
<strength>weak</strength>
<source>
<path>identifier</path>
Expand All @@ -37,6 +38,9 @@
</mapping>

<mapping>
<documentation>
Assigns a parent org based on a path in `extension/pc:parentIdentifier` (create on demand, recursively).
</documentation>
<source>
<path>extension/pc:parentIdentifier</path>
</source>
Expand Down Expand Up @@ -114,6 +118,7 @@
</mapping>

<mapping>
<documentation>Creates a description from identifier</documentation>
<strength>weak</strength>
<source>
<path>identifier</path>
Expand All @@ -131,10 +136,11 @@
</mapping>

<mapping>
<documentation>Assigns a metarole</documentation>
<expression>
<assignmentTargetSearch>
<targetType>RoleType</targetType>
<oid>3d82a1af-0380-4368-b80a-b28a8c87b5bb</oid>
<oid>3d82a1af-0380-4368-b80a-b28a8c87b5bb</oid> <!-- metarole for orgs -->
</assignmentTargetSearch>
</expression>
<target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<name>object template user</name>

<mapping>
<documentation>Assigns a parent organization based on `organization` (create on demand, recursively)</documentation>
<source>
<path>organization</path>
</source>
Expand Down Expand Up @@ -81,7 +82,7 @@
<set>
<condition>
<script>
<code>
<code> // FIXME the subtype is not set in the above code
assignment.subtype.contains("org")
</code>
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
xmlns:pc="http://midpoint.evolveum.com/xml/ns/samples/preview-changes">

<name>child org</name>
<description>no-provisioning</description>
<description>no-provisioning</description> <!-- eliminates creation of the projection -->

<extension>
<pc:parentIdentifier>parentOfChild-1</pc:parentIdentifier>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@

<icfc:configurationProperties>
<icfi:instanceId>resource-preview-changes-cod</icfi:instanceId>
<icfi:requireExplicitEnable>true</icfi:requireExplicitEnable>
<icfi:uselessGuardedString>
<clearValue>whatever</clearValue>
</icfi:uselessGuardedString>
<icfi:uselessString>Useless</icfi:uselessString>
<icfi:varyLetterCase>false</icfi:varyLetterCase>
</icfc:configurationProperties>

Expand All @@ -64,13 +59,6 @@
<source>
<path>name</path>
</source>
<expression>
<script>
<code>
name
</code>
</script>
</expression>
</outbound>
</attribute>
<attribute>
Expand Down Expand Up @@ -121,13 +109,6 @@
<source>
<path>name</path>
</source>
<expression>
<script>
<code>
name
</code>
</script>
</expression>
</outbound>
</attribute>
<attribute>
Expand All @@ -140,13 +121,6 @@
<source>
<path>description</path>
</source>
<expression>
<script>
<code>
description
</code>
</script>
</expression>
</outbound>
</attribute>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
oid="1ac00214-ffd0-49db-a1b9-51b46a0e9ae1">

<name>meta role</name>
<documentation>Creates a role assignment for the org. This metarole is assigned manually.</documentation>

<inducement>
<documentation>Creates an assignment to the role named `Role: NAME-Read` (the role is created on demand)</documentation>
<focusMappings>
<mapping>
<name>Create new read role</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
oid="3d82a1af-0380-4368-b80a-b28a8c87b5bb">

<name>role org</name>
<name>metarole for orgs</name>
<documentation>
Creates group (for the org) and memberships (for the org members) - but only if "no-provisioning" flag is not set.
This metarole is assigned automatically by the template.
</documentation>

<inducement>
<description>create group for OrgType</description>
<description>creates group for the org</description>
<construction>
<resourceRef oid="8dfeccc9-e144-4864-a692-e483f4b1873a"/>
<kind>entitlement</kind>
Expand Down Expand Up @@ -84,7 +88,7 @@
</inducement>

<inducement>
<description>create account with group membership for user that has OrgType assigned</description>
<description>creates account with group membership for user that has the org assigned</description>
<construction>
<resourceRef oid="8dfeccc9-e144-4864-a692-e483f4b1873a"/>
<kind>account</kind>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
-->

<user xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3">

<name>bob</name>

<organization>parent:child</organization>
</user>

0 comments on commit ac6b074

Please sign in to comment.