use of com.evolveum.midpoint.repo.sqale.qmodel.ref.MReference in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test160AddingProjectionRefInsertsRowsToTable.
// endregion
// region multi-value refs
@Test
public void test160AddingProjectionRefInsertsRowsToTable() throws Exception {
OperationResult result = createOperationResult();
MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
given("delta adding projection ref to non-existent shadow for user 1");
UUID refTargetOid = UUID.randomUUID();
QName refRelation = QName.valueOf("{https://random.org/ns}projection-rel1");
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(UserType.F_LINK_REF).add(new ObjectReferenceType().oid(refTargetOid.toString()).type(ShadowType.COMPLEX_TYPE).relation(refRelation)).asObjectDelta(user1Oid);
when("modifyObject is called");
repositoryService.modifyObject(UserType.class, user1Oid, delta.getModifications(), result);
then("operation is successful, ref target doesn't have to exist");
assertThatOperationResult(result).isSuccess();
and("serialized form (fullObject) is updated");
UserType userObject = repositoryService.getObject(UserType.class, user1Oid, null, result).asObjectable();
assertThat(userObject.getVersion()).isEqualTo(String.valueOf(originalRow.version + 1));
assertThat(userObject.getLinkRef()).hasSize(1).anyMatch(refMatcher(refTargetOid, refRelation));
and("user row version is incremented");
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(row.version).isEqualTo(originalRow.version + 1);
and("externalized refs are inserted to the dedicated table");
QObjectReference<?> r = QObjectReferenceMapping.getForProjection().defaultAlias();
UUID ownerOid = UUID.fromString(user1Oid);
List<MReference> refs = select(r, r.ownerOid.eq(ownerOid));
assertThat(refs).hasSize(1).anyMatch(refRowMatcher(refTargetOid, MObjectType.SHADOW, refRelation)).allMatch(ref -> ref.ownerOid.equals(ownerOid));
}
Aggregations