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
+ }
0 commit comments