1
1
package com .adyen ;
2
2
3
- import com .adyen .enums .Environment ;
4
- import com .adyen .enums .Region ;
5
- import com .adyen .model .RequestOptions ;
3
+ import java .util .HashMap ;
4
+ import java .util .stream .Stream ;
5
+
6
+ import javax .net .ssl .SSLContext ;
7
+
6
8
import org .junit .Assert ;
7
9
import org .junit .Test ;
8
10
import org .mockito .Mock ;
11
+ import org .junit .jupiter .params .ParameterizedTest ;
12
+ import org .junit .jupiter .params .provider .Arguments ;
13
+ import org .junit .jupiter .params .provider .MethodSource ;
9
14
10
- import javax .net .ssl .SSLContext ;
11
- import java .util .HashMap ;
15
+ import com .adyen .enums .Environment ;
16
+ import com .adyen .enums .Region ;
17
+ import com .adyen .model .RequestOptions ;
12
18
13
19
public class ClientTest {
14
20
@@ -18,16 +24,16 @@ public class ClientTest {
18
24
@ Mock
19
25
private String apiKey ;
20
26
27
+
21
28
@ Test
22
29
public void testConfigTestClient () {
23
30
Config config = new Config ();
24
31
config .setEnvironment (Environment .TEST );
25
32
config .setApiKey (apiKey );
26
33
Client client = new Client (config );
27
-
28
34
Assert .assertEquals (Environment .TEST , client .getConfig ().getEnvironment ());
29
35
}
30
-
36
+
31
37
@ Test
32
38
public void testConfigLiveClient () {
33
39
Config config = new Config ();
@@ -38,6 +44,56 @@ public void testConfigLiveClient() {
38
44
Assert .assertEquals (Environment .LIVE , client .getConfig ().getEnvironment ());
39
45
}
40
46
47
+ private static Stream <Arguments > provideCloudTestEndpointTestCases () {
48
+ return Stream .of (
49
+ Arguments .of (null , Environment .TEST , "https://terminal-api-test.adyen.com" ),
50
+ Arguments .of (Region .EU , Environment .TEST , "https://terminal-api-test.adyen.com" ),
51
+ Arguments .of (Region .AU , Environment .TEST , "https://terminal-api-test.adyen.com" ),
52
+ Arguments .of (Region .US , Environment .TEST , "https://terminal-api-test.adyen.com" ),
53
+ Arguments .of (Region .APSE , Environment .TEST , "https://terminal-api-test.adyen.com" )
54
+ );
55
+ }
56
+
57
+ @ ParameterizedTest
58
+ @ MethodSource ("provideCloudTestEndpointTestCases" )
59
+ public void testGetCloudEndpointForTestEnvironment (Region region , Environment environment , String expectedEndpoint ) {
60
+ Config testConfig = new Config ();
61
+ testConfig .setEnvironment (Environment .TEST );
62
+ testConfig .setTerminalApiRegion (region );
63
+ Client testClient = new Client (testConfig );
64
+ Assert .assertEquals (expectedEndpoint , testConfig .getTerminalApiCloudEndpoint ());
65
+ }
66
+
67
+ private static Stream <Arguments > provideCloudLiveEndpointTestCases () {
68
+ return Stream .of (
69
+ Arguments .of (null , Environment .LIVE , "https://terminal-api-live.adyen.com" ),
70
+ Arguments .of (Region .EU , Environment .LIVE , "https://terminal-api-live.adyen.com" ),
71
+ Arguments .of (Region .AU , Environment .LIVE , "https://terminal-api-live-au.adyen.com" ),
72
+ Arguments .of (Region .US , Environment .LIVE , "https://terminal-api-live-us.adyen.com" ),
73
+ Arguments .of (Region .APSE , Environment .LIVE , "https://terminal-api-live-apse.adyen.com" )
74
+ );
75
+ }
76
+
77
+ @ ParameterizedTest
78
+ @ MethodSource ("provideCloudLiveEndpointTestCases" )
79
+ public void testGetCloudEndpointForLiveEnvironment (Region region , Environment environment , String expectedEndpoint ) {
80
+ Config liveConfig = new Config ();
81
+ liveConfig .setEnvironment (Environment .LIVE );
82
+ liveConfig .setTerminalApiRegion (region );
83
+ Client liveClient = new Client (liveConfig );
84
+ Assert .assertEquals (expectedEndpoint , liveConfig .getTerminalApiCloudEndpoint ());
85
+ }
86
+
87
+ @ Test
88
+ public void testUnmappedIndiaRegionThrowsException () {
89
+ Config config = new Config ();
90
+ config .setEnvironment (Environment .LIVE );
91
+ config .setTerminalApiRegion (Region .IN );
92
+
93
+ Assert .assertThrows (IllegalArgumentException .class ,
94
+ () -> new Client (config ));
95
+ }
96
+
41
97
@ Test
42
98
public void testClientCertificateAuth () {
43
99
Client client = new Client (clientCertificateAuthSSLContext , apiKey );
@@ -54,8 +110,4 @@ public void testRequestOptionsBuilderPattern() {
54
110
.additionalServiceHeaders (map );
55
111
Assert .assertEquals (requestOptions .getAdditionalServiceHeaders (), map );
56
112
}
57
-
58
- private void assertCommonEndpoints (Config config ) {
59
- Assert .assertEquals (Client .TERMINAL_API_ENDPOINT_LIVE , config .getTerminalApiCloudEndpoint ());
60
- }
61
- }
113
+ }
0 commit comments