11package com .adyen ;
22
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+
68import org .junit .Assert ;
79import org .junit .Test ;
810import 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 ;
914
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 ;
1218
1319public class ClientTest {
1420
@@ -18,16 +24,16 @@ public class ClientTest {
1824 @ Mock
1925 private String apiKey ;
2026
27+
2128 @ Test
2229 public void testConfigTestClient () {
2330 Config config = new Config ();
2431 config .setEnvironment (Environment .TEST );
2532 config .setApiKey (apiKey );
2633 Client client = new Client (config );
27-
2834 Assert .assertEquals (Environment .TEST , client .getConfig ().getEnvironment ());
2935 }
30-
36+
3137 @ Test
3238 public void testConfigLiveClient () {
3339 Config config = new Config ();
@@ -38,6 +44,56 @@ public void testConfigLiveClient() {
3844 Assert .assertEquals (Environment .LIVE , client .getConfig ().getEnvironment ());
3945 }
4046
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+
4197 @ Test
4298 public void testClientCertificateAuth () {
4399 Client client = new Client (clientCertificateAuthSSLContext , apiKey );
@@ -54,8 +110,4 @@ public void testRequestOptionsBuilderPattern() {
54110 .additionalServiceHeaders (map );
55111 Assert .assertEquals (requestOptions .getAdditionalServiceHeaders (), map );
56112 }
57-
58- private void assertCommonEndpoints (Config config ) {
59- Assert .assertEquals (Client .TERMINAL_API_ENDPOINT_LIVE , config .getTerminalApiCloudEndpoint ());
60- }
61- }
113+ }
0 commit comments