Skip to content

Commit 2423b42

Browse files
committed
Add test for check toObjectMap method allows null metadata values
Signed-off-by: WOONBE <[email protected]>
1 parent 7182792 commit 2423b42

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2023-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* <https://www.apache.org/licenses/LICENSE-2.0>
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ai.vectorstore.qdrant;
18+
19+
import java.util.Map;
20+
21+
import io.qdrant.client.grpc.JsonWithInt.NullValue;
22+
import io.qdrant.client.grpc.JsonWithInt.Value;
23+
import org.junit.jupiter.api.Test;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
/**
28+
* Tests for {@link QdrantObjectFactory}.
29+
*
30+
* @author Heonwoo Kim
31+
*/
32+
class QdrantObjectFactoryTest {
33+
34+
@Test
35+
void toObjectMapShouldHandleNullValues() {
36+
37+
Map<String, Value> payloadWithNull = Map.of(
38+
"name", Value.newBuilder().setStringValue("Spring AI").build(),
39+
"version", Value.newBuilder().setDoubleValue(1.0).build(),
40+
"is_ga", Value.newBuilder().setBoolValue(true).build(),
41+
"description", Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()
42+
);
43+
44+
Map<String, Object> result = QdrantObjectFactory.toObjectMap(payloadWithNull);
45+
46+
47+
assertThat(result).isNotNull();
48+
49+
assertThat(result).hasSize(4);
50+
51+
assertThat(result.get("name")).isEqualTo("Spring AI");
52+
assertThat(result.get("version")).isEqualTo(1.0);
53+
assertThat(result.get("is_ga")).isEqualTo(true);
54+
55+
assertThat(result).containsKey("description");
56+
assertThat(result.get("description")).isNull();
57+
}
58+
59+
}

0 commit comments

Comments
 (0)