Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class HostMetadata {
@JsonProperty("workspace_id")
private String workspaceId;

@JsonProperty("cloud")
private String cloud;

public HostMetadata() {}

public HostMetadata(String oidcEndpoint, String accountId, String workspaceId) {
Expand All @@ -28,6 +31,13 @@ public HostMetadata(String oidcEndpoint, String accountId, String workspaceId) {
this.workspaceId = workspaceId;
}

public HostMetadata(String oidcEndpoint, String accountId, String workspaceId, String cloud) {
this.oidcEndpoint = oidcEndpoint;
this.accountId = accountId;
this.workspaceId = workspaceId;
this.cloud = cloud;
}

public String getOidcEndpoint() {
return oidcEndpoint;
}
Expand All @@ -39,4 +49,8 @@ public String getAccountId() {
public String getWorkspaceId() {
return workspaceId;
}

public String getCloud() {
return cloud;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.databricks.sdk.core.oauth;

import static org.junit.jupiter.api.Assertions.*;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

class HostMetadataTest {

private final ObjectMapper mapper = new ObjectMapper();

@Test
void testDeserializeWithCloud() throws Exception {
String json =
"{\"oidc_endpoint\":\"https://example.com/oidc\","
+ "\"account_id\":\"acc-123\","
+ "\"workspace_id\":\"ws-456\","
+ "\"cloud\":\"aws\"}";

HostMetadata meta = mapper.readValue(json, HostMetadata.class);

assertEquals("https://example.com/oidc", meta.getOidcEndpoint());
assertEquals("acc-123", meta.getAccountId());
assertEquals("ws-456", meta.getWorkspaceId());
assertEquals("aws", meta.getCloud());
}

@Test
void testDeserializeWithoutCloud() throws Exception {
String json =
"{\"oidc_endpoint\":\"https://example.com/oidc\","
+ "\"account_id\":\"acc-123\","
+ "\"workspace_id\":\"ws-456\"}";

HostMetadata meta = mapper.readValue(json, HostMetadata.class);

assertEquals("https://example.com/oidc", meta.getOidcEndpoint());
assertEquals("acc-123", meta.getAccountId());
assertEquals("ws-456", meta.getWorkspaceId());
assertNull(meta.getCloud());
}

@Test
void testConstructorWithCloud() {
HostMetadata meta = new HostMetadata("https://example.com/oidc", "acc-123", "ws-456", "gcp");

assertEquals("https://example.com/oidc", meta.getOidcEndpoint());
assertEquals("acc-123", meta.getAccountId());
assertEquals("ws-456", meta.getWorkspaceId());
assertEquals("gcp", meta.getCloud());
}

@Test
void testConstructorWithoutCloud() {
HostMetadata meta = new HostMetadata("https://example.com/oidc", "acc-123", "ws-456");

assertEquals("https://example.com/oidc", meta.getOidcEndpoint());
assertEquals("acc-123", meta.getAccountId());
assertEquals("ws-456", meta.getWorkspaceId());
assertNull(meta.getCloud());
}
}
Loading