-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathCustomersApiTest.java
156 lines (141 loc) · 5.17 KB
/
CustomersApiTest.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
package com.mastercard.openbanking.client.api;
import com.mastercard.openbanking.client.ApiException;
import com.mastercard.openbanking.client.model.CustomerUpdate;
import com.mastercard.openbanking.client.model.NewCustomer;
import com.mastercard.openbanking.client.test.BaseTest;
import com.mastercard.openbanking.client.test.ModelFactory;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class CustomersApiTest extends BaseTest {
private final CustomersApi api = new CustomersApi(apiClient);
@Test
void addTestingCustomerTest() {
try {
var newCustomer = ModelFactory.newCustomer();
var customer = api.addTestingCustomer(newCustomer);
assertNotNull(customer.getId());
assertNotNull(customer.getCreatedDate());
assertEquals(newCustomer.getUsername(), customer.getUsername());
createdCustomerIds.add(customer.getId());
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
void addCustomerTest() {
try {
var username = "customer_" + RandomStringUtils.randomAlphabetic(10);
var emailAddress= username+"@test.com";
var newCustomer = new NewCustomer().username(username).email(emailAddress);
var customer = api.addCustomer(newCustomer);
assertNotNull(customer.getId());
assertNotNull(customer.getCreatedDate());
assertEquals(newCustomer.getUsername(), customer.getUsername());
createdCustomerIds.add(customer.getId());
} catch (ApiException e) {
// HTTP 401: Not available from the Test Drive
logApiException(e);
}
}
@Test
void getCustomerTest() {
try {
var customer = api.getCustomer(CUSTOMER_ID);
assertEquals(CUSTOMER_ID, customer.getId());
assertNotNull(customer.getUsername());
assertNotNull(customer.getCreatedDate());
assertNotNull(customer.getType());
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
void getCustomerTest_UnknownCustomerId() {
try {
api.getCustomer("1234");
Assertions.fail();
} catch (ApiException e) {
// {"code":14001,"message":"Customer not found."}
logApiException(e);
assertErrorCodeEquals(14001, e);
assertErrorMessageEquals("Customer not found.", e);
}
}
@Test
void getCustomerWithApplicationDataTest_NoAppRegistered() {
try {
var customer = api.getCustomerWithAppData(CUSTOMER_ID);
assertEquals(CUSTOMER_ID, customer.getId());
} catch (ApiException e) {
// {"code":50051,"message":"No registered partner applications found."}
logApiException(e);
assertErrorCodeEquals(50051, e);
assertErrorMessageEquals("No registered partner applications found.", e);
}
}
@Test
void getCustomersTest_NoFilter() {
try {
var customers = api.getCustomers(null, null, null, null, null);
assertTrue(customers.getCustomers().size() > 0);
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
void getCustomersTest_UnknownUsername() {
try {
var customers = api.getCustomers("1234", null, null, null, null);
assertEquals(0, customers.getCustomers().size());
assertEquals(0, customers.getDisplaying());
assertFalse(customers.getMoreAvailable());
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
void getCustomersTest_UsernameFilter() {
try {
var customer = api.getCustomer(CUSTOMER_ID);
var customers = api.getCustomers(customer.getUsername(), null, null, null, null);
assertTrue(customers.getCustomers().size() > 0);
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
void modifyCustomerTest() {
try {
var customerUpdate = new CustomerUpdate()
.firstName("John_" + ModelFactory.randomStr())
.lastName("Smith_" + ModelFactory.randomStr());
api.modifyCustomer(CUSTOMER_ID, customerUpdate);
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
void deleteCustomerTest() {
try {
var newCustomer = ModelFactory.newCustomer();
var customer = api.addTestingCustomer(newCustomer);
api.deleteCustomer(customer.getId());
} catch (ApiException e) {
Assertions.fail(e);
}
}
@Test
void deleteCustomerTest_UnknownCustomerId() {
try {
api.deleteCustomer("1234");
Assertions.fail();
} catch (ApiException e) {
// {"code":14001,"message":"Customer not found."}
logApiException(e);
assertErrorCodeEquals(14001, e);
assertErrorMessageEquals("Customer not found.", e);
}
}
}