Skip to content

Commit 904bac2

Browse files
committed
feat: add withTenant and withDefaults to CollectionHandleAsync
1 parent 4b52821 commit 904bac2

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

src/main/java/io/weaviate/client6/v1/api/collections/CollectionHandleAsync.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,17 @@ public CollectionHandleAsync<PropertiesT> withConsistencyLevel(ConsistencyLevel
8989
return new CollectionHandleAsync<>(this, CollectionHandleDefaults.of(
9090
def -> def.consistencyLevel(consistencyLevel)));
9191
}
92+
93+
public String tenant() {
94+
return defaults.tenant();
95+
}
96+
97+
public CollectionHandleAsync<PropertiesT> withTenant(String tenant) {
98+
return new CollectionHandleAsync<>(this, CollectionHandleDefaults.of(with -> with.tenant(tenant)));
99+
}
100+
101+
public CollectionHandleAsync<PropertiesT> withDefaults(
102+
Function<CollectionHandleDefaults.Builder, ObjectBuilder<CollectionHandleDefaults>> fn) {
103+
return new CollectionHandleAsync<>(this, CollectionHandleDefaults.of(fn));
104+
}
92105
}

src/test/java/io/weaviate/client6/v1/api/collections/CollectionHandleDefaultsTest.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public class CollectionHandleDefaultsTest {
2424
/** All defaults are {@code null} if none were set. */
2525
@Test
2626
public void test_defaults() {
27-
Assertions.assertThat(HANDLE_NONE.consistencyLevel()).isNull();
27+
Assertions.assertThat(HANDLE_NONE.consistencyLevel()).as("default ConsistencyLevel").isNull();
28+
Assertions.assertThat(HANDLE_NONE.tenant()).as("default tenant").isNull();
2829
}
2930

3031
/**
@@ -39,7 +40,7 @@ public void test_withConsistencyLevel() {
3940
}
4041

4142
/**
42-
* {@link CollectionHandleAsync#withConsistencyLevel} should create a copy with
43+
* {@link CollectionHandleAsync#withTenant} should create a copy with
4344
* different defaults but not modify the original.
4445
*/
4546
@Test
@@ -48,4 +49,26 @@ public void test_withConsistencyLevel_async() {
4849
Assertions.assertThat(handle.consistencyLevel()).isEqualTo(ConsistencyLevel.QUORUM);
4950
Assertions.assertThat(HANDLE_NONE_ASYNC.consistencyLevel()).isNull();
5051
}
52+
53+
/**
54+
* {@link CollectionHandle#withTenant} should create a copy with
55+
* different defaults but not modify the original.
56+
*/
57+
@Test
58+
public void test_withTenant() {
59+
var handle = HANDLE_NONE.withTenant("john_doe");
60+
Assertions.assertThat(handle.tenant()).isEqualTo("john_doe");
61+
Assertions.assertThat(HANDLE_NONE.consistencyLevel()).isNull();
62+
}
63+
64+
/**
65+
* {@link CollectionHandleAsync#withTenant} should create a copy with
66+
* different defaults but not modify the original.
67+
*/
68+
@Test
69+
public void test_withTenant_async() {
70+
var handle = HANDLE_NONE_ASYNC.withTenant("john_doe");
71+
Assertions.assertThat(handle.tenant()).isEqualTo("john_doe");
72+
Assertions.assertThat(HANDLE_NONE_ASYNC.consistencyLevel()).isNull();
73+
}
5174
}

0 commit comments

Comments
 (0)