From e70c84ad84b06a92c5e4a2b6face8e8c29e1ae3d Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Sat, 30 May 2020 09:24:41 +0200 Subject: [PATCH] Expand "dependent children" linked objects test Project sub-orgs (project_users, project_groups) are automatically created/modified/deleted on project creation/rename/deletion. --- .../model/intest/TestLinkedObjects.java | 62 ++++++++- .../linked/archetype-project-groups.xml | 37 ++++++ .../linked/archetype-project-users.xml | 37 ++++++ .../resources/linked/archetype-project.xml | 122 +++++++++--------- .../resources/linked/system-configuration.xml | 31 +++++ 5 files changed, 228 insertions(+), 61 deletions(-) create mode 100644 model/model-intest/src/test/resources/linked/archetype-project-groups.xml create mode 100644 model/model-intest/src/test/resources/linked/archetype-project-users.xml diff --git a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestLinkedObjects.java b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestLinkedObjects.java index 4fa52660bb0..a1b7468bf54 100644 --- a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestLinkedObjects.java +++ b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestLinkedObjects.java @@ -13,6 +13,7 @@ import org.springframework.test.context.ContextConfiguration; import org.testng.annotations.Test; +import com.evolveum.midpoint.prism.PrismObject; import com.evolveum.midpoint.prism.delta.ObjectDelta; import com.evolveum.midpoint.prism.polystring.PolyString; import com.evolveum.midpoint.schema.constants.SchemaConstants; @@ -51,8 +52,10 @@ public class TestLinkedObjects extends AbstractEmptyModelIntegrationTest { private static final TestResource USER_GRAMMI = new TestResource<>(TEST_DIR, "user-grammi.xml", "041d0c03-c322-4e0d-89ba-a2d49b732674"); private static final TestResource USER_CUBBY = new TestResource<>(TEST_DIR, "user-cubby.xml", "7b8f2e00-a49e-40ff-a4bd-11b70bac89d3"); - // Separate scenario + // Separate scenario (projects and sub-orgs) private static final TestResource ARCHETYPE_PROJECT = new TestResource<>(TEST_DIR, "archetype-project.xml", "4d3280a1-6514-4984-ac2c-7e56c05af258"); + private static final TestResource ARCHETYPE_PROJECT_USERS = new TestResource<>(TEST_DIR, "archetype-project-users.xml", "3af67ba4-183f-45e7-887e-4ae5ddff4cdf"); + private static final TestResource ARCHETYPE_PROJECT_GROUPS = new TestResource<>(TEST_DIR, "archetype-project-groups.xml", "a85bddc9-4ff0-475f-8ccc-17f9038d4ce1"); @Override public void initSystem(Task initTask, OperationResult initResult) throws Exception { @@ -77,6 +80,8 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti addObject(USER_CUBBY, initTask, initResult); addObject(ARCHETYPE_PROJECT, initTask, initResult); + addObject(ARCHETYPE_PROJECT_USERS, initTask, initResult); + addObject(ARCHETYPE_PROJECT_GROUPS, initTask, initResult); // predefinedTestMethodTracing = PredefinedTestMethodTracing.MODEL_LOGGING; } @@ -482,7 +487,7 @@ public void test300CreateNewWhistleHolder() throws Exception { * Creates a project. Two children should be created automatically. */ @Test - public void test900CreateProject() throws Exception { + public void test700CreateProject() throws Exception { given(); Task task = getTestTask(); OperationResult result = task.getResult(); @@ -509,4 +514,57 @@ public void test900CreateProject() throws Exception { .display() .assertParentOrgRefs(ariane.getOid()); } + + /** + * Renames a project. Children should be renamed automatically. + */ + @Test + public void test710RenameProject() throws Exception { + given(); + Task task = getTestTask(); + OperationResult result = task.getResult(); + + when(); + PrismObject ariane = assertSingleObjectByName(OrgType.class, "ariane", task, result); + ObjectDelta delta = deltaFor(OrgType.class) + .item(OrgType.F_NAME).replace(PolyString.fromOrig("ariane5")) + .asObjectDelta(ariane.getOid()); + + executeChanges(delta, null, task, result); + + then(); + assertSuccess(result); + + assertOrgAfter(ariane.getOid()) + .assertName("ariane5"); + + assertOrgByName("ariane5_users", "after") + .display() + .assertParentOrgRefs(ariane.getOid()); + + assertOrgByName("ariane5_groups", "after") + .display() + .assertParentOrgRefs(ariane.getOid()); + } + + /** + * Deletes a project. Children should be deleted automatically. + */ + @Test + public void test720DeleteProject() throws Exception { + given(); + Task task = getTestTask(); + OperationResult result = task.getResult(); + + when(); + PrismObject ariane5 = assertSingleObjectByName(OrgType.class, "ariane5", task, result); + deleteObject(OrgType.class, ariane5.getOid(), task, result); + + then(); + assertSuccess(result); + + assertNoObjectByName(OrgType.class, "ariane5", task, result); + assertNoObjectByName(OrgType.class, "ariane5_users", task, result); + assertNoObjectByName(OrgType.class, "ariane5_groups", task, result); + } } diff --git a/model/model-intest/src/test/resources/linked/archetype-project-groups.xml b/model/model-intest/src/test/resources/linked/archetype-project-groups.xml new file mode 100644 index 00000000000..252de2647bd --- /dev/null +++ b/model/model-intest/src/test/resources/linked/archetype-project-groups.xml @@ -0,0 +1,37 @@ + + + + project-groups + + "Groups" sub-org for project org. + + + + + + strong + + + + + name + + + + + + diff --git a/model/model-intest/src/test/resources/linked/archetype-project-users.xml b/model/model-intest/src/test/resources/linked/archetype-project-users.xml new file mode 100644 index 00000000000..4460ce77b1e --- /dev/null +++ b/model/model-intest/src/test/resources/linked/archetype-project-users.xml @@ -0,0 +1,37 @@ + + + + project-users + + "Users" sub-org for project org. + + + + + + strong + + + + + name + + + + + + diff --git a/model/model-intest/src/test/resources/linked/archetype-project.xml b/model/model-intest/src/test/resources/linked/archetype-project.xml index be5035b3966..9d6efb41ac9 100644 --- a/model/model-intest/src/test/resources/linked/archetype-project.xml +++ b/model/model-intest/src/test/resources/linked/archetype-project.xml @@ -7,11 +7,13 @@ project - A project has two child objects: users and groups. These are to be created when project is created. + A project has two child objects: users and groups. + 1. These are to be created when project is created. + 2. They need to be deleted when project is deleted. + 3. They need to be renamed when project is renamed. @@ -30,39 +32,37 @@ - - - execute-script - - script - - - import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType + + + + import com.evolveum.midpoint.xml.ns._public.common.common_3.ArchetypeType + import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType - users = new OrgType(prismContext) - .name(input.name + '_users') - .beginAssignment() - .targetRef(input.oid, OrgType.COMPLEX_TYPE) - .end() + ARCHETYPE_USERS_OID = '3af67ba4-183f-45e7-887e-4ae5ddff4cdf' + ARCHETYPE_GROUPS_OID = 'a85bddc9-4ff0-475f-8ccc-17f9038d4ce1' - groups = new OrgType(prismContext) - .name(input.name + '_groups') - .beginAssignment() - .targetRef(input.oid, OrgType.COMPLEX_TYPE) - .end() + users = new OrgType(prismContext) + .beginAssignment() + .targetRef(input.oid, OrgType.COMPLEX_TYPE) + .end() + .beginAssignment() + .targetRef(ARCHETYPE_USERS_OID, ArchetypeType.COMPLEX_TYPE) + .end() - [users, groups] // Returning two objects - they will be created in the second action - - - - - outputItem - OrgType - - - - add - + groups = new OrgType(prismContext) + .beginAssignment() + .targetRef(input.oid, OrgType.COMPLEX_TYPE) + .end() + .beginAssignment() + .targetRef(ARCHETYPE_GROUPS_OID, ArchetypeType.COMPLEX_TYPE) + .end() + + [users, groups] // Returning two objects - they will be created in the second action + + + OrgType + + @@ -71,56 +71,59 @@ 1 - - + - recompute-device-on-user-name-change - Recomputes a device when user's name or fullName changes. + delete-children-on-project-deletion + + Deletes children when project is deleted. + - - - name - - - fullName - - + + delete + - - - true - + + OrgType + + + - + - 2 + 1 - recompute-device-on-membership-change + recompute-children-on-project-rename - Recomputes all devices whose membership has changed. + Recomputes children when the project is renamed. - + + modify + name + - - changed - - true - + + OrgType + + + @@ -128,6 +131,7 @@ - 2 + 1 + diff --git a/model/model-intest/src/test/resources/linked/system-configuration.xml b/model/model-intest/src/test/resources/linked/system-configuration.xml index 6346c3f5360..8620949fcd5 100644 --- a/model/model-intest/src/test/resources/linked/system-configuration.xml +++ b/model/model-intest/src/test/resources/linked/system-configuration.xml @@ -48,4 +48,35 @@ + + + + OrgType + + + delete-children-on-project-deletion + + Deletes children when project is deleted. + + + + delete + + + + + + + OrgType + + + + + + + + + + +