@@ -23,6 +23,7 @@ public class DataPlaneTokenSourceTest {
2323 private static final String TEST_TOKEN_TYPE = "Bearer" ;
2424 private static final String TEST_REFRESH_TOKEN = "refresh-token" ;
2525 private static final int TEST_EXPIRES_IN = 3600 ;
26+ private static final String TEST_HOST = "https://test.databricks.com" ;
2627
2728 private static Stream <Arguments > provideDataPlaneTokenScenarios () throws Exception {
2829 // Mock DatabricksOAuthTokenSource for control plane token
@@ -31,7 +32,6 @@ private static Stream<Arguments> provideDataPlaneTokenScenarios() throws Excepti
3132 DatabricksOAuthTokenSource mockCpTokenSource = mock (DatabricksOAuthTokenSource .class );
3233 when (mockCpTokenSource .getToken ()).thenReturn (cpToken );
3334
34- // --- Mock HttpClient for different scenarios ---
3535 // Success JSON for endpoint1/auth1
3636 String successJson1 =
3737 "{"
@@ -56,7 +56,6 @@ private static Stream<Arguments> provideDataPlaneTokenScenarios() throws Excepti
5656 when (mockSuccessClient2 .execute (any ()))
5757 .thenReturn (new Response (successJson2 , 200 , "OK" , new URL (TEST_ENDPOINT_2 )));
5858
59- // Error response JSON
6059 String errorJson =
6160 "{" + "\" error\" :\" invalid_request\" ," + "\" error_description\" :\" Bad request\" " + "}" ;
6261 HttpClient mockErrorClient = mock (HttpClient .class );
@@ -67,12 +66,6 @@ private static Stream<Arguments> provideDataPlaneTokenScenarios() throws Excepti
6766 HttpClient mockIOExceptionClient = mock (HttpClient .class );
6867 when (mockIOExceptionClient .execute (any ())).thenThrow (new IOException ("Network error" ));
6968
70- // For null cpTokenSource
71- DatabricksOAuthTokenSource nullCpTokenSource = null ;
72-
73- // For null httpClient
74- HttpClient nullHttpClient = null ;
75-
7669 // For null/empty endpoint or authDetails
7770 return Stream .of (
7871 Arguments .of (
@@ -81,6 +74,7 @@ private static Stream<Arguments> provideDataPlaneTokenScenarios() throws Excepti
8174 TEST_AUTH_DETAILS_1 ,
8275 mockSuccessClient1 ,
8376 mockCpTokenSource ,
77+ TEST_HOST ,
8478 new Token (
8579 "dp-access-token1" ,
8680 TEST_TOKEN_TYPE ,
@@ -94,6 +88,7 @@ private static Stream<Arguments> provideDataPlaneTokenScenarios() throws Excepti
9488 TEST_AUTH_DETAILS_2 ,
9589 mockSuccessClient2 ,
9690 mockCpTokenSource ,
91+ TEST_HOST ,
9792 new Token (
9893 "dp-access-token2" ,
9994 TEST_TOKEN_TYPE ,
@@ -106,6 +101,7 @@ private static Stream<Arguments> provideDataPlaneTokenScenarios() throws Excepti
106101 TEST_AUTH_DETAILS_1 ,
107102 mockErrorClient ,
108103 mockCpTokenSource ,
104+ TEST_HOST ,
109105 null ,
110106 com .databricks .sdk .core .DatabricksException .class ),
111107 Arguments .of (
@@ -114,22 +110,25 @@ private static Stream<Arguments> provideDataPlaneTokenScenarios() throws Excepti
114110 TEST_AUTH_DETAILS_1 ,
115111 mockIOExceptionClient ,
116112 mockCpTokenSource ,
113+ TEST_HOST ,
117114 null ,
118115 com .databricks .sdk .core .DatabricksException .class ),
119116 Arguments .of (
120117 "Null cpTokenSource" ,
121118 TEST_ENDPOINT_1 ,
122119 TEST_AUTH_DETAILS_1 ,
123120 mockSuccessClient1 ,
124- nullCpTokenSource ,
121+ null ,
122+ TEST_HOST ,
125123 null ,
126124 NullPointerException .class ),
127125 Arguments .of (
128126 "Null httpClient" ,
129127 TEST_ENDPOINT_1 ,
130128 TEST_AUTH_DETAILS_1 ,
131- nullHttpClient ,
129+ null ,
132130 mockCpTokenSource ,
131+ TEST_HOST ,
133132 null ,
134133 NullPointerException .class ),
135134 Arguments .of (
@@ -138,6 +137,7 @@ private static Stream<Arguments> provideDataPlaneTokenScenarios() throws Excepti
138137 TEST_AUTH_DETAILS_1 ,
139138 mockSuccessClient1 ,
140139 mockCpTokenSource ,
140+ TEST_HOST ,
141141 null ,
142142 NullPointerException .class ),
143143 Arguments .of (
@@ -146,8 +146,27 @@ private static Stream<Arguments> provideDataPlaneTokenScenarios() throws Excepti
146146 null ,
147147 mockSuccessClient1 ,
148148 mockCpTokenSource ,
149+ TEST_HOST ,
150+ null ,
151+ NullPointerException .class ),
152+ Arguments .of (
153+ "Null host" ,
154+ TEST_ENDPOINT_1 ,
155+ TEST_AUTH_DETAILS_1 ,
156+ mockSuccessClient1 ,
157+ mockCpTokenSource ,
158+ null ,
159+ null ,
160+ NullPointerException .class ),
161+ Arguments .of (
162+ "Empty host" ,
163+ TEST_ENDPOINT_1 ,
164+ TEST_AUTH_DETAILS_1 ,
165+ mockSuccessClient1 ,
166+ mockCpTokenSource ,
167+ "" ,
149168 null ,
150- NullPointerException .class ));
169+ IllegalArgumentException .class ));
151170 }
152171
153172 @ ParameterizedTest (name = "{0}" )
@@ -158,17 +177,18 @@ void testDataPlaneTokenSource(
158177 String authDetails ,
159178 HttpClient httpClient ,
160179 DatabricksOAuthTokenSource cpTokenSource ,
180+ String host ,
161181 Token expectedToken ,
162182 Class <? extends Exception > expectedException ) {
163183 if (expectedException != null ) {
164184 assertThrows (
165185 expectedException ,
166186 () -> {
167- DataPlaneTokenSource source = new DataPlaneTokenSource (httpClient , cpTokenSource );
187+ DataPlaneTokenSource source = new DataPlaneTokenSource (httpClient , cpTokenSource , host );
168188 source .getToken (endpoint , authDetails );
169189 });
170190 } else {
171- DataPlaneTokenSource source = new DataPlaneTokenSource (httpClient , cpTokenSource );
191+ DataPlaneTokenSource source = new DataPlaneTokenSource (httpClient , cpTokenSource , host );
172192 Token token = source .getToken (endpoint , authDetails );
173193 assertNotNull (token );
174194 assertEquals (expectedToken .getAccessToken (), token .getAccessToken ());
0 commit comments