From 0a42867fb918a7363dec6e58fa230e293973a3ea Mon Sep 17 00:00:00 2001 From: Viliam Repan Date: Tue, 6 Feb 2018 13:51:04 +0100 Subject: [PATCH] some assignment update tests --- .../repo/sql/ObjectDeltaUpdaterTest.java | 119 +++++++++++++----- .../src/test/resources/update/user.xml | 8 +- 2 files changed, 96 insertions(+), 31 deletions(-) diff --git a/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/ObjectDeltaUpdaterTest.java b/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/ObjectDeltaUpdaterTest.java index f6701239b5f..eefdeb272ee 100644 --- a/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/ObjectDeltaUpdaterTest.java +++ b/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/ObjectDeltaUpdaterTest.java @@ -26,6 +26,7 @@ import com.evolveum.midpoint.repo.sql.data.common.RUser; import com.evolveum.midpoint.repo.sql.data.common.any.RAnyValue; import com.evolveum.midpoint.repo.sql.data.common.container.RAssignment; +import com.evolveum.midpoint.repo.sql.data.common.embedded.RActivation; import com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString; import com.evolveum.midpoint.repo.sql.data.common.enums.RActivationStatus; import com.evolveum.midpoint.repo.sql.testing.QueryCountInterceptor; @@ -46,14 +47,8 @@ import javax.xml.namespace.QName; import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; +import java.util.*; import java.util.Objects; -import java.util.Set; - -//import com.evolveum.midpoint.repo.sql.helpers.EntityModificationRegistry; -//import com.evolveum.midpoint.repo.sql.helpers.ObjectDeltaUpdater; /** * Created by Viliam Repan (lazyman). @@ -129,6 +124,32 @@ public void test100UpdateGivenNameAndActivation() throws Exception { } } + @Test + public void test115DeleteActivation() throws Exception { + OperationResult result = new OperationResult("test115DeleteActivation"); + + ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext); + + ActivationType activation = new ActivationType(); + activation.setAdministrativeStatus(ActivationStatusType.DISABLED); + + delta.addModificationDeleteContainer(UserType.F_ACTIVATION, activation.asPrismContainerValue()); + + queryCountInterceptor.startCounter(); + repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result); + + AssertJUnit.assertEquals(3, queryCountInterceptor.getQueryCount()); + + Session session = factory.openSession(); + try { + RUser u = session.get(RUser.class, userOid); + + AssertJUnit.assertNull(u.getActivation()); + } finally { + session.close(); + } + } + @Test public void test110ReplaceExtensionProperty() throws Exception { OperationResult result = new OperationResult("test110ReplaceExtensionProperty"); @@ -249,12 +270,73 @@ public void test140AddDeleteAssignment() throws Exception { } } + @Test + public void test145AddActivationToAssignment() throws Exception { + OperationResult result = new OperationResult("test145AddActivationToAssignment"); + + ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext); + + ActivationType activation = new ActivationType(); + activation.setAdministrativeStatus(ActivationStatusType.ENABLED); + delta.addModificationAddContainer( + new ItemPath(UserType.F_ASSIGNMENT, 2, AssignmentType.F_ACTIVATION), activation.asPrismContainerValue()); + + queryCountInterceptor.startCounter(); + repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result); + + AssertJUnit.assertEquals(4, queryCountInterceptor.getQueryCount()); + + Session session = factory.openSession(); + try { + RUser u = session.get(RUser.class, userOid); + + Set assignments = u.getAssignments(); + AssertJUnit.assertEquals(1, assignments.size()); + + RAssignment a = assignments.iterator().next(); + RActivation act = a.getActivation(); + AssertJUnit.assertNotNull(act); + + AssertJUnit.assertEquals(RActivationStatus.ENABLED, act.getAdministrativeStatus()); + } finally { + session.close(); + } + } + + @Test + public void test150AddDeleteLinkRef() throws Exception { + OperationResult result = new OperationResult("test150AddDeleteLinkRef"); + + ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext); + ObjectReferenceType linkRef = createRef(ShadowType.COMPLEX_TYPE, "456"); + delta.addModificationDeleteReference(UserType.F_LINK_REF, linkRef.asReferenceValue()); + + linkRef = createRef(ShadowType.COMPLEX_TYPE, "789"); + delta.addModificationAddReference(UserType.F_LINK_REF, linkRef.asReferenceValue()); + + queryCountInterceptor.startCounter(); + repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result); + + AssertJUnit.assertEquals(5, queryCountInterceptor.getQueryCount()); + + Session session = factory.openSession(); + try { + RUser u = session.get(RUser.class, userOid); + + assertReferences((Collection) u.getLinkRef(), + RObjectReference.copyFromJAXB(createRef(ShadowType.COMPLEX_TYPE, "123", SchemaConstants.ORG_DEFAULT), new RObjectReference()), + RObjectReference.copyFromJAXB(createRef(ShadowType.COMPLEX_TYPE, "789", SchemaConstants.ORG_DEFAULT), new RObjectReference())); + } finally { + session.close(); + } + } + @Test public void test160AddDeleteParentRef() throws Exception { OperationResult result = new OperationResult("test160AddDeleteParentRef"); ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext); - ObjectReferenceType parentOrgRef = createRef(OrgType.COMPLEX_TYPE, "123"); + ObjectReferenceType parentOrgRef = createRef(OrgType.COMPLEX_TYPE, "456"); delta.addModificationDeleteReference(UserType.F_PARENT_ORG_REF, parentOrgRef.asReferenceValue()); parentOrgRef = createRef(OrgType.COMPLEX_TYPE, "789"); @@ -270,7 +352,7 @@ public void test160AddDeleteParentRef() throws Exception { RUser u = session.get(RUser.class, userOid); assertReferences((Collection) u.getParentOrgRef(), - RObjectReference.copyFromJAXB(createRef(OrgType.COMPLEX_TYPE, "456", SchemaConstants.ORG_DEFAULT), new RObjectReference()), + RObjectReference.copyFromJAXB(createRef(OrgType.COMPLEX_TYPE, "123", SchemaConstants.ORG_DEFAULT), new RObjectReference()), RObjectReference.copyFromJAXB(createRef(OrgType.COMPLEX_TYPE, "789", SchemaConstants.ORG_DEFAULT), new RObjectReference())); } finally { session.close(); @@ -310,7 +392,6 @@ private void assertReferences(Collection collection, ObjectRefe } } - @Test public void test170ModifyEmployeeTypeAndMetadataCreateChannel() throws Exception { OperationResult result = new OperationResult("test170ModifyEmployeeTypeAndMetadataCreateChannel"); @@ -357,22 +438,4 @@ public void test180ModifyMetadataChannel() throws Exception { assertReferences((Collection) u.getCreateApproverRef(), RObjectReference.copyFromJAXB(createRef(UserType.COMPLEX_TYPE, "111", SchemaConstants.ORG_DEFAULT), new RObjectReference())); } - - public void addLinkRef() throws Exception { - String oid = null; - -// ObjectDelta delta = ObjectDelta.createModificationAddReference(UserType.class, oid, UserType.F_LINK_REF, -// prismContext, "123"); - - ObjectDelta delta = ObjectDelta.createModificationReplaceProperty(UserType.class, oid, UserType.F_GIVEN_NAME, - prismContext, new PolyString("asdf", "asdf")); - -// delta.addModificationReplaceProperty( -// new ItemPath(UserType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS), ActivationStatusType.DISABLED); - -// ActivationType activation = new ActivationType(); -// activation.setAdministrativeStatus(ActivationStatusType.ENABLED); -// delta.addModificationAddContainer( -// new ItemPath(UserType.F_ASSIGNMENT, 1, AssignmentType.F_ACTIVATION), activation.asPrismContainerValue()); - } } diff --git a/repo/repo-sql-impl-test/src/test/resources/update/user.xml b/repo/repo-sql-impl-test/src/test/resources/update/user.xml index 524a4e252c7..c5fd79a1278 100644 --- a/repo/repo-sql-impl-test/src/test/resources/update/user.xml +++ b/repo/repo-sql-impl-test/src/test/resources/update/user.xml @@ -20,9 +20,9 @@ xmlns:p="http://example.com/p"> add link user Add Link - - - + + enabled + sig @@ -31,4 +31,6 @@ + + \ No newline at end of file