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.assertNotNull;
23 import static org.junit.jupiter.api.Assertions.fail;
24
25 import java.util.UUID;
26 import javax.ws.rs.core.Response;
27 import org.apache.syncope.common.lib.SyncopeClientException;
28 import org.apache.syncope.common.lib.to.ImplementationTO;
29 import org.apache.syncope.common.lib.to.PullTaskTO;
30 import org.apache.syncope.common.lib.types.ClientExceptionType;
31 import org.apache.syncope.common.lib.types.IdMImplementationType;
32 import org.apache.syncope.common.lib.types.ImplementationEngine;
33 import org.apache.syncope.common.lib.types.TaskType;
34 import org.apache.syncope.common.rest.api.RESTHeaders;
35 import org.apache.syncope.fit.AbstractITCase;
36 import org.apache.syncope.fit.core.reference.TestPullActions;
37 import org.junit.jupiter.api.Test;
38
39 public class ImplementationITCase extends AbstractITCase {
40
41 @Test
42 public void create() {
43 ImplementationTO implementationTO = new ImplementationTO();
44 implementationTO.setKey(UUID.randomUUID().toString());
45 implementationTO.setEngine(ImplementationEngine.JAVA);
46 implementationTO.setType(IdMImplementationType.PUSH_ACTIONS);
47 implementationTO.setBody(TestPullActions.class.getName());
48
49
50 try {
51 IMPLEMENTATION_SERVICE.create(implementationTO);
52 fail("This should not happen");
53 } catch (SyncopeClientException e) {
54 assertEquals(ClientExceptionType.InvalidImplementation, e.getType());
55 }
56 implementationTO.setType(IdMImplementationType.PULL_ACTIONS);
57
58 Response response = IMPLEMENTATION_SERVICE.create(implementationTO);
59 if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
60 Exception ex = CLIENT_FACTORY.getExceptionMapper().fromResponse(response);
61 if (ex != null) {
62 throw (RuntimeException) ex;
63 }
64 }
65
66 ImplementationTO actual = IMPLEMENTATION_SERVICE.read(
67 implementationTO.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
68 assertNotNull(actual);
69 assertEquals(actual, implementationTO);
70 }
71
72 @Test
73 public void delete() {
74 ImplementationTO implementationTO = new ImplementationTO();
75 implementationTO.setKey(UUID.randomUUID().toString());
76 implementationTO.setEngine(ImplementationEngine.JAVA);
77 implementationTO.setType(IdMImplementationType.PULL_ACTIONS);
78 implementationTO.setBody(TestPullActions.class.getName());
79
80 IMPLEMENTATION_SERVICE.create(implementationTO);
81
82 PullTaskTO pullTask = TASK_SERVICE.read(TaskType.PULL, AbstractTaskITCase.PULL_TASK_KEY, false);
83 assertNotNull(pullTask);
84
85 int before = pullTask.getActions().size();
86
87 pullTask.getActions().add(implementationTO.getKey());
88 TASK_SERVICE.update(TaskType.PULL, pullTask);
89
90 pullTask = TASK_SERVICE.read(TaskType.PULL, AbstractTaskITCase.PULL_TASK_KEY, false);
91 assertNotNull(pullTask);
92
93 int after = pullTask.getActions().size();
94 assertEquals(before + 1, after);
95
96
97 try {
98 IMPLEMENTATION_SERVICE.delete(implementationTO.getType(), implementationTO.getKey());
99 fail("Unexpected");
100 } catch (SyncopeClientException e) {
101 assertEquals(e.getType(), ClientExceptionType.InUse);
102 }
103
104 pullTask.getActions().remove(implementationTO.getKey());
105 TASK_SERVICE.update(TaskType.PULL, pullTask);
106
107 IMPLEMENTATION_SERVICE.delete(implementationTO.getType(), implementationTO.getKey());
108 }
109
110 }