|
1 | 1 | package io.weaviate.integration; |
2 | 2 |
|
| 3 | +import java.io.IOException; |
3 | 4 | import java.time.OffsetDateTime; |
4 | 5 | import java.util.List; |
5 | 6 | import java.util.Map; |
|
14 | 15 | import io.weaviate.ConcurrentTest; |
15 | 16 | import io.weaviate.client6.v1.api.WeaviateClient; |
16 | 17 | import io.weaviate.client6.v1.api.collections.CollectionConfig; |
| 18 | +import io.weaviate.client6.v1.api.collections.WeaviateObject; |
17 | 19 | import io.weaviate.client6.v1.api.collections.annotations.Collection; |
18 | 20 | import io.weaviate.client6.v1.api.collections.annotations.Property; |
19 | 21 | import io.weaviate.client6.v1.api.collections.data.InsertManyResponse.InsertObject; |
|
23 | 25 | public class ORMITest extends ConcurrentTest { |
24 | 26 | private static WeaviateClient client = Container.WEAVIATE.getClient(); |
25 | 27 |
|
26 | | - @Collection("ORMITest") |
| 28 | + @Collection("ORMITestThings") |
27 | 29 | static record Thing( |
28 | 30 | // text / text[] |
29 | 31 | String text, |
@@ -95,7 +97,7 @@ public void test_createCollection() throws Exception { |
95 | 97 |
|
96 | 98 | // Assert |
97 | 99 | Assertions.assertThat(config).get() |
98 | | - .returns("ORMITest", CollectionConfig::collectionName) |
| 100 | + .returns("ORMITestThings", CollectionConfig::collectionName) |
99 | 101 | .extracting(CollectionConfig::properties, |
100 | 102 | InstanceOfAssertFactories.list(io.weaviate.client6.v1.api.collections.Property.class)) |
101 | 103 | .extracting(p -> Map.entry( |
@@ -307,4 +309,45 @@ public void test_insertManyAndQuery() throws Exception { |
307 | 309 | .usingRecursiveComparison(COMPARISON_CONFIG) |
308 | 310 | .asInstanceOf(InstanceOfAssertFactories.list(Thing.class)); |
309 | 311 | } |
| 312 | + |
| 313 | + @Collection("ORMITestSongs") |
| 314 | + record Song( |
| 315 | + String title, |
| 316 | + String album, |
| 317 | + int year, |
| 318 | + boolean hasAward, |
| 319 | + Long monthlyListeners) { |
| 320 | + } |
| 321 | + |
| 322 | + /** |
| 323 | + * Test that serialization works correctly when some fields are null and |
| 324 | + * deserialization works correctly when some properties are not returned. |
| 325 | + */ |
| 326 | + @Test |
| 327 | + public void test_partialScan() throws IOException { |
| 328 | + client.collections.create(Song.class); |
| 329 | + |
| 330 | + var songs = client.collections.use(Song.class); |
| 331 | + |
| 332 | + // Act: insert with nulls |
| 333 | + var dystopia = songs.data.insert(new Song( |
| 334 | + "Dystopia", |
| 335 | + null, |
| 336 | + 2016, |
| 337 | + true, |
| 338 | + null)); |
| 339 | + |
| 340 | + // Act: return subset of the properties |
| 341 | + var got = songs.query.byId(dystopia.uuid(), |
| 342 | + q -> q.returnProperties("title", "hasAward")); |
| 343 | + |
| 344 | + // Assert |
| 345 | + Assertions.assertThat(got).get() |
| 346 | + .extracting(WeaviateObject::properties) |
| 347 | + .returns("Dystopia", Song::title) |
| 348 | + .returns(null, Song::album) |
| 349 | + .returns(0, Song::year) |
| 350 | + .returns(true, Song::hasAward) |
| 351 | + .returns(null, Song::monthlyListeners); |
| 352 | + } |
310 | 353 | } |
0 commit comments