use of com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser 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));
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test811ModifyDynamicallyWithFailingSupplier.
@Test
public void test811ModifyDynamicallyWithFailingSupplier() {
OperationResult result = createOperationResult();
MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
expect("modifyObjectDynamically with failing supplier fails");
Assertions.assertThatThrownBy(() -> repositoryService.modifyObjectDynamically(UserType.class, user1Oid, null, u -> {
throw new RuntimeException("Random exception");
}, null, result)).isInstanceOf(SystemException.class).hasMessage("Random exception");
and("operation is fatal error and modification is not executed");
assertThatOperationResult(result).isFatalError();
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(row.version).isEqualTo(originalRow.version);
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test305DeleteAssignmentByContent.
@Test
public // or by value, or by equality
void test305DeleteAssignmentByContent() throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
OperationResult result = createOperationResult();
MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
given("delta deleting assignments without CID by equality for user 1");
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).delete(new AssignmentType(prismContext).order(50)).asObjectDelta(user1Oid);
when("modifyObject is called");
repositoryService.modifyObject(UserType.class, user1Oid, delta.getModifications(), result);
then("operation is successful");
assertThatOperationResult(result).isSuccess();
and("serialized form (fullObject) is updated and assignments with only order 50");
UserType userObject = repositoryService.getObject(UserType.class, user1Oid, null, result).asObjectable();
assertThat(userObject.getVersion()).isEqualTo(String.valueOf(originalRow.version + 1));
List<AssignmentType> assignments = userObject.getAssignment();
assertThat(assignments).hasSize(2).anyMatch(a -> a.getOrder().equals(47)).anyMatch(ass -> ass.getOrder() == 50 && ass.getTargetRef() != null);
and("corresponding assignment row is deleted");
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(row.version).isEqualTo(originalRow.version + 1);
QAssignment<?> a = QAssignmentMapping.getAssignmentMapping().defaultAlias();
List<MAssignment> aRows = select(a, a.ownerOid.eq(UUID.fromString(user1Oid)));
assertThat(aRows).hasSize(2).anyMatch(aRow -> aRow.orderValue.equals(47)).anyMatch(ass -> ass.orderValue == 50 && ass.targetRefTargetOid != null);
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test303ModificationsOnOneAssignmentDoesNotAffectOthers.
@Test
public void test303ModificationsOnOneAssignmentDoesNotAffectOthers() throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
OperationResult result = createOperationResult();
MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
given("delta changing item inside single assignments for user 1");
QAssignment<?> a = QAssignmentMapping.getAssignmentMapping().defaultAlias();
long assOrder49Cid = selectOne(a, a.ownerOid.eq(UUID.fromString(user1Oid)), a.orderValue.eq(49)).cid;
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT, assOrder49Cid, AssignmentType.F_ORDER).replace(50).asObjectDelta(user1Oid);
when("modifyObject is called");
repositoryService.modifyObject(UserType.class, user1Oid, delta.getModifications(), result);
then("operation is successful");
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));
List<AssignmentType> assignments = UserObject.getAssignment();
assertThat(assignments).hasSize(3).anyMatch(ass -> ass.getOrder() == 47).anyMatch(ass -> ass.getOrder() == 48).anyMatch(ass -> ass.getOrder() == 50);
and("assignment row is modified");
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(row.version).isEqualTo(originalRow.version + 1);
MAssignment aRow = selectOne(a, a.ownerOid.eq(UUID.fromString(user1Oid)), a.cid.eq(assOrder49Cid));
assertThat(aRow.orderValue).isEqualTo(50);
and("no other assignment rows are modified");
assertThat(count(a, a.ownerOid.eq(UUID.fromString(user1Oid)), a.orderValue.eq(50))).isEqualTo(1);
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test211DeleteDeeplyNestedFocusPasswordCreateTimestamp.
@Test
public void test211DeleteDeeplyNestedFocusPasswordCreateTimestamp() throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
OperationResult result = createOperationResult();
given("delta with metadata/createChannel status replace to null ('delete') for user 1");
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(FocusType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_METADATA, MetadataType.F_CREATE_TIMESTAMP).replace().asObjectDelta(user1Oid);
and("user row previously having the passwordCreateTimestamp value");
MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
assertThat(originalRow.passwordCreateTimestamp).isNotNull();
when("modifyObject is called");
repositoryService.modifyObject(UserType.class, user1Oid, delta.getModifications(), result);
then("operation is successful");
assertThatOperationResult(result).isSuccess();
and("serialized form (fullObject) is updated and password create timestamp is gone");
UserType userObject = repositoryService.getObject(UserType.class, user1Oid, null, result).asObjectable();
assertThat(userObject.getVersion()).isEqualTo(String.valueOf(originalRow.version + 1));
assertTrue(// if removed with last item
userObject.getCredentials() == null || userObject.getCredentials().getPassword() == null || userObject.getCredentials().getPassword().getMetadata() == null || userObject.getCredentials().getPassword().getMetadata().getCreateTimestamp() == null);
and("externalized column is set to NULL");
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(row.version).isEqualTo(originalRow.version + 1);
assertThat(row.passwordCreateTimestamp).isNull();
}
Aggregations