forked from Mastercard/open-banking-us-openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsumersApiTest.java
124 lines (111 loc) · 3.93 KB
/
ConsumersApiTest.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
package com.mastercard.finicity.client.api;
import com.mastercard.finicity.client.ApiException;
import com.mastercard.finicity.client.model.ConsumerUpdate;
import com.mastercard.finicity.client.test.BaseTest;
import com.mastercard.finicity.client.test.utils.ConsumerUtils;
import com.mastercard.finicity.client.test.ModelFactory;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
class ConsumersApiTest extends BaseTest {
private final static ConsumersApi api = new ConsumersApi(apiClient);
private static String existingConsumerId;
@BeforeAll
protected static void beforeAll() {
try {
existingConsumerId = ConsumerUtils.getOrCreateDefaultConsumer(api, CUSTOMER_ID);
} catch (ApiException e) {
fail(e);
}
}
@Test
void createConsumerTest() {
try {
var customer = customersApi.addTestingCustomer(ModelFactory.newCustomer());
createdCustomerIds.add(customer.getId());
var consumer = api.createConsumer(customer.getId(), ModelFactory.newConsumer());
assertNotNull(consumer.getId());
assertNotNull(consumer.getCreatedDate());
assertEquals(customer.getId(), String.valueOf(consumer.getCustomerId()));
} catch (ApiException e) {
fail(e);
}
}
@Test
void createConsumerTest_AlreadyCreated() {
try {
api.createConsumer(CUSTOMER_ID, ModelFactory.newConsumer());
fail();
} catch (ApiException e) {
// {"code":11000,"message":"A consumer already exists for customer 5025024821"}
logApiException(e);
assertErrorCodeEquals(11000, e);
assertErrorMessageEquals("A consumer already exists for customer " + CUSTOMER_ID, e);
}
}
@Test
void getConsumerTest() {
try {
var consumer = api.getConsumer(existingConsumerId);
assertNotNull(consumer);
} catch (ApiException e) {
fail(e);
}
}
@Test
void getConsumerTest_NonExistingId() {
try {
api.getConsumer("1234");
fail();
} catch (ApiException e) {
// {"code":10100,"message":"Cannot find consumer with id 1234."}
logApiException(e);
assertErrorCodeEquals(10100, e);
assertErrorMessageEquals("Cannot find consumer with id 1234.", e);
}
}
@Test
void getConsumerForCustomerTest() {
try {
var consumer = api.getConsumerForCustomer(CUSTOMER_ID);
assertNotNull(consumer.getId());
} catch (ApiException e) {
fail(e);
}
}
@Test
void getConsumerForCustomerTest_NonExistingId() {
try {
api.getConsumerForCustomer("1234");
fail();
} catch (ApiException e) {
// {"code":14001,"message":"Resource not found."}
logApiException(e);
assertErrorCodeEquals(14001, e);
assertErrorMessageEquals("Resource not found.", e);
}
}
@Test
void modifyConsumerTest() {
try {
var request = new ConsumerUpdate().firstName("New first name");
api.modifyConsumer(existingConsumerId, request);
} catch (ApiException e) {
fail(e);
}
}
@Test
void modifyConsumerTest_NonExistingId() {
try {
var request = new ConsumerUpdate().firstName("New first name");
api.modifyConsumer("1234", request);
fail();
} catch (ApiException e) {
// {"code":10100,"message":"Cannot find consumer with id 1234."}
logApiException(e);
assertErrorCodeEquals(10100, e);
assertErrorMessageEquals("Cannot find consumer with id 1234.", e);
}
}
}