-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathAccountsApiTest.java
188 lines (169 loc) · 7.05 KB
/
AccountsApiTest.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package com.mastercard.openbanking.client.api;
import com.mastercard.openbanking.client.ApiException;
import com.mastercard.openbanking.client.model.CustomerAccounts;
import com.mastercard.openbanking.client.test.BaseTest;
import com.mastercard.openbanking.client.test.utils.AccountUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class AccountsApiTest extends BaseTest {
private final static AccountsApi api = new AccountsApi(apiClient);
private static String existingInstitutionLoginId;
private static Long existingInstitutionId;
private static String existingAccountId;
@BeforeAll
protected static void beforeAll() {
try {
// Load existing IDs to be used in the subsequent tests
var existingAccount = AccountUtils.getCustomerAccounts(api, CUSTOMER_ID).get(0);
existingInstitutionLoginId = existingAccount.getInstitutionLoginId().toString();
existingAccountId = existingAccount.getId();
existingInstitutionId = Long.parseLong(existingAccount.getInstitutionId());
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
void getCustomerAccountsByInstitutionLoginTest() {
try {
var accounts = api.getCustomerAccountsByInstitutionLogin(CUSTOMER_ID, existingInstitutionLoginId);
assertTrue(accounts.getAccounts().size() > 0);
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
void refreshCustomerAccountsByInstitutionLoginTest() {
try {
CustomerAccounts accounts = api.refreshCustomerAccountsByInstitutionLogin(CUSTOMER_ID, existingInstitutionLoginId);
assertTrue(accounts.getAccounts().size() > 0);
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
void getCustomerAccountTest() {
try {
var account = api.getCustomerAccount(CUSTOMER_ID, existingAccountId);
assertEquals(existingAccountId, account.getId());
assertEquals(CUSTOMER_ID, account.getCustomerId());
assertNotNull(account);
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
void getCustomerAccountsTest() {
try {
var customerAccounts = api.getCustomerAccounts(CUSTOMER_ID, null, null);
var accounts = customerAccounts.getAccounts();
assertTrue(accounts.size() > 0);
var firstAccount = accounts.get(0);
assertEquals(CUSTOMER_ID, firstAccount.getCustomerId());
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
void getCustomerAccountsByInstitutionTest() {
try {
var accounts = api.getCustomerAccountsByInstitution(CUSTOMER_ID, existingInstitutionId);
var firstAccount = accounts.getAccounts().get(0);
assertEquals(existingInstitutionId, Long.parseLong(firstAccount.getInstitutionId()));
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
void refreshCustomerAccountsTest() {
try {
var response = api.refreshCustomerAccounts(CUSTOMER_ID);
assertNotNull(response.getAccounts());
assertTrue(response.getAccounts().size() > 0);
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
void getCustomerAccountsByInstitutionTest_UnknownInstitution() {
try {
api.getCustomerAccountsByInstitution(CUSTOMER_ID, 1234567L);
Assertions.fail();
} catch (ApiException e) {
// HTTP 404
// {"code":38006,"message":"Customer does not have any accounts associated with institutionId = (1234567)"}
logApiException(e);
assertErrorCodeEquals(38006, e);
assertErrorMessageEquals("Customer does not have any accounts associated with institutionId = (1234567)", e);
}
}
@Test
void deleteCustomerAccountsByInstitutionLoginTest_UnknownCustomerId() {
try {
api.deleteCustomerAccountsByInstitutionLogin("1234", "1234");
Assertions.fail();
} catch (ApiException e) {
// {"code":38007,"message":"Customer does not have any accounts associated with institutionLoginId = (1234)"}
logApiException(e);
assertErrorCodeEquals(38007, e);
assertErrorMessageEquals("Customer does not have any accounts associated with institutionLoginId = (1234)", e);
}
}
@Test
void deleteCustomerAccountsByInstitutionLoginTest_UnknownInstitutionLoginId() {
try {
api.deleteCustomerAccountsByInstitutionLogin(CUSTOMER_ID, "1234");
Assertions.fail();
} catch (ApiException e) {
// {"code":38007,"message":"Customer does not have any accounts associated with institutionLoginId = (1234)"}
logApiException(e);
assertErrorCodeEquals(38007, e);
assertErrorMessageEquals("Customer does not have any accounts associated with institutionLoginId = (1234)", e);
}
}
@Test
void deleteCustomerAccountTest_UnknownCustomerId() {
try {
api.deleteCustomerAccount("1234", "1234");
Assertions.fail();
} catch (ApiException e) {
// {"code":38003,"message":"customer does not have given account (customerId = 1234, accountId = [1234])"}
logApiException(e);
assertErrorCodeEquals(38003, e);
assertErrorMessageEquals("customer does not have given account (customerId = 1234, accountId = [1234])", e);
}
}
@Test
void deleteCustomerAccountTest_UnknownAccountId() {
try {
api.deleteCustomerAccount(CUSTOMER_ID, "1234");
Assertions.fail();
} catch (ApiException e) {
// {"code":38003,"message":"customer does not have given account (customerId = 5026247981, accountId = [1234])"}
logApiException(e);
assertErrorCodeEquals(38003, e);
assertErrorMessageEquals("customer does not have given account (customerId = " + CUSTOMER_ID + ", accountId = [1234])", e);
}
}
@Test
void refreshCustomerAccountsByInstitutionLoginV2Test() {
String institutionLoginId = existingInstitutionLoginId;
try {
api.refreshCustomerAccountsByInstitutionLoginV2(CUSTOMER_ID, institutionLoginId);
} catch (ApiException e) {
// {"code":38007,"message":"Customer does not have any accounts associated with institutionLoginId = (1234)"}
logApiException(e);
assertErrorCodeEquals(38007, e);
assertErrorMessageEquals("Customer does not have any accounts associated with institutionLoginId = (1234)", e);
}
}
@Test
void refreshCustomerAccountsV2Test() {
try {
api.refreshCustomerAccountsV2(CUSTOMER_ID);
} catch (ApiException e) {
Assertions.fail(e);
}
}
}