Skip to content

Commit 4ab833a

Browse files
committed
test(azure): add unit tests for mutable metadata parsing and distance
Add `AzureVectorStoreMetadataParsingTests` to verify: - valid JSON → mutable LinkedHashMap copy - blank/invalid JSON → empty LinkedHashMap - can inject `distance` without throwing UnsupportedOperationException These tests fail on the previous implementation and pass with the fix, guarding against regressions. Relates to GH-4117 Signed-off-by: Jinwoo Lee <[email protected]>
1 parent 25b0353 commit 4ab833a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.springframework.ai.vectorstore.azure;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.util.Map;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
class AzureVectorStoreMetadataTests {
10+
11+
@Test
12+
void returnsMutableMapForBlankOrNull() {
13+
Map<String, Object> m1 = AzureVectorStore.parseMetadataToMutable(null);
14+
m1.put("distance", 0.1);
15+
assertThat(m1).containsEntry("distance", 0.1);
16+
17+
Map<String, Object> m2 = AzureVectorStore.parseMetadataToMutable("");
18+
m2.put("distance", 0.2);
19+
assertThat(m2).containsEntry("distance", 0.2);
20+
21+
Map<String, Object> m3 = AzureVectorStore.parseMetadataToMutable(" ");
22+
m3.put("distance", 0.3);
23+
assertThat(m3).containsEntry("distance", 0.3);
24+
}
25+
26+
@Test
27+
void wrapsParsedJsonInLinkedHashMapSoItIsMutable() {
28+
Map<String, Object> map = AzureVectorStore.parseMetadataToMutable("{\"k\":\"v\"}");
29+
assertThat(map).containsEntry("k", "v");
30+
map.put("distance", 0.4);
31+
assertThat(map).containsEntry("distance", 0.4);
32+
}
33+
34+
}

0 commit comments

Comments
 (0)