-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGetItemTest.java
More file actions
104 lines (82 loc) · 3.88 KB
/
GetItemTest.java
File metadata and controls
104 lines (82 loc) · 3.88 KB
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
package ai.pluggy.client.integration;
import static ai.pluggy.client.integration.helper.ItemHelper.ITEM_FINISH_STATUSES;
import static ai.pluggy.client.integration.helper.ItemHelper.NON_EXISTING_ITEM_ID;
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 static org.junit.jupiter.api.Assertions.assertTrue;
import ai.pluggy.client.integration.util.Poller;
import ai.pluggy.client.request.ParametersMap;
import ai.pluggy.client.response.ErrorResponse;
import ai.pluggy.client.response.ExecutionErrorCode;
import ai.pluggy.client.response.ItemResponse;
import ai.pluggy.client.response.ItemStatus;
import java.io.IOException;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import retrofit2.Response;
public class GetItemTest extends BaseApiIntegrationTest {
@Test
void getItem_existingItem_ok() throws IOException {
// ensure item exists
Integer connectorId = 0;
ItemResponse item = createItem(client, connectorId);
assertNotNull(item);
String createdItemId = item.getId();
// get item by id
ItemResponse itemResponse = client.service().getItem(createdItemId).execute().body();
// expect item response id to match requested
assertNotNull(itemResponse);
assertEquals(itemResponse.getId(), createdItemId);
this.getItemsIdCreated().add(item.getId());
}
@SneakyThrows
@Test
void getItem_validItemWithInvalidCredentials_finishesWithLoginError() throws IOException {
// precondition: ensure item with bad credentials params exists
Integer connectorId = 0;
ParametersMap validParametersBadCredentialsMap = ParametersMap
.map("user", "_bad_user_")
.with("password", "_bad_password_");
ItemResponse itemWithBadCredentials = createItem(client, connectorId,
validParametersBadCredentialsMap);
assertNotNull(itemWithBadCredentials);
// wait for item execution to finish.
Poller.pollRequestUntil(
() -> getItemStatus(client, itemWithBadCredentials.getId()),
(ItemResponse itemStatusResponse) -> ITEM_FINISH_STATUSES
.indexOf(itemStatusResponse.getStatus().getValue()) > 0,
500, 35000);
// expect item to be finished with login error status & code
ItemStatus expectedItemStatus = ItemStatus.LOGIN_ERROR;
ExecutionErrorCode expectedLoginErrorCode = ExecutionErrorCode.INVALID_CREDENTIALS;
Response<ItemResponse> getItemFinishedResponse = client.service()
.getItem(itemWithBadCredentials.getId()).execute();
assertTrue(getItemFinishedResponse.isSuccessful());
ItemResponse itemFinishedResponse = getItemFinishedResponse.body();
assertNotNull(itemFinishedResponse);
assertEquals(itemFinishedResponse.getStatus(), expectedItemStatus);
assertNotNull(itemFinishedResponse.getError());
assertEquals(itemFinishedResponse.getError().getCode(), expectedLoginErrorCode);
this.getItemsIdCreated().add(itemWithBadCredentials.getId());
}
@Test
void getItem_nonExistingItem_errorResponse404() throws IOException {
Response<ItemResponse> getItemResponse = client.service().getItem(NON_EXISTING_ITEM_ID)
.execute();
ErrorResponse errorResponse = client.parseError(getItemResponse);
// expect error response with 404 error
assertNotNull(errorResponse);
assertEquals(errorResponse.getCode(), 404);
}
@Test
void getItem_invalidItemId_errorResponse400() throws IOException {
String invalidItemId = "_";
Response<ItemResponse> getItemResponse = client.service().getItem(invalidItemId).execute();
ErrorResponse errorResponse = client.parseError(getItemResponse);
// expect error response with 400 error
assertNotNull(errorResponse);
assertEquals(errorResponse.getCode(), 400);
}
}