Skip to content

Commit 6d533ae

Browse files
GH-168 - Fix mutating containers by properties.
Fixes #168.
1 parent d0b1ee7 commit 6d533ae

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

neo4j-cypher-dsl/src/main/java/org/neo4j/cypherdsl/core/Operations.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
final class Operations {
3838

3939
private static final java.util.Set<Class<? extends Expression>> VALID_MUTATORS =
40-
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(Property.class, MapExpression.class, Parameter.class)));
40+
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(MapExpression.class, Parameter.class)));
4141

4242
static Operation concat(Expression op1, Expression op2) {
4343

@@ -113,7 +113,8 @@ static Operation mutate(Expression target, MapExpression value) {
113113
static Operation mutate(Expression target, Expression value) {
114114

115115
Assertions.notNull(value, "New properties value must not be null");
116-
Assertions.isTrue(VALID_MUTATORS.contains(value.getClass()), "A property container can only be mutated by a map, or a parameter or property pointing to a map.");
116+
Assertions.isTrue(Property.class.isAssignableFrom(value.getClass()) || VALID_MUTATORS.contains(value.getClass()),
117+
"A property container can only be mutated by a map, or a parameter or property pointing to a map.");
117118

118119
return Operation.create(target, Operator.MUTATE, value);
119120
}

neo4j-cypher-dsl/src/test/java/org/neo4j/cypherdsl/core/IssueRelatedIT.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ class IssueRelatedIT {
3636
private static final Renderer cypherRenderer = Renderer.getDefaultRenderer();
3737
private final Node person = Cypher.node("Person").named("person");
3838

39-
@Test
40-
void unionMustClearCache() {
41-
42-
43-
}
44-
4539
@Test
4640
void gh115() {
4741
Node nodes = Cypher.node("Node").named("node").withProperties("id", Cypher.literalOf("node_42"));
@@ -605,6 +599,15 @@ void removeAllPropertiesShouldWork() {
605599
assertThat(cypher).isEqualTo("MATCH (n:`DeleteMe`) SET n = {} SET n.newProperty = 'aValue' RETURN n");
606600
}
607601

602+
@Test // GH-168
603+
void containersMustBeMutatableByProperties() {
604+
605+
Node nodeA = Cypher.node("Target").named("t");
606+
Node nodeB = Cypher.node("Source").named("s");
607+
String cypher = Cypher.match(nodeA, nodeB).mutate(nodeA, nodeB.property("whatever")).build().getCypher();
608+
assertThat(cypher).isEqualTo("MATCH (t:`Target`), (s:`Source`) SET t += s.whatever");
609+
}
610+
608611
@ParameterizedTest // GH-152
609612
@MethodSource("relpatternChainingArgs")
610613
void relpatternChaining(boolean multihops, int length, boolean backward, String expected) {

0 commit comments

Comments
 (0)