Skip to content

Commit b8d8235

Browse files
authored
Add comprehensive test coverage for Neo4jVectorFilterExpressionConverter (#3957)
Signed-off-by: Alex Klimenko <[email protected]>
1 parent c37ed3c commit b8d8235

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

vector-stores/spring-ai-neo4j-store/src/test/java/org/springframework/ai/vectorstore/neo4j/filter/Neo4jVectorFilterExpressionConverterTests.java

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,115 @@ public void testComplexIdentifiers2() {
139139
.isEqualTo("node.`metadata.author` IN [\"john\",\"jill\"] AND node.`metadata.'article_type'` = \"blog\"");
140140
}
141141

142+
@Test
143+
public void testEmptyList() {
144+
// category IN []
145+
String vectorExpr = this.converter
146+
.convertExpression(new Expression(IN, new Key("category"), new Value(List.of())));
147+
assertThat(vectorExpr).isEqualTo("node.`metadata.category` IN []");
148+
}
149+
150+
@Test
151+
public void testSingleItemList() {
152+
// status IN ["active"]
153+
String vectorExpr = this.converter
154+
.convertExpression(new Expression(IN, new Key("status"), new Value(List.of("active"))));
155+
assertThat(vectorExpr).isEqualTo("node.`metadata.status` IN [\"active\"]");
156+
}
157+
158+
@Test
159+
public void testNullValue() {
160+
// description = null
161+
String vectorExpr = this.converter
162+
.convertExpression(new Expression(EQ, new Key("description"), new Value(null)));
163+
assertThat(vectorExpr).isEqualTo("node.`metadata.description` = null");
164+
}
165+
166+
@Test
167+
public void testNestedJsonPath() {
168+
// entity.profile.name = "EntityA"
169+
String vectorExpr = this.converter
170+
.convertExpression(new Expression(EQ, new Key("entity.profile.name"), new Value("EntityA")));
171+
assertThat(vectorExpr).isEqualTo("node.`metadata.entity.profile.name` = \"EntityA\"");
172+
}
173+
174+
@Test
175+
public void testNumericStringValue() {
176+
// id = "1"
177+
String vectorExpr = this.converter.convertExpression(new Expression(EQ, new Key("id"), new Value("1")));
178+
assertThat(vectorExpr).isEqualTo("node.`metadata.id` = \"1\"");
179+
}
180+
181+
@Test
182+
public void testZeroValue() {
183+
// count = 0
184+
String vectorExpr = this.converter.convertExpression(new Expression(EQ, new Key("count"), new Value(0)));
185+
assertThat(vectorExpr).isEqualTo("node.`metadata.count` = 0");
186+
}
187+
188+
@Test
189+
public void testComplexNestedGroups() {
190+
// ((fieldA >= 100 AND fieldB = "X1") OR (fieldA >= 50 AND fieldB = "Y2")) AND
191+
// fieldC <> "inactive"
192+
String vectorExpr = this.converter.convertExpression(new Expression(AND,
193+
new Group(new Expression(OR,
194+
new Group(new Expression(AND, new Expression(GTE, new Key("fieldA"), new Value(100)),
195+
new Expression(EQ, new Key("fieldB"), new Value("X1")))),
196+
new Group(new Expression(AND, new Expression(GTE, new Key("fieldA"), new Value(50)),
197+
new Expression(EQ, new Key("fieldB"), new Value("Y2")))))),
198+
new Expression(NE, new Key("fieldC"), new Value("inactive"))));
199+
200+
assertThat(vectorExpr).isEqualTo("((node.`metadata.fieldA` >= 100 AND node.`metadata.fieldB` = \"X1\") OR "
201+
+ "(node.`metadata.fieldA` >= 50 AND node.`metadata.fieldB` = \"Y2\")) AND "
202+
+ "node.`metadata.fieldC` <> \"inactive\"");
203+
}
204+
205+
@Test
206+
public void testMixedDataTypes() {
207+
// active = true AND score >= 1.5 AND tags IN ["featured", "premium"] AND version
208+
// = 1
209+
String vectorExpr = this.converter.convertExpression(new Expression(AND,
210+
new Expression(AND,
211+
new Expression(AND, new Expression(EQ, new Key("active"), new Value(true)),
212+
new Expression(GTE, new Key("score"), new Value(1.5))),
213+
new Expression(IN, new Key("tags"), new Value(List.of("featured", "premium")))),
214+
new Expression(EQ, new Key("version"), new Value(1))));
215+
216+
assertThat(vectorExpr).isEqualTo("node.`metadata.active` = true AND node.`metadata.score` >= 1.5 AND "
217+
+ "node.`metadata.tags` IN [\"featured\",\"premium\"] AND node.`metadata.version` = 1");
218+
}
219+
220+
@Test
221+
public void testNinWithMixedTypes() {
222+
// status NOT IN ["A", "B", "C"]
223+
String vectorExpr = this.converter
224+
.convertExpression(new Expression(NIN, new Key("status"), new Value(List.of("A", "B", "C"))));
225+
assertThat(vectorExpr).isEqualTo("NOT node.`metadata.status` IN [\"A\",\"B\",\"C\"]");
226+
}
227+
228+
@Test
229+
public void testEmptyStringValue() {
230+
// description <> ""
231+
String vectorExpr = this.converter.convertExpression(new Expression(NE, new Key("description"), new Value("")));
232+
assertThat(vectorExpr).isEqualTo("node.`metadata.description` <> \"\"");
233+
}
234+
235+
@Test
236+
public void testArrayIndexAccess() {
237+
// tags[0] = "important"
238+
String vectorExpr = this.converter
239+
.convertExpression(new Expression(EQ, new Key("tags[0]"), new Value("important")));
240+
assertThat(vectorExpr).isEqualTo("node.`metadata.tags[0]` = \"important\"");
241+
}
242+
243+
@Test
244+
public void testNegativeNumbers() {
245+
// valueA <= -5 AND valueB >= -10
246+
String vectorExpr = this.converter
247+
.convertExpression(new Expression(AND, new Expression(LTE, new Key("valueA"), new Value(-5)),
248+
new Expression(GTE, new Key("valueB"), new Value(-10))));
249+
250+
assertThat(vectorExpr).isEqualTo("node.`metadata.valueA` <= -5 AND node.`metadata.valueB` >= -10");
251+
}
252+
142253
}

0 commit comments

Comments
 (0)