|
26 | 26 | import static org.junit.jupiter.api.Assertions.fail; |
27 | 27 |
|
28 | 28 | import jakarta.ws.rs.core.Response; |
| 29 | +import java.util.List; |
29 | 30 | import java.util.Set; |
30 | 31 | import java.util.UUID; |
| 32 | +import java.util.function.Consumer; |
31 | 33 | import org.apache.syncope.client.lib.SyncopeClient; |
32 | 34 | import org.apache.syncope.common.lib.Attr; |
33 | 35 | import org.apache.syncope.common.lib.SyncopeClientException; |
34 | 36 | import org.apache.syncope.common.lib.SyncopeConstants; |
| 37 | +import org.apache.syncope.common.lib.request.AnyCR; |
35 | 38 | import org.apache.syncope.common.lib.request.AnyObjectCR; |
36 | 39 | import org.apache.syncope.common.lib.request.AnyObjectUR; |
| 40 | +import org.apache.syncope.common.lib.request.AnyUR; |
| 41 | +import org.apache.syncope.common.lib.request.GroupCR; |
| 42 | +import org.apache.syncope.common.lib.request.GroupUR; |
37 | 43 | import org.apache.syncope.common.lib.request.RelationshipUR; |
38 | 44 | import org.apache.syncope.common.lib.request.StringPatchItem; |
| 45 | +import org.apache.syncope.common.lib.request.UserCR; |
| 46 | +import org.apache.syncope.common.lib.request.UserUR; |
39 | 47 | import org.apache.syncope.common.lib.to.AnyObjectTO; |
| 48 | +import org.apache.syncope.common.lib.to.AnyTO; |
| 49 | +import org.apache.syncope.common.lib.to.AnyTypeClassTO; |
40 | 50 | import org.apache.syncope.common.lib.to.ConnObject; |
| 51 | +import org.apache.syncope.common.lib.to.GroupTO; |
41 | 52 | import org.apache.syncope.common.lib.to.PagedResult; |
| 53 | +import org.apache.syncope.common.lib.to.PlainSchemaTO; |
42 | 54 | import org.apache.syncope.common.lib.to.RelationshipTO; |
| 55 | +import org.apache.syncope.common.lib.to.UserTO; |
43 | 56 | import org.apache.syncope.common.lib.types.AnyTypeKind; |
| 57 | +import org.apache.syncope.common.lib.types.AttrSchemaType; |
44 | 58 | import org.apache.syncope.common.lib.types.ClientExceptionType; |
45 | 59 | import org.apache.syncope.common.lib.types.PatchOperation; |
46 | 60 | import org.apache.syncope.common.lib.types.SchemaType; |
47 | 61 | import org.apache.syncope.common.rest.api.beans.AnyQuery; |
| 62 | +import org.apache.syncope.common.rest.api.service.AnyTypeClassService; |
48 | 63 | import org.apache.syncope.fit.AbstractITCase; |
49 | 64 | import org.junit.jupiter.api.Assertions; |
50 | 65 | import org.junit.jupiter.api.Test; |
@@ -327,4 +342,101 @@ public void issueSYNCOPE1686() { |
327 | 342 | assertEquals(ClientExceptionType.InvalidRelationship, e.getType()); |
328 | 343 | assertTrue(e.getMessage().contains("Relationships shall be created or updated only from their left end")); |
329 | 344 | } |
| 345 | + |
| 346 | + public void issueSYNCOPE1957() { |
| 347 | + // prepare |
| 348 | + PlainSchemaTO schema1 = new PlainSchemaTO(); |
| 349 | + schema1.setKey("schema1" + getUUIDString()); |
| 350 | + schema1.setType(AttrSchemaType.Boolean); |
| 351 | + createSchema(SchemaType.PLAIN, schema1); |
| 352 | + |
| 353 | + PlainSchemaTO schema2 = new PlainSchemaTO(); |
| 354 | + schema2.setKey("schema2" + getUUIDString()); |
| 355 | + schema2.setType(AttrSchemaType.Boolean); |
| 356 | + createSchema(SchemaType.PLAIN, schema2); |
| 357 | + |
| 358 | + String class1Key = "class1" + getUUIDString(); |
| 359 | + AnyTypeClassTO class1 = new AnyTypeClassTO(); |
| 360 | + class1.setKey(class1Key); |
| 361 | + class1.getPlainSchemas().add(schema1.getKey()); |
| 362 | + class1.getPlainSchemas().add(schema2.getKey()); |
| 363 | + |
| 364 | + Response response = ANY_TYPE_CLASS_SERVICE.create(class1); |
| 365 | + assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode()); |
| 366 | + |
| 367 | + class1 = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class); |
| 368 | + |
| 369 | + // 1. create user, group and printer with auxClass class1 |
| 370 | + Consumer<AnyCR> setupAnyCR = anyCR -> { |
| 371 | + anyCR.getResources().clear(); |
| 372 | + anyCR.getAuxClasses().add(class1Key); |
| 373 | + anyCR.getPlainAttrs().add(attr(schema1.getKey(), "true")); |
| 374 | + anyCR.getPlainAttrs().add(attr(schema2.getKey(), "true")); |
| 375 | + }; |
| 376 | + Consumer<AnyTO> checkAnyTO = anyTO -> { |
| 377 | + assertTrue(anyTO.getPlainAttr(schema1.getKey()).isPresent()); |
| 378 | + assertTrue(anyTO.getPlainAttr(schema2.getKey()).isPresent()); |
| 379 | + }; |
| 380 | + |
| 381 | + UserCR userCR = UserITCase.getUniqueSample("syncope1957@apache.org"); |
| 382 | + setupAnyCR.accept(userCR); |
| 383 | + |
| 384 | + UserTO user = createUser(userCR).getEntity(); |
| 385 | + checkAnyTO.accept(user); |
| 386 | + |
| 387 | + GroupCR groupCR = GroupITCase.getSample("syncope1957"); |
| 388 | + setupAnyCR.accept(groupCR); |
| 389 | + |
| 390 | + GroupTO group = createGroup(groupCR).getEntity(); |
| 391 | + checkAnyTO.accept(group); |
| 392 | + |
| 393 | + AnyObjectCR printerCR = getSample("syncope1957"); |
| 394 | + setupAnyCR.accept(printerCR); |
| 395 | + |
| 396 | + AnyObjectTO printer = createAnyObject(printerCR).getEntity(); |
| 397 | + checkAnyTO.accept(printer); |
| 398 | + |
| 399 | + // 2. create new anytypeclass and move schema there |
| 400 | + class1.getPlainSchemas().remove(schema2.getKey()); |
| 401 | + ANY_TYPE_CLASS_SERVICE.update(class1); |
| 402 | + |
| 403 | + class1 = ANY_TYPE_CLASS_SERVICE.read(class1.getKey()); |
| 404 | + assertEquals(List.of(schema1.getKey()), class1.getPlainSchemas()); |
| 405 | + |
| 406 | + String class2Key = "class2" + getUUIDString(); |
| 407 | + AnyTypeClassTO class2 = new AnyTypeClassTO(); |
| 408 | + class2.setKey(class2Key); |
| 409 | + class2.getPlainSchemas().add(schema2.getKey()); |
| 410 | + |
| 411 | + response = ANY_TYPE_CLASS_SERVICE.create(class2); |
| 412 | + assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode()); |
| 413 | + |
| 414 | + class2 = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class); |
| 415 | + assertEquals(List.of(schema2.getKey()), class2.getPlainSchemas()); |
| 416 | + |
| 417 | + // 3. update user, group and printer by adding auxClass class2 |
| 418 | + Consumer<AnyUR> setupAnyUR = anyUR -> anyUR.getAuxClasses(). |
| 419 | + add(new StringPatchItem.Builder().value(class2Key).build()); |
| 420 | + |
| 421 | + UserUR userUR = new UserUR(); |
| 422 | + userUR.setKey(user.getKey()); |
| 423 | + setupAnyUR.accept(userUR); |
| 424 | + |
| 425 | + user = updateUser(userUR).getEntity(); |
| 426 | + checkAnyTO.accept(user); |
| 427 | + |
| 428 | + GroupUR groupUR = new GroupUR(); |
| 429 | + groupUR.setKey(group.getKey()); |
| 430 | + setupAnyUR.accept(groupUR); |
| 431 | + |
| 432 | + group = updateGroup(groupUR).getEntity(); |
| 433 | + checkAnyTO.accept(group); |
| 434 | + |
| 435 | + AnyObjectUR printerUR = new AnyObjectUR(); |
| 436 | + printerUR.setKey(printer.getKey()); |
| 437 | + setupAnyUR.accept(printerUR); |
| 438 | + |
| 439 | + printer = updateAnyObject(printerUR).getEntity(); |
| 440 | + checkAnyTO.accept(printer); |
| 441 | + } |
330 | 442 | } |
0 commit comments