1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.fit.core;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertFalse;
23 import static org.junit.jupiter.api.Assertions.assertNotNull;
24 import static org.junit.jupiter.api.Assertions.fail;
25
26 import java.util.List;
27 import javax.ws.rs.core.Response;
28 import org.apache.syncope.common.lib.SyncopeClientException;
29 import org.apache.syncope.common.lib.to.RelationshipTypeTO;
30 import org.apache.syncope.common.lib.types.ClientExceptionType;
31 import org.apache.syncope.common.rest.api.service.RelationshipTypeService;
32 import org.apache.syncope.fit.AbstractITCase;
33 import org.junit.jupiter.api.Test;
34
35 public class RelationshipTypeITCase extends AbstractITCase {
36
37 @Test
38 public void read() {
39 RelationshipTypeTO otherType = RELATIONSHIP_TYPE_SERVICE.read("inclusion");
40 assertNotNull(otherType);
41 assertEquals("inclusion", otherType.getKey());
42 }
43
44 @Test
45 public void list() {
46 List<RelationshipTypeTO> list = RELATIONSHIP_TYPE_SERVICE.list();
47 assertFalse(list.isEmpty());
48 }
49
50 @Test
51 public void crud() {
52 RelationshipTypeTO newType = new RelationshipTypeTO();
53 newType.setKey("new type");
54 newType.setDescription("description");
55
56 Response response = RELATIONSHIP_TYPE_SERVICE.create(newType);
57 assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
58
59 newType = getObject(response.getLocation(), RelationshipTypeService.class, RelationshipTypeTO.class);
60 assertNotNull(newType);
61 assertEquals("description", newType.getDescription());
62
63 newType.setDescription("new description");
64 RELATIONSHIP_TYPE_SERVICE.update(newType);
65
66 newType = RELATIONSHIP_TYPE_SERVICE.read(newType.getKey());
67 assertNotNull(newType);
68 assertEquals("new description", newType.getDescription());
69
70 RELATIONSHIP_TYPE_SERVICE.delete(newType.getKey());
71
72 try {
73 RELATIONSHIP_TYPE_SERVICE.read(newType.getKey());
74 fail("This should not happen");
75 } catch (SyncopeClientException e) {
76 assertEquals(ClientExceptionType.NotFound, e.getType());
77 }
78 }
79
80 @Test
81 public void createInvalidName() {
82 RelationshipTypeTO newType = new RelationshipTypeTO();
83 newType.setKey("membership");
84 try {
85 RELATIONSHIP_TYPE_SERVICE.create(newType);
86 fail("This should not happen");
87 } catch (SyncopeClientException e) {
88 assertEquals(ClientExceptionType.InvalidRelationshipType, e.getType());
89 }
90 }
91 }