-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-use sequence values during approvals
When a sequence value(s) are used during operation being approved, they are now stored along with the approval request. After the request is approved, the same values are applied. Therefore, e.g. for user creation, the properties of user actually created are the same as they were in the creation approval request. This resolves MID-7575. (cherry picked from commit 921c190)
- Loading branch information
Showing
12 changed files
with
298 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
model/workflow-impl/src/test/java/com/evolveum/midpoint/wf/impl/other/TestSequence.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright (C) 2010-2022 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.wf.impl.other; | ||
|
||
import static com.evolveum.midpoint.test.util.MidPointTestConstants.TEST_RESOURCES_DIR; | ||
|
||
import java.io.File; | ||
|
||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.testng.annotations.Test; | ||
|
||
import com.evolveum.midpoint.schema.result.OperationResult; | ||
import com.evolveum.midpoint.schema.util.ObjectTypeUtil; | ||
import com.evolveum.midpoint.schema.util.WorkItemId; | ||
import com.evolveum.midpoint.schema.util.cases.ApprovalUtils; | ||
import com.evolveum.midpoint.task.api.Task; | ||
import com.evolveum.midpoint.test.TestResource; | ||
import com.evolveum.midpoint.wf.impl.AbstractWfTestPolicy; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.*; | ||
|
||
/** | ||
* Test for using sequences in objects being approved. | ||
* | ||
* See MID-7575. | ||
*/ | ||
@ContextConfiguration(locations = { "classpath:ctx-workflow-test-main.xml" }) | ||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) | ||
public class TestSequence extends AbstractWfTestPolicy { | ||
|
||
private static final File TEST_DIR = new File(TEST_RESOURCES_DIR, "sequence"); | ||
|
||
private static final File SYSTEM_CONFIGURATION_FILE = new File(TEST_DIR, "system-configuration.xml"); | ||
|
||
private static final TestResource<SequenceType> SEQUENCE_USER_NAME = | ||
new TestResource<>(TEST_DIR, "sequence-user-name.xml", "84f9d763-bfd9-4edb-9f5b-a49158580e16"); | ||
|
||
private static final TestResource<ObjectTemplateType> TEMPLATE_USER = | ||
new TestResource<>(TEST_DIR, "template-user.xml", "5e156e0f-5844-44d3-a7f7-78df11e3c98a"); | ||
|
||
private String rootCaseOid; | ||
|
||
@Override | ||
public void initSystem(Task initTask, OperationResult initResult) throws Exception { | ||
super.initSystem(initTask, initResult); | ||
addObject(SEQUENCE_USER_NAME, initTask, initResult); | ||
addObject(TEMPLATE_USER, initTask, initResult); | ||
} | ||
|
||
@Override | ||
protected File getSystemConfigurationFile() { | ||
return SYSTEM_CONFIGURATION_FILE; | ||
} | ||
|
||
/** | ||
* Request a user be created. It should be named 100000. | ||
*/ | ||
@Test | ||
public void test100RequestUserCreation() throws Exception { | ||
given(); | ||
Task task = getTestTask(); | ||
OperationResult result = task.getResult(); | ||
login(USER_ADMINISTRATOR_USERNAME); | ||
|
||
when("user creation is requested"); | ||
UserType user = new UserType() | ||
.fullName("Joe Black"); | ||
|
||
addObject(user.asPrismObject(), task, result); | ||
|
||
then("an approval case should be created"); | ||
|
||
// @formatter:off | ||
CaseType rootCase = assertCase(result, "after") | ||
.display() | ||
.displayXml() | ||
.subcases() | ||
.single() | ||
.display() | ||
.end() | ||
.end() | ||
.getObjectable(); | ||
// @formatter:on | ||
|
||
rootCaseOid = rootCase.getOid(); | ||
|
||
and("the user to be created should have a name of 100000 (start of sequence)"); | ||
UserType userToCreate = (UserType) ObjectTypeUtil.getObjectFromReference(rootCase.getObjectRef()); | ||
assertUser(userToCreate, "user to create") | ||
.display() | ||
.assertName("100000") | ||
.assertFullName("Joe Black"); | ||
|
||
assertNoObjectByName(UserType.class, "100000", task, result); | ||
} | ||
|
||
/** | ||
* Approve user creation. The created user should have the same name as the one that was being approved (100000). | ||
*/ | ||
@Test | ||
public void test110ApproveUserCreation() throws Exception { | ||
given(); | ||
Task task = getTestTask(); | ||
OperationResult result = task.getResult(); | ||
|
||
when("creation is approved"); | ||
CaseWorkItemType workItem = getWorkItem(task, result); | ||
caseService.completeWorkItem( | ||
WorkItemId.of(workItem), | ||
ApprovalUtils.createApproveOutput(), | ||
task, | ||
result); | ||
|
||
then("user is created with the same name"); | ||
waitForCaseClose(getCase(rootCaseOid), 20000); | ||
|
||
assertUserAfterByUsername("100000") | ||
.assertFullName("Joe Black"); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
model/workflow-impl/src/test/resources/sequence/sequence-user-name.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- | ||
~ Copyright (C) 2010-2022 Evolveum and contributors | ||
~ | ||
~ This work is dual-licensed under the Apache License 2.0 | ||
~ and European Union Public License. See LICENSE file for details. | ||
--> | ||
|
||
<sequence xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3" | ||
oid="84f9d763-bfd9-4edb-9f5b-a49158580e16"> | ||
<name>sequence-user-name</name> | ||
<counter>100000</counter> | ||
<maxUnusedValues>10</maxUnusedValues> | ||
</sequence> |
36 changes: 36 additions & 0 deletions
36
model/workflow-impl/src/test/resources/sequence/system-configuration.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<!-- | ||
~ Copyright (C) 2010-2022 Evolveum and contributors | ||
~ | ||
~ This work is dual-licensed under the Apache License 2.0 | ||
~ and European Union Public License. See LICENSE file for details. | ||
--> | ||
|
||
<systemConfiguration oid="00000000-0000-0000-0000-000000000001" | ||
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"> | ||
<name>SystemConfiguration</name> | ||
<defaultObjectPolicyConfiguration> | ||
<objectTemplateRef oid="5e156e0f-5844-44d3-a7f7-78df11e3c98a" /> | ||
<type>UserType</type> | ||
</defaultObjectPolicyConfiguration> | ||
<workflowConfiguration> | ||
<useLegacyApproversSpecification>never</useLegacyApproversSpecification> | ||
<useDefaultApprovalPolicyRules>never</useDefaultApprovalPolicyRules> | ||
</workflowConfiguration> | ||
<globalPolicyRule> | ||
<name>User creation approval</name> | ||
<policyConstraints> | ||
<modification> | ||
<operation>add</operation> | ||
</modification> | ||
</policyConstraints> | ||
<policyActions> | ||
<approval> | ||
<approverRef oid="00000000-0000-0000-0000-000000000002" type="UserType"/> | ||
</approval> | ||
</policyActions> | ||
<focusSelector> | ||
<type>UserType</type> | ||
</focusSelector> | ||
</globalPolicyRule> | ||
</systemConfiguration> |
23 changes: 23 additions & 0 deletions
23
model/workflow-impl/src/test/resources/sequence/template-user.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!-- | ||
~ Copyright (C) 2010-2022 Evolveum and contributors | ||
~ | ||
~ This work is dual-licensed under the Apache License 2.0 | ||
~ and European Union Public License. See LICENSE file for details. | ||
--> | ||
|
||
<objectTemplate | ||
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3" | ||
oid="5e156e0f-5844-44d3-a7f7-78df11e3c98a"> | ||
<name>template-user</name> | ||
<item> | ||
<ref>name</ref> | ||
<mapping> | ||
<strength>weak</strength> | ||
<expression> | ||
<sequentialValue> | ||
<sequenceRef oid="84f9d763-bfd9-4edb-9f5b-a49158580e16"/> | ||
</sequentialValue> | ||
</expression> | ||
</mapping> | ||
</item> | ||
</objectTemplate> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.