Search in sources :

Example 1 with ModificationPrecondition

use of com.evolveum.midpoint.repo.api.ModificationPrecondition in project midpoint by Evolveum.

the class ModifyTest method test160ModifyWithPrecondition.

@Test
public void test160ModifyWithPrecondition() throws Exception {
    OperationResult result = createOperationResult();
    // GIVEN
    String versionBefore = repositoryService.getVersion(RoleType.class, roleOid, result);
    ModificationPrecondition<RoleType> precondition = o -> {
        throw new PreconditionViolationException("hello");
    };
    // WHEN
    List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(RoleType.class).item(RoleType.F_DESCRIPTION).replace("123456").asItemDeltas();
    try {
        repositoryService.modifyObject(RoleType.class, roleOid, itemDeltas, precondition, getModifyOptions(), result);
        // THEN
        fail("unexpected success");
    } catch (PreconditionViolationException e) {
        assertEquals("Wrong exception message", "hello", e.getMessage());
    }
    String versionAfter = repositoryService.getVersion(RoleType.class, roleOid, result);
    assertEquals("unexpected version change", versionBefore, versionAfter);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) VersionPrecondition(com.evolveum.midpoint.repo.api.VersionPrecondition) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) DOMUtil(com.evolveum.midpoint.util.DOMUtil) PrismTestUtil(com.evolveum.midpoint.prism.util.PrismTestUtil) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) PrismAsserts(com.evolveum.midpoint.prism.util.PrismAsserts) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PreconditionViolationException(com.evolveum.midpoint.repo.api.PreconditionViolationException) List(java.util.List) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) com.evolveum.midpoint.prism.delta(com.evolveum.midpoint.prism.delta) QName(javax.xml.namespace.QName) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) NotNull(org.jetbrains.annotations.NotNull) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) COMPLETED(com.evolveum.midpoint.xml.ns._public.common.common_3.PendingOperationExecutionStatusType.COMPLETED) AssertJUnit(org.testng.AssertJUnit) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Session(org.hibernate.Session) DebugUtil(com.evolveum.midpoint.util.DebugUtil) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ArrayList(java.util.ArrayList) EquivalenceStrategy(com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) DeltaConvertor(com.evolveum.midpoint.schema.DeltaConvertor) ModificationPrecondition(com.evolveum.midpoint.repo.api.ModificationPrecondition) SqlRepoTestUtil(com.evolveum.midpoint.repo.sql.testing.SqlRepoTestUtil) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) GetOperationOptions.createRawCollection(com.evolveum.midpoint.schema.GetOperationOptions.createRawCollection) SynchronizationUtils(com.evolveum.midpoint.common.SynchronizationUtils) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) ItemName(com.evolveum.midpoint.prism.path.ItemName) RepoModifyOptions(com.evolveum.midpoint.repo.api.RepoModifyOptions) SerializationOptions.createSerializeForExport(com.evolveum.midpoint.prism.SerializationOptions.createSerializeForExport) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) MidPointConstants(com.evolveum.midpoint.schema.constants.MidPointConstants) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PreconditionViolationException(com.evolveum.midpoint.repo.api.PreconditionViolationException) Test(org.testng.annotations.Test)

Example 2 with ModificationPrecondition

use of com.evolveum.midpoint.repo.api.ModificationPrecondition in project midpoint by Evolveum.

the class ModifyTest method test162ModifyWithPrecondition2.

@Test
public void test162ModifyWithPrecondition2() throws Exception {
    OperationResult result = createOperationResult();
    // GIVEN
    String versionBefore = repositoryService.getVersion(RoleType.class, roleOid, result);
    ModificationPrecondition<RoleType> precondition = o -> false;
    // WHEN
    List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(RoleType.class).item(RoleType.F_DESCRIPTION).replace("123456").asItemDeltas();
    try {
        repositoryService.modifyObject(RoleType.class, roleOid, itemDeltas, precondition, getModifyOptions(), result);
        // THEN
        fail("unexpected success");
    } catch (PreconditionViolationException e) {
        // ok
        System.out.println("got expected exception: " + e.getMessage());
    }
    String versionAfter = repositoryService.getVersion(RoleType.class, roleOid, result);
    assertEquals("unexpected version change", versionBefore, versionAfter);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) VersionPrecondition(com.evolveum.midpoint.repo.api.VersionPrecondition) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) DOMUtil(com.evolveum.midpoint.util.DOMUtil) PrismTestUtil(com.evolveum.midpoint.prism.util.PrismTestUtil) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) PrismAsserts(com.evolveum.midpoint.prism.util.PrismAsserts) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PreconditionViolationException(com.evolveum.midpoint.repo.api.PreconditionViolationException) List(java.util.List) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) com.evolveum.midpoint.prism.delta(com.evolveum.midpoint.prism.delta) QName(javax.xml.namespace.QName) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) NotNull(org.jetbrains.annotations.NotNull) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) COMPLETED(com.evolveum.midpoint.xml.ns._public.common.common_3.PendingOperationExecutionStatusType.COMPLETED) AssertJUnit(org.testng.AssertJUnit) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Session(org.hibernate.Session) DebugUtil(com.evolveum.midpoint.util.DebugUtil) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ArrayList(java.util.ArrayList) EquivalenceStrategy(com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) DeltaConvertor(com.evolveum.midpoint.schema.DeltaConvertor) ModificationPrecondition(com.evolveum.midpoint.repo.api.ModificationPrecondition) SqlRepoTestUtil(com.evolveum.midpoint.repo.sql.testing.SqlRepoTestUtil) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) GetOperationOptions.createRawCollection(com.evolveum.midpoint.schema.GetOperationOptions.createRawCollection) SynchronizationUtils(com.evolveum.midpoint.common.SynchronizationUtils) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) ItemName(com.evolveum.midpoint.prism.path.ItemName) RepoModifyOptions(com.evolveum.midpoint.repo.api.RepoModifyOptions) SerializationOptions.createSerializeForExport(com.evolveum.midpoint.prism.SerializationOptions.createSerializeForExport) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) MidPointConstants(com.evolveum.midpoint.schema.constants.MidPointConstants) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PreconditionViolationException(com.evolveum.midpoint.repo.api.PreconditionViolationException) Test(org.testng.annotations.Test)

Aggregations

SynchronizationUtils (com.evolveum.midpoint.common.SynchronizationUtils)2 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)2 SerializationOptions.createSerializeForExport (com.evolveum.midpoint.prism.SerializationOptions.createSerializeForExport)2 com.evolveum.midpoint.prism.delta (com.evolveum.midpoint.prism.delta)2 EquivalenceStrategy (com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy)2 ItemName (com.evolveum.midpoint.prism.path.ItemName)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 PrismAsserts (com.evolveum.midpoint.prism.util.PrismAsserts)2 PrismTestUtil (com.evolveum.midpoint.prism.util.PrismTestUtil)2 XmlTypeConverter (com.evolveum.midpoint.prism.xml.XmlTypeConverter)2 ModificationPrecondition (com.evolveum.midpoint.repo.api.ModificationPrecondition)2 PreconditionViolationException (com.evolveum.midpoint.repo.api.PreconditionViolationException)2 RepoModifyOptions (com.evolveum.midpoint.repo.api.RepoModifyOptions)2 VersionPrecondition (com.evolveum.midpoint.repo.api.VersionPrecondition)2 RObject (com.evolveum.midpoint.repo.sql.data.common.RObject)2 SqlRepoTestUtil (com.evolveum.midpoint.repo.sql.testing.SqlRepoTestUtil)2 DeltaConvertor (com.evolveum.midpoint.schema.DeltaConvertor)2