-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGetIdentityTest.java
121 lines (95 loc) · 4.21 KB
/
GetIdentityTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package ai.pluggy.client.integration;
import static ai.pluggy.client.integration.helper.ItemHelper.createItem;
import static ai.pluggy.client.integration.helper.ItemHelper.getItemStatus;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import ai.pluggy.client.integration.util.Poller;
import ai.pluggy.client.request.ParametersMap;
import ai.pluggy.client.response.ErrorResponse;
import ai.pluggy.client.response.IdentityResponse;
import ai.pluggy.client.response.ItemResponse;
import ai.pluggy.client.response.ItemStatus;
import java.util.Objects;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import retrofit2.Response;
public class GetIdentityTest extends BaseApiIntegrationTest {
@SneakyThrows
@Test
void getIdentityByItemId_existingItemId_waitUntilCompleted_ok() {
// ensure item exists
Integer connectorId = 0;
ParametersMap validCredentials = ParametersMap.map("user", "user-ok")
.with("password", "password-ok");
ItemResponse item = createItem(client, connectorId, validCredentials);
assertNotNull(item);
String existingItemId = item.getId();
// wait until item completed (item status: "UPDATED")
Poller.pollRequestUntil(
() -> getItemStatus(client, item.getId()),
(ItemResponse itemResponse) -> Objects.equals(itemResponse.getStatus(), ItemStatus.UPDATED),
500, 30000);
// get identity by item id
Response<IdentityResponse> identityByItemIdResponse = client.service()
.getIdentityByItemId(existingItemId)
.execute();
// expect response to be OK (and not null)
assertEquals(200, identityByItemIdResponse.code());
IdentityResponse identityResponse = identityByItemIdResponse.body();
assertNotNull(identityResponse);
this.getItemsIdCreated().add(item.getId());
}
@SneakyThrows
@Test
void getIdentityByItemId_existingItemId_beforeCompleted_fails() {
// ensure item exists
Integer connectorId = 0;
ParametersMap validCredentials = ParametersMap.map("user", "user-ok")
.with("password", "password-ok");
ItemResponse item = createItem(client, connectorId, validCredentials);
assertNotNull(item);
String existingItemId = item.getId();
// get identity by item id
Response<IdentityResponse> identityByItemIdResponse = client.service()
.getIdentityByItemId(existingItemId)
.execute();
// expect response to be 404 not found
assertEquals(404, identityByItemIdResponse.code());
ErrorResponse errorResponse = client.parseError(identityByItemIdResponse);
assertEquals(404, errorResponse.getCode());
this.getItemsIdCreated().add(item.getId());
}
@SneakyThrows
@Test
void getIdentityById_existingIdentityOfExistingCompletedItemId_ok() {
// ensure item exists
Integer connectorId = 0;
ParametersMap validCredentials = ParametersMap.map("user", "user-ok")
.with("password", "password-ok");
ItemResponse item = createItem(client, connectorId, validCredentials);
assertNotNull(item);
String existingItemId = item.getId();
// wait until item completed (item status: "UPDATED")
Poller.pollRequestUntil(
() -> getItemStatus(client, existingItemId),
(ItemResponse itemResponse) -> Objects.equals(itemResponse.getStatus(), ItemStatus.UPDATED),
500, 30000);
// ensure identity by item id exists
Response<IdentityResponse> identityByItemIdResponse = client.service()
.getIdentityByItemId(existingItemId)
.execute();
IdentityResponse identityResponse = identityByItemIdResponse.body();
String identityId = identityResponse.getId();
assertNotNull(identityId);
// get identity by id
Response<IdentityResponse> identityByIdResponse = client.service().getIdentityById(identityId)
.execute();
// expect response to be OK and to match originally requested identity
assertEquals(identityByIdResponse.code(), 200);
IdentityResponse identityById = identityByIdResponse.body();
assertNotNull(identityById);
assertEquals(identityById.getId(), identityId);
assertEquals(identityById.getFullName(), identityResponse.getFullName());
this.getItemsIdCreated().add(item.getId());
}
}