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.SecurityQuestionTO;
30 import org.apache.syncope.common.lib.types.ClientExceptionType;
31 import org.apache.syncope.common.rest.api.service.SecurityQuestionService;
32 import org.apache.syncope.fit.AbstractITCase;
33 import org.junit.jupiter.api.Test;
34
35 public class SecurityQuestionITCase extends AbstractITCase {
36
37 @Test
38 public void read() {
39 SecurityQuestionTO securityQuestionTO = SECURITY_QUESTION_SERVICE.read(
40 "887028ea-66fc-41e7-b397-620d7ea6dfbb");
41 assertNotNull(securityQuestionTO);
42 }
43
44 @Test
45 public void list() {
46 List<SecurityQuestionTO> securityQuestionTOs = SECURITY_QUESTION_SERVICE.list();
47 assertNotNull(securityQuestionTOs);
48 assertFalse(securityQuestionTOs.isEmpty());
49 for (SecurityQuestionTO instance : securityQuestionTOs) {
50 assertNotNull(instance);
51 }
52 }
53
54 @Test
55 public void create() {
56 SecurityQuestionTO securityQuestionTO = new SecurityQuestionTO();
57 securityQuestionTO.setContent("What is your favorite pet's name?");
58
59 Response response = SECURITY_QUESTION_SERVICE.create(securityQuestionTO);
60 SecurityQuestionTO actual = getObject(response.getLocation(), SecurityQuestionService.class,
61 SecurityQuestionTO.class);
62
63 assertNotNull(actual);
64 assertNotNull(actual.getKey());
65 securityQuestionTO.setKey(actual.getKey());
66 assertEquals(actual, securityQuestionTO);
67 }
68
69 @Test
70 public void update() {
71 SecurityQuestionTO securityQuestionTO = SECURITY_QUESTION_SERVICE.read(
72 "887028ea-66fc-41e7-b397-620d7ea6dfbb");
73 securityQuestionTO.setContent("What is your favorite color?");
74
75 SECURITY_QUESTION_SERVICE.update(securityQuestionTO);
76 SecurityQuestionTO actual = SECURITY_QUESTION_SERVICE.read(securityQuestionTO.getKey());
77 assertNotNull(actual);
78 assertEquals(actual, securityQuestionTO);
79 }
80
81 @Test
82 public void delete() {
83 SecurityQuestionTO securityQuestion = new SecurityQuestionTO();
84 securityQuestion.setContent("What is your first pet's name?");
85
86 Response response = SECURITY_QUESTION_SERVICE.create(securityQuestion);
87 securityQuestion = getObject(response.getLocation(), SecurityQuestionService.class, SecurityQuestionTO.class);
88
89 SECURITY_QUESTION_SERVICE.delete(securityQuestion.getKey());
90
91 try {
92 SECURITY_QUESTION_SERVICE.read(securityQuestion.getKey());
93 fail("This should not happen");
94 } catch (SyncopeClientException e) {
95 assertEquals(ClientExceptionType.NotFound, e.getType());
96 }
97 }
98
99 }