use of com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test502AddingAndDeletingMultipleExtensionItems.
@Test
public void test502AddingAndDeletingMultipleExtensionItems() throws Exception {
OperationResult result = createOperationResult();
MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
given("delta adding int extension item");
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(FocusType.F_EXTENSION, new QName("int")).replace(47).item(FocusType.F_EXTENSION, new QName("string-mv")).add("s1", "s2", "s3", "s4").item(FocusType.F_EXTENSION, new QName("string")).delete("string-value500").item(FocusType.F_EXTENSION, new QName("poly-mv")).add(new PolyString("poly-ext1"), new PolyString("poly-ext2")).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 user = repositoryService.getObject(UserType.class, user1Oid, null, result).asObjectable();
assertThat(user.getVersion()).isEqualTo(String.valueOf(originalRow.version + 1));
// no check of ext container, we believe in prism here
and("externalized column is updated");
ExtensionType extensionContainer = user.getExtension();
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(row.version).isEqualTo(originalRow.version + 1);
assertThat(row.ext).isNotNull();
assertThat(Jsonb.toMap(row.ext)).doesNotContainKey(// deleted
extensionKey(extensionContainer, "string")).containsEntry(extensionKey(extensionContainer, "int"), // replaced
47).containsEntry(// added
extensionKey(extensionContainer, "string-mv"), List.of("s1", "s2", "s3", "s4")).containsEntry(extensionKey(extensionContainer, "poly-mv"), List.of(Map.of("o", "poly-ext1", "n", "polyext1"), Map.of("o", "poly-ext2", "n", "polyext2")));
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test191AddingAndDeletingOrganizationValuesSetsArrayColumn.
@Test
public void test191AddingAndDeletingOrganizationValuesSetsArrayColumn() throws Exception {
OperationResult result = createOperationResult();
given("delta for subtypes with both delete and add values");
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(UserType.F_ORGANIZATION).delete(new PolyString("orgmod-2"), new PolyString("wrong")).add(new PolyString("orgmod-3"), new PolyString("orgmod-4")).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 has expected subtypes");
UserType userObject = repositoryService.getObject(UserType.class, user1Oid, null, result).asObjectable();
assertThat(userObject.getOrganization()).extracting(p -> p.getOrig()).containsExactlyInAnyOrder("orgmod-1", "orgmod-3", "orgmod-4");
and("column with subtypes is updated");
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(Jsonb.toList(row.organizations)).containsExactlyInAnyOrder(Map.of("o", "orgmod-1", "n", "orgmod1"), Map.of("o", "orgmod-3", "n", "orgmod3"), Map.of("o", "orgmod-4", "n", "orgmod4"));
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test171DeletingMetadataContainerRemovesContainedRefs.
@Test
public void test171DeletingMetadataContainerRemovesContainedRefs() throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
OperationResult result = createOperationResult();
MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
given("delta to replace metadata with no value");
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(UserType.F_METADATA).replace().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 has no metadata");
UserType userObject = repositoryService.getObject(UserType.class, user1Oid, null, result).asObjectable();
assertThat(userObject.getVersion()).isEqualTo(String.valueOf(originalRow.version + 1));
assertThat(userObject.getMetadata()).isNull();
and("externalized refs under metadata are removed");
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(row.version).isEqualTo(originalRow.version + 1);
QObjectReference<?> r = QObjectReferenceMapping.getForCreateApprover().defaultAlias();
assertThat(count(r, r.ownerOid.eq(UUID.fromString(user1Oid)))).isZero();
r = QObjectReferenceMapping.getForModifyApprover().defaultAlias();
assertThat(count(r, r.ownerOid.eq(UUID.fromString(user1Oid)))).isZero();
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test506SettingExtensionContainerValue.
@Test
public void test506SettingExtensionContainerValue() throws Exception {
OperationResult result = createOperationResult();
MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
given("delta adding extension container value");
ExtensionType extension = new ExtensionType(prismContext);
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(FocusType.F_EXTENSION).add(extension).asObjectDelta(user1Oid);
addExtensionValue(extension, "string", "string-value");
addExtensionValue(extension, "int-mv", 1, 2);
addExtensionValue(extension, "decimal", new BigDecimal("1E300"));
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 user = repositoryService.getObject(UserType.class, user1Oid, null, result).asObjectable();
assertThat(user.getVersion()).isEqualTo(String.valueOf(originalRow.version + 1));
ExtensionType extensionContainer = user.getExtension();
assertThat(extensionContainer).isNotNull().matches(m -> !m.asPrismContainerValue().isEmpty());
and("ext column is populated");
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(row.version).isEqualTo(originalRow.version + 1);
assertThat(row.ext).isNotNull();
assertThat(Jsonb.toMap(row.ext)).containsExactlyInAnyOrderEntriesOf(Map.of(extensionKey(extensionContainer, "string"), "string-value", extensionKey(extensionContainer, "int-mv"), List.of(1, 2), // retrieved number is converted to BigInteger, as it has no decimal places
extensionKey(extensionContainer, "decimal"), new BigDecimal("1E300").toBigInteger()));
}
use of com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser in project midpoint by Evolveum.
the class SqaleRepoModifyObjectTest method test300AddedAssignmentStoresItAndGeneratesMissingId.
// endregion
// region multi-value containers (e.g. assignments)
@Test
public void test300AddedAssignmentStoresItAndGeneratesMissingId() throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
OperationResult result = createOperationResult();
MUser originalRow = selectObjectByOid(QUser.class, user1Oid);
given("delta replacing assignments for user 1 with a single one");
UUID roleOid = UUID.randomUUID();
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).replace(new AssignmentType(prismContext).targetRef(roleOid.toString(), // default relation
RoleType.COMPLEX_TYPE)).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).isNotNull();
// next free CID was assigned
assertThat(assignments.get(0).getId()).isEqualTo(originalRow.containerIdSeq);
and("assignment row is created");
MUser row = selectObjectByOid(QUser.class, user1Oid);
assertThat(row.version).isEqualTo(originalRow.version + 1);
QAssignment<?> a = QAssignmentMapping.getAssignmentMapping().defaultAlias();
MAssignment aRow = selectOne(a, a.ownerOid.eq(UUID.fromString(user1Oid)));
assertThat(aRow.cid).isEqualTo(originalRow.containerIdSeq);
assertThat(aRow.containerType).isEqualTo(MContainerType.ASSIGNMENT);
assertThat(aRow.targetRefTargetOid).isEqualTo(roleOid);
assertThat(aRow.targetRefTargetType).isEqualTo(MObjectType.ROLE);
assertCachedUri(aRow.targetRefRelationId, relationRegistry.getDefaultRelation());
}
Aggregations