Skip to content

Commit ba47000

Browse files
committed
tests
1 parent 1609dd5 commit ba47000

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

databricks-sdk-java/src/main/java/com/databricks/sdk/core/ApiClient.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static class Builder {
4242
private Integer debugTruncateBytes;
4343
private HttpClient httpClient;
4444
private String accountId;
45-
private String defaultWorkspaceId;
45+
private String workspaceId;
4646
private RetryStrategyPicker retryStrategyPicker;
4747
private boolean isDebugHeaders;
4848

@@ -53,6 +53,7 @@ public Builder withDatabricksConfig(DatabricksConfig config) {
5353
this.httpClient = config.getHttpClient();
5454
this.debugTruncateBytes = config.getDebugTruncateBytes();
5555
this.accountId = config.getAccountId();
56+
this.workspaceId = config.getWorkspaceId();
5657
this.isDebugHeaders = config.isDebugHeaders();
5758

5859
if (config.getDisableRetries()) {
@@ -115,7 +116,7 @@ public ApiClient build() {
115116
private final Function<Void, String> getHostFunc;
116117
private final Function<Void, String> getAuthTypeFunc;
117118
private final String accountId;
118-
private final String defaultWorkspaceId;
119+
private final String workspaceId;
119120
private final boolean isDebugHeaders;
120121
private static final String RETRY_AFTER_HEADER = "retry-after";
121122

@@ -127,8 +128,8 @@ public String configuredAccountID() {
127128
return accountId;
128129
}
129130

130-
public String defaultWorkspaceId() {
131-
return defaultWorkspaceId;
131+
public String workspaceId() {
132+
return workspaceId;
132133
}
133134

134135
public ApiClient(DatabricksConfig config) {
@@ -149,7 +150,7 @@ private ApiClient(Builder builder) {
149150
this.getAuthTypeFunc = builder.getAuthTypeFunc != null ? builder.getAuthTypeFunc : v -> "";
150151
this.httpClient = builder.httpClient;
151152
this.accountId = builder.accountId;
152-
this.defaultWorkspaceId = builder.defaultWorkspaceId;
153+
this.workspaceId = builder.workspaceId;
153154
this.retryStrategyPicker =
154155
builder.retryStrategyPicker != null
155156
? builder.retryStrategyPicker

databricks-sdk-java/src/test/java/com/databricks/sdk/core/ApiClientTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,4 +483,30 @@ void privateLinkRedirectBecomesPrivateLinkValidationError() throws MalformedURLE
483483
new Request("GET", req.getUri().getPath()), MyEndpointResponse.class));
484484
assertTrue(e.getMessage().contains("AWS PrivateLink"));
485485
}
486+
487+
@Test
488+
void testDefaultWorkspaceIdReturnsNullWhenNotSet() {
489+
Request req = getBasicRequest();
490+
DatabricksConfig config =
491+
new DatabricksConfig()
492+
.setHost("http://my.host")
493+
.setCredentialsProvider(new DummyCredentialsProvider());
494+
ApiClient client =
495+
getApiClient(config, req, Collections.singletonList(getSuccessResponse(req)));
496+
assertNull(client.workspaceId());
497+
}
498+
499+
@Test
500+
void testDefaultWorkspaceIdReturnsValueFromConfig() {
501+
String expectedWorkspaceId = "test-workspace-123";
502+
Request req = getBasicRequest();
503+
DatabricksConfig config =
504+
new DatabricksConfig()
505+
.setHost("http://my.host")
506+
.setWorkspaceId(expectedWorkspaceId)
507+
.setCredentialsProvider(new DummyCredentialsProvider());
508+
ApiClient client =
509+
getApiClient(config, req, Collections.singletonList(getSuccessResponse(req)));
510+
assertEquals(expectedWorkspaceId, client.workspaceId());
511+
}
486512
}

0 commit comments

Comments
 (0)