use of com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test990ChangeOfNonPersistedAttributeWorksOk.
@Test
public void test990ChangeOfNonPersistedAttributeWorksOk() throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
OperationResult result = createOperationResult();
MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
given("delta with email change for user 1 using property add modification");
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(UserType.F_DESCRIPTION).replace("Description only in serialized form.").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));
assertThat(userObject.getDescription()).isEqualTo("Description only in serialized form.");
and("externalized version is updated");
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(row.version).isEqualTo(originalRow.version + 1);
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test101ChangeStringAttributeWithPreviousValueUsingAddModification.
/**
* NOTE: This test documents current behavior where {@link ItemDelta#applyTo(Item)} interprets
* ADD for single-value item as REPLACE if the value is not empty.
* This behavior is likely to change.
*/
@Test
public void test101ChangeStringAttributeWithPreviousValueUsingAddModification() throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
OperationResult result = createOperationResult();
MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
given("delta with email change for user 1 using property add modification");
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(UserType.F_EMAIL_ADDRESS).add("new2@email.com").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 old value is overridden");
UserType userObject = repositoryService.getObject(UserType.class, user1Oid, null, result).asObjectable();
assertThat(userObject.getVersion()).isEqualTo(String.valueOf(originalRow.version + 1));
assertThat(userObject.getEmailAddress()).isEqualTo("new2@email.com");
and("externalized column is updated");
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(row.version).isEqualTo(originalRow.version + 1);
assertThat(row.emailAddress).isEqualTo("new2@email.com");
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test136ObjectNameCantBeRemoved.
@Test
public void test136ObjectNameCantBeRemoved() throws ObjectNotFoundException, SchemaException {
OperationResult result = createOperationResult();
MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
given("delta with object name replace with null for user 1");
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(UserType.F_NAME).replace().asObjectDelta(user1Oid);
expect("modifyObject throws exception");
assertThatThrownBy(() -> repositoryService.modifyObject(UserType.class, user1Oid, delta.getModifications(), result)).isInstanceOf(SystemException.class).hasCauseInstanceOf(com.querydsl.core.QueryException.class);
and("operation is fatal error");
assertThatOperationResult(result).isFatalError();
and("serialized form (fullObject) is not updated");
UserType userObject = repositoryService.getObject(UserType.class, user1Oid, null, result).asObjectable();
assertThat(userObject.getVersion()).isEqualTo(String.valueOf(originalRow.version));
assertThat(userObject.getName()).isNotNull();
and("externalized column is set to NULL");
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(row.version).isEqualTo(originalRow.version);
assertThat(row.nameOrig).isNotNull();
assertThat(row.nameNorm).isNotNull();
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser in project midpoint by Evolveum.
the class SqaleRepoAddDeleteObjectTest method test300AddObjectWithIndexedStringExtension.
// endregion
// region extension attributes
@Test
public void test300AddObjectWithIndexedStringExtension() throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException {
OperationResult result = createOperationResult();
given("object with string extension item");
String objectName = "user" + getTestNumber();
UserType object = new UserType(prismContext).name(objectName).extension(new ExtensionType(prismContext));
ExtensionType extensionContainer = object.getExtension();
addExtensionValue(extensionContainer, "string", "string-value");
when("adding it to the repository");
String returnedOid = repositoryService.addObject(object.asPrismObject(), null, result);
then("operation is successful and ext column contains the value");
assertThatOperationResult(result).isSuccess();
assertThat(returnedOid).isEqualTo(object.getOid());
MUser row = selectObjectByOid(QUser.class, returnedOid);
assertThat(row.oid).isEqualTo(UUID.fromString(returnedOid));
assertThat(row.ext).isNotNull();
assertThat(Jsonb.toMap(row.ext)).containsEntry(extensionKey(extensionContainer, "string"), "string-value");
and("stored object contains the extension item");
PrismObject<UserType> storedObject = repositoryService.getObject(UserType.class, returnedOid, null, result);
assertThat(storedObject.getExtension().findItem(new ItemName("string"))).isNotNull().extracting(i -> i.getRealValue()).isEqualTo("string-value");
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser in project midpoint by Evolveum.
the class SqaleRepoAddDeleteObjectTest method test307AddObjectWithExtensionReferenceAndPolyString.
@Test
public void test307AddObjectWithExtensionReferenceAndPolyString() throws ObjectAlreadyExistsException, SchemaException {
OperationResult result = createOperationResult();
given("object with extension reference and poly string");
String objectName = "user" + getTestNumber();
UserType object = new UserType(prismContext).name(objectName).extension(new ExtensionType(prismContext));
ExtensionType extensionContainer = object.getExtension();
addExtensionValue(extensionContainer, "poly", PolyString.fromOrig("poly-value"));
String targetOid = UUID.randomUUID().toString();
QName relation = QName.valueOf("{https://random.org/ns}random-rel-1");
addExtensionValue(extensionContainer, "ref", ref(targetOid, UserType.COMPLEX_TYPE, relation));
when("adding it to the repository");
String returnedOid = repositoryService.addObject(object.asPrismObject(), null, result);
then("operation is successful and ext column stores the values as nested objects");
assertThatOperationResult(result).isSuccess();
assertThat(returnedOid).isEqualTo(object.getOid());
MUser row = selectObjectByOid(QUser.class, returnedOid);
assertThat(row.ext).isNotNull();
assertThat(Jsonb.toMap(row.ext)).containsEntry(extensionKey(extensionContainer, "poly"), Map.of("o", "poly-value", "n", "polyvalue")).containsEntry(extensionKey(extensionContainer, "ref"), Map.of("o", targetOid, "t", MObjectType.USER.name(), "r", cachedUriId(relation)));
}
Aggregations