Skip to content

Commit 138fc22

Browse files
authored
PaymentsApp API unit tests (#1509)
* Add PaymentsApp unit tests * Minor edit
1 parent e4f461b commit 138fc22

File tree

7 files changed

+173
-4
lines changed

7 files changed

+173
-4
lines changed

src/main/java/com/adyen/service/PosTerminalManagementApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* terminals, you must use Management API: see
3737
* https://docs.adyen.com/point-of-sale/automating-terminal-management/assign-terminals-api/
3838
*
39-
* @deprecated Use instead PaymentsApi and ModificationsApi in the com.adyen.service.payment package
39+
* @deprecated Use Management API instead
4040
*/
4141
@Deprecated(since = "v37.0.0", forRemoval = true)
4242
public class PosTerminalManagementApi extends Service {

src/test/java/com/adyen/BaseTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ protected Client createMockClientFromResponse(String response) {
9292
.thenReturn(response);
9393
when(adyenHttpClient.request(
9494
anyString(), any(), any(Config.class), anyBoolean(), isNull(), any(), any()))
95-
.thenReturn(response);
95+
.thenReturn(response);
96+
when(adyenHttpClient.request(
97+
anyString(), any(), any(Config.class), anyBoolean(), isNotNull(), any(), any()))
98+
.thenReturn(response);
9699

97100
} catch (IOException | HTTPClientException e) {
98101
e.printStackTrace();
@@ -309,8 +312,9 @@ protected Client createMockClientForErrors(int status, String fileName) {
309312
new HTTPClientException(status, "An error occured", new HashMap<>(), response);
310313
try {
311314
when(adyenHttpClient.request(
312-
anyString(), anyString(), any(Config.class), anyBoolean(), isNull(), any(), any()))
313-
.thenThrow(httpClientException);
315+
anyString(), any(), any(Config.class), anyBoolean(), isNull(), any(), any()))
316+
.thenThrow(httpClientException);
317+
314318
} catch (IOException | HTTPClientException e) {
315319
fail("Unexpected exception: " + e.getMessage());
316320
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package com.adyen;
2+
3+
import com.adyen.model.RequestOptions;
4+
import com.adyen.model.paymentsapp.BoardingTokenRequest;
5+
import com.adyen.model.paymentsapp.BoardingTokenResponse;
6+
import com.adyen.model.paymentsapp.PaymentsAppResponse;
7+
import com.adyen.service.exception.ApiException;
8+
import com.adyen.service.paymentsapp.PaymentsAppApi;
9+
import org.junit.Test;
10+
11+
import static org.junit.Assert.assertEquals;
12+
import static org.junit.Assert.assertNotNull;
13+
import static org.junit.Assert.assertTrue;
14+
import static org.junit.Assert.fail;
15+
16+
public class PaymentsAppTest extends BaseTest {
17+
18+
@Test
19+
public void testGeneratePaymentsAppBoardingTokenForMerchantSuccess() throws Exception {
20+
Client client = createMockClientFromFile("mocks/paymentsapp/boardingToken-success.json");
21+
PaymentsAppApi paymentsAppApi = new PaymentsAppApi(client);
22+
23+
BoardingTokenResponse response = paymentsAppApi.
24+
generatePaymentsAppBoardingTokenForMerchant("MerchantAccount123", new BoardingTokenRequest()
25+
.boardingRequestToken("mockedRequestToken"));
26+
27+
assertNotNull(response);
28+
assertEquals("eyJhYmMxMjMiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", response.getBoardingToken());
29+
assertEquals("mockedInstallationId", response.getInstallationId());
30+
}
31+
32+
@Test
33+
public void testGeneratePaymentsAppBoardingTokenForMerchantError() throws Exception {
34+
Client client = createMockClientForErrors(403, "mocks/paymentsapp/boardingToken-error-403.json");
35+
PaymentsAppApi paymentsAppApi = new PaymentsAppApi(client);
36+
37+
try {
38+
paymentsAppApi.
39+
generatePaymentsAppBoardingTokenForMerchant("MerchantAccount123", new BoardingTokenRequest()
40+
.boardingRequestToken("mockedRequestToken"));
41+
fail("ApiException expected");
42+
} catch (ApiException e) {
43+
assertEquals(403, e.getStatusCode());
44+
assertNotNull(e.getResponseBody());
45+
assertTrue(e.getResponseBody().contains("PA001"));
46+
}
47+
}
48+
49+
@Test
50+
public void testGeneratePaymentsAppBoardingTokenForStoreSuccess() throws Exception {
51+
Client client = createMockClientFromFile("mocks/paymentsapp/boardingToken-success.json");
52+
PaymentsAppApi paymentsAppApi = new PaymentsAppApi(client);
53+
54+
BoardingTokenResponse response = paymentsAppApi.
55+
generatePaymentsAppBoardingTokenForStore("MerchantAccount123", "StoreEU", new BoardingTokenRequest()
56+
.boardingRequestToken("mockedRequestToken"));
57+
58+
assertNotNull(response);
59+
assertEquals("eyJhYmMxMjMiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", response.getBoardingToken());
60+
assertEquals("mockedInstallationId", response.getInstallationId());
61+
62+
}
63+
64+
@Test
65+
public void testGeneratePaymentsAppBoardingTokenForStoreError() throws Exception {
66+
Client client = createMockClientForErrors(403, "mocks/paymentsapp/boardingToken-error-403.json");
67+
PaymentsAppApi paymentsAppApi = new PaymentsAppApi(client);
68+
69+
try {
70+
paymentsAppApi.
71+
generatePaymentsAppBoardingTokenForStore("MerchantAccount123", "StoreEU", new BoardingTokenRequest()
72+
.boardingRequestToken("mockedRequestToken"));
73+
fail("ApiException expected");
74+
} catch (ApiException e) {
75+
assertEquals(403, e.getStatusCode());
76+
assertNotNull(e.getResponseBody());
77+
assertTrue(e.getResponseBody().contains("PA001"));
78+
}
79+
}
80+
81+
@Test
82+
public void testListPaymentsAppForMerchantSuccess() throws Exception {
83+
Client client = createMockClientFromFile("mocks/paymentsapp/paymentsAppList-success.json");
84+
PaymentsAppApi paymentsAppApi = new PaymentsAppApi(client);
85+
86+
PaymentsAppResponse response = paymentsAppApi.listPaymentsAppForMerchant("MerchantAccount123");
87+
88+
assertNotNull(response);
89+
assertNotNull(response.getPaymentsApps());
90+
assertEquals(2, response.getPaymentsApps().size());
91+
}
92+
93+
@Test
94+
public void testListPaymentsAppForMerchantWithParamsSuccess() throws Exception {
95+
Client client = createMockClientFromFile("mocks/paymentsapp/paymentsAppList-success.json");
96+
PaymentsAppApi paymentsAppApi = new PaymentsAppApi(client);
97+
RequestOptions requestOptions = new RequestOptions();
98+
99+
PaymentsAppResponse response = paymentsAppApi.listPaymentsAppForMerchant("MerchantAccount123", "BOARDED",
100+
10, 0L, requestOptions);
101+
102+
assertNotNull(response);
103+
assertNotNull(response.getPaymentsApps());
104+
assertEquals(2, response.getPaymentsApps().size());
105+
}
106+
107+
@Test
108+
public void testListPaymentsAppForMerchantError() throws Exception {
109+
Client client = createMockClientForErrors(500, "mocks/paymentsapp/paymentsAppList-error-500.json");
110+
PaymentsAppApi paymentsAppApi = new PaymentsAppApi(client);
111+
112+
try {
113+
paymentsAppApi.listPaymentsAppForMerchant("MerchantAccount123");
114+
fail("ApiException expected");
115+
} catch (ApiException e) {
116+
assertEquals(500, e.getStatusCode());
117+
assertNotNull(e.getResponseBody());
118+
assertTrue(e.getResponseBody().contains("PA002"));
119+
}
120+
}
121+
122+
@Test
123+
public void testListPaymentsAppForStoreSuccess() throws Exception {
124+
Client client = createMockClientFromFile("mocks/paymentsapp/paymentsAppList-success.json");
125+
PaymentsAppApi paymentsAppApi = new PaymentsAppApi(client);
126+
127+
PaymentsAppResponse response = paymentsAppApi.listPaymentsAppForStore("MerchantAccount123", "StoreEU");
128+
129+
assertNotNull(response);
130+
assertNotNull(response.getPaymentsApps());
131+
assertEquals(2, response.getPaymentsApps().size());
132+
}
133+
134+
@Test
135+
public void testRevokePaymentsAppSuccess() throws Exception {
136+
Client client = createMockClientFromResponse("");
137+
PaymentsAppApi paymentsAppApi = new PaymentsAppApi(client);
138+
139+
// This is a void method, so we just check that no exception is thrown.
140+
paymentsAppApi.revokePaymentsApp("MerchantAccount123", "StoreEU");
141+
}
142+
143+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"status": 403,
3+
"errorCode": "PA001",
4+
"message": "Merchant not permitted for this action.",
5+
"errorType": "security"
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"boardingToken": "eyJhYmMxMjMiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
3+
"installationId": "mockedInstallationId"
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"status": 500,
3+
"errorCode": "PA002",
4+
"message": "An internal server error occurred.",
5+
"errorType": "api"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"paymentsApps": [
3+
{ "installationId": "app1", "merchantAccountCode": "merchantAccountCode", "status": "BOARDED" },
4+
{ "installationId": "app2", "merchantAccountCode": "merchantAccountCode", "status": "BOARDING" }
5+
]
6+
}

0 commit comments

Comments
 (0)