@@ -231,4 +231,71 @@ public void testNoHeaderInjectionForTraditionalWorkspace() {
231231 assertEquals ("Bearer test-token" , headers .get ("Authorization" ));
232232 assertNull (headers .get ("X-Databricks-Org-Id" ));
233233 }
234+
235+ // --- Resolved host type from metadata tests ---
236+
237+ @ Test
238+ public void testMetadataWorkspaceOverridesAccountLikeUrl () {
239+ DatabricksConfig config =
240+ new DatabricksConfig ()
241+ .setHost ("https://accounts.cloud.databricks.com" )
242+ .setResolvedHostType (HostType .WORKSPACE );
243+ assertEquals (HostType .WORKSPACE , config .getHostType ());
244+ }
245+
246+ @ Test
247+ public void testMetadataAccountOverridesWorkspaceLikeUrl () {
248+ DatabricksConfig config =
249+ new DatabricksConfig ()
250+ .setHost ("https://my-workspace.cloud.databricks.com" )
251+ .setResolvedHostType (HostType .ACCOUNTS );
252+ assertEquals (HostType .ACCOUNTS , config .getHostType ());
253+ }
254+
255+ @ Test
256+ public void testMetadataUnifiedIsReturned () {
257+ DatabricksConfig config =
258+ new DatabricksConfig ()
259+ .setHost ("https://my-workspace.cloud.databricks.com" )
260+ .setResolvedHostType (HostType .UNIFIED );
261+ assertEquals (HostType .UNIFIED , config .getHostType ());
262+ }
263+
264+ @ Test
265+ public void testFallsBackToUrlMatchingWhenResolvedHostTypeNull () {
266+ DatabricksConfig config =
267+ new DatabricksConfig ().setHost ("https://accounts.cloud.databricks.com" );
268+ // resolvedHostType is null by default
269+ assertEquals (HostType .ACCOUNTS , config .getHostType ());
270+ }
271+
272+ @ Test
273+ public void testMetadataOverridesExperimentalFlag () {
274+ DatabricksConfig config =
275+ new DatabricksConfig ()
276+ .setHost ("https://my-workspace.cloud.databricks.com" )
277+ .setExperimentalIsUnifiedHost (true )
278+ .setResolvedHostType (HostType .ACCOUNTS );
279+ // Resolved host type takes priority over experimental flag
280+ assertEquals (HostType .ACCOUNTS , config .getHostType ());
281+ }
282+
283+ @ Test
284+ public void testEndToEndResolveToGetHostType () throws IOException {
285+ String response =
286+ "{\" oidc_endpoint\" :\" https://ws.databricks.com/oidc\" ,"
287+ + "\" account_id\" :\" test-account\" ,"
288+ + "\" host_type\" :\" unified\" }" ;
289+ try (FixtureServer server =
290+ new FixtureServer ()
291+ .with ("GET" , "/.well-known/databricks-config" , response , 200 )
292+ .with ("GET" , "/.well-known/databricks-config" , response , 200 )) {
293+ DatabricksConfig config =
294+ new DatabricksConfig ().setHost (server .getUrl ()).setExperimentalIsUnifiedHost (true );
295+ config .resolve (
296+ new Environment (new HashMap <>(), new ArrayList <>(), System .getProperty ("os.name" )));
297+ // After resolve(), tryResolveHostMetadata() should have set resolvedHostType
298+ assertEquals (HostType .UNIFIED , config .getHostType ());
299+ }
300+ }
234301}
0 commit comments