-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathThirdPartyAccessApiTest.java
97 lines (83 loc) · 3.53 KB
/
ThirdPartyAccessApiTest.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
package com.mastercard.openbanking.client.api;
import com.mastercard.openbanking.client.ApiException;
import com.mastercard.openbanking.client.model.ThirdPartyAccessKeyReceiptData;
import com.mastercard.openbanking.client.model.ThirdPartyAccessReceipt;
import com.mastercard.openbanking.client.test.BaseTest;
import com.mastercard.openbanking.client.test.ModelFactory;
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.*;
public class ThirdPartyAccessApiTest extends BaseTest {
private static final ThirdPartyAccessApi api = new ThirdPartyAccessApi(apiClient);
private static final AccountsApi accountApi = new AccountsApi(apiClient);
private static String existingAccountId;
@BeforeAll
protected static void beforeAll() {
try {
// Load existing IDs to be used in the subsequent tests
var existingAccount = AccountUtils.getCustomerAccounts(accountApi, CUSTOMER_ID).get(0);
existingAccountId = existingAccount.getId();
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
public void generateThirdPartyAccessKeyTest() {
try {
var receiptData = generateThirdPartyAccessKey();
var data = receiptData.getData();
assertNotNull(data);
assertTrue(data.size() > 0);
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
public void revokeThirdPartyAccessKeyTest() {
try {
var receiptData = generateThirdPartyAccessKey();
var consentReceiptId = extractReceiptId(receiptData);
api.revokeThirdPartyAccessKey(consentReceiptId);
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
public void updateThirdPartyAccessKeyTest() {
try {
// GIVEN
var receiptData = generateThirdPartyAccessKey();
var consentReceiptId = extractReceiptId(receiptData);
// WHEN
var newData = ModelFactory.newThirdPartyAccessKeyData("single", existingAccountId, CUSTOMER_ID, PARTNER_ID);
var newReceiptData = api.updateThirdPartyAccessKey(consentReceiptId, newData);
// THEN
var receipt = extractReceipt(newReceiptData);
var products = receipt.getProducts();
assertNotNull(products);
assertTrue(products.size() > 0);
assertEquals("single", products.get(0).getAccessPeriod().getType());
} catch (ApiException e) {
Assertions.fail(e);
}
}
private static ThirdPartyAccessKeyReceiptData generateThirdPartyAccessKey() throws ApiException {
var data = ModelFactory.newThirdPartyAccessKeyData("timeframe", existingAccountId, CUSTOMER_ID, PARTNER_ID);
return api.generateThirdPartyAccessKey(data);
}
private static ThirdPartyAccessReceipt extractReceipt(ThirdPartyAccessKeyReceiptData receiptData) {
var data = receiptData.getData();
assertNotNull(data);
var receipt = data.get(0).getReceipt();
assertNotNull(receipt);
return receipt;
}
private static String extractReceiptId(ThirdPartyAccessKeyReceiptData receiptData) {
var receipt = extractReceipt(receiptData);
var consentReceiptId = receipt.getReceiptId();
assertNotNull(consentReceiptId);
return consentReceiptId;
}
}