Skip to content

Commit 3b59e68

Browse files
alxkmmarkpollack
authored andcommitted
test: Enhances test coverage for QdrantObjectFactory.toObjectMap
Co-authored-by: Oleksandr Klymenko <[email protected]> Signed-off-by: Oleksandr Klymenko <[email protected]>
1 parent c72c8c2 commit 3b59e68

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

vector-stores/spring-ai-qdrant-store/src/test/java/org/springframework/ai/vectorstore/qdrant/QdrantObjectFactoryTests.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,83 @@ void toObjectMapShouldHandleMixedDataTypes() {
113113
assertThat(result.get("number")).isEqualTo(1L);
114114
}
115115

116+
@Test
117+
void toObjectMapShouldHandleWhitespaceStrings() {
118+
Map<String, Value> payload = Map.of("spaces", Value.newBuilder().setStringValue(" ").build(), "tabs",
119+
Value.newBuilder().setStringValue("\t\t").build(), "newlines",
120+
Value.newBuilder().setStringValue("\n\r\n").build(), "mixed",
121+
Value.newBuilder().setStringValue(" \t\n mixed \r\n ").build());
122+
123+
Map<String, Object> result = QdrantObjectFactory.toObjectMap(payload);
124+
125+
assertThat(result).hasSize(4);
126+
assertThat(result.get("spaces")).isEqualTo(" ");
127+
assertThat(result.get("tabs")).isEqualTo("\t\t");
128+
assertThat(result.get("newlines")).isEqualTo("\n\r\n");
129+
assertThat(result.get("mixed")).isEqualTo(" \t\n mixed \r\n ");
130+
}
131+
132+
@Test
133+
void toObjectMapShouldHandleComplexFieldNames() {
134+
Map<String, Value> payload = Map.of("field_with_underscores",
135+
Value.newBuilder().setStringValue("value1").build(), "field-with-dashes",
136+
Value.newBuilder().setStringValue("value2").build(), "field.with.dots",
137+
Value.newBuilder().setStringValue("value3").build(), "FIELD_WITH_CAPS",
138+
Value.newBuilder().setStringValue("value4").build(), "field1",
139+
Value.newBuilder().setStringValue("value5").build());
140+
141+
Map<String, Object> result = QdrantObjectFactory.toObjectMap(payload);
142+
143+
assertThat(result).hasSize(5);
144+
assertThat(result.get("field_with_underscores")).isEqualTo("value1");
145+
assertThat(result.get("field-with-dashes")).isEqualTo("value2");
146+
assertThat(result.get("field.with.dots")).isEqualTo("value3");
147+
assertThat(result.get("FIELD_WITH_CAPS")).isEqualTo("value4");
148+
assertThat(result.get("field1")).isEqualTo("value5");
149+
}
150+
151+
@Test
152+
void toObjectMapShouldHandleSingleCharacterValues() {
153+
Map<String, Value> payload = Map.of("singleChar", Value.newBuilder().setStringValue("a").build(), "specialChar",
154+
Value.newBuilder().setStringValue("@").build(), "digit",
155+
Value.newBuilder().setStringValue("1").build());
156+
157+
Map<String, Object> result = QdrantObjectFactory.toObjectMap(payload);
158+
159+
assertThat(result).hasSize(3);
160+
assertThat(result.get("singleChar")).isEqualTo("a");
161+
assertThat(result.get("specialChar")).isEqualTo("@");
162+
assertThat(result.get("digit")).isEqualTo("1");
163+
}
164+
165+
@Test
166+
void toObjectMapShouldHandleAllNullValues() {
167+
Map<String, Value> payload = Map.of("null1", Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build(),
168+
"null2", Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build(), "null3",
169+
Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build());
170+
171+
Map<String, Object> result = QdrantObjectFactory.toObjectMap(payload);
172+
173+
assertThat(result).hasSize(3);
174+
assertThat(result.get("null1")).isNull();
175+
assertThat(result.get("null2")).isNull();
176+
assertThat(result.get("null3")).isNull();
177+
assertThat(result).containsKeys("null1", "null2", "null3");
178+
}
179+
180+
@Test
181+
void toObjectMapShouldHandleDuplicateValues() {
182+
Map<String, Value> payload = Map.of("field1", Value.newBuilder().setStringValue("same").build(), "field2",
183+
Value.newBuilder().setStringValue("same").build(), "field3",
184+
Value.newBuilder().setIntegerValue(1).build(), "field4", Value.newBuilder().setIntegerValue(1).build());
185+
186+
Map<String, Object> result = QdrantObjectFactory.toObjectMap(payload);
187+
188+
assertThat(result).hasSize(4);
189+
assertThat(result.get("field1")).isEqualTo("same");
190+
assertThat(result.get("field2")).isEqualTo("same");
191+
assertThat(result.get("field3")).isEqualTo(1L);
192+
assertThat(result.get("field4")).isEqualTo(1L);
193+
}
194+
116195
}

0 commit comments

Comments
 (0)