Skip to content

Commit

Permalink
[pLz5YbCW] order tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nadja-muller committed Oct 3, 2023
1 parent 54970b9 commit 8b470ff
Showing 1 changed file with 58 additions and 59 deletions.
117 changes: 58 additions & 59 deletions core/src/test/java/apoc/merge/MergeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void testMergeNodeWithStats() {
testMergeNodeCommon(true);
}

// MERGE NODES
private void testMergeNodeCommon(boolean isWithStats) {
String procName = isWithStats ? "nodeWithStats" : "node";

Expand Down Expand Up @@ -111,33 +112,6 @@ public void testMergeWithNoLabel() {
);
}

@Test
public void testMergeRelationships() {
db.executeTransactionally("create (:Person{name:'Foo'}), (:Person{name:'Bar'})");

testCall(db, "MERGE (s:Person{name:'Foo'}) MERGE (e:Person{name:'Bar'}) WITH s,e CALL apoc.merge.relationship(s, 'KNOWS', {rid:123}, {since:'Thu'}, e) YIELD rel RETURN rel",
(row) -> {
Relationship rel = (Relationship) row.get("rel");
assertEquals("KNOWS", rel.getType().name());
assertEquals(123L, rel.getProperty("rid"));
assertEquals("Thu", rel.getProperty("since"));
});

testCall(db, "MERGE (s:Person{name:'Foo'}) MERGE (e:Person{name:'Bar'}) WITH s,e CALL apoc.merge.relationship(s, 'KNOWS', {rid:123}, {since:'Fri'}, e) YIELD rel RETURN rel",
(row) -> {
Relationship rel = (Relationship) row.get("rel");
assertEquals("KNOWS", rel.getType().name());
assertEquals(123L, rel.getProperty("rid"));
assertEquals("Thu", rel.getProperty("since"));
});
testCall(db, "MERGE (s:Person{name:'Foo'}) MERGE (e:Person{name:'Bar'}) WITH s,e CALL apoc.merge.relationship(s, 'OTHER', null, null, e) YIELD rel RETURN rel",
(row) -> {
Relationship rel = (Relationship) row.get("rel");
assertEquals("OTHER", rel.getType().name());
assertTrue(rel.getAllProperties().isEmpty());
});
}

@Test
public void testMergeWithEmptyIdentityPropertiesShouldFail() {
for (String idProps: new String[]{"null", "{}"}) {
Expand Down Expand Up @@ -173,44 +147,22 @@ public void testMergeNodeWithEmptyLabelListShouldFail() {
}
}

@Test
public void testMergeRelWithNullRelTypeShouldFail() {
try {
testCall(db, "MERGE (s:Person{name:'Foo'}) MERGE (e:Person{name:'Bar'}) WITH s,e CALL apoc.merge.relationship(s, null, null, null, e) YIELD rel RETURN rel",
row -> assertTrue(row.get("rel") instanceof Relationship));
fail();
} catch (QueryExecutionException e) {
assertTrue(e.getMessage().contains("It is not possible to merge a relationship without a relationship type."));
}
}

@Test
public void testMergeWithEmptyRelTypeShouldFail() {
try {
testCall(db, "MERGE (s:Person{name:'Foo'}) MERGE (e:Person{name:'Bar'}) WITH s,e CALL apoc.merge.relationship(s, '', null, null, e) YIELD rel RETURN rel",
row -> assertTrue(row.get("rel") instanceof Relationship));
fail();
} catch (QueryExecutionException e) {
assertTrue(e.getMessage().contains("It is not possible to merge a relationship without a relationship type."));
}
}

@Test
public void testEscapeIdentityPropertiesWithSpecialCharactersShouldWork() {
for (String key: new String[]{"normal", "i:d", "i-d", "i d"}) {
Map<String, Object> identProps = MapUtil.map(key, "value");
Map<String, Object> params = MapUtil.map("identProps", identProps);

testCall(db, "CALL apoc.merge.node(['Person'], $identProps) YIELD node RETURN node", params,
(row) -> {
Node node = (Node) row.get("node");
assertNotNull(node);
assertTrue(node.hasProperty(key));
assertEquals("value", node.getProperty(key));
});
(row) -> {
Node node = (Node) row.get("node");
assertNotNull(node);
assertTrue(node.hasProperty(key));
assertEquals("value", node.getProperty(key));
});
}
}

@Test
public void testLabelsWithSpecialCharactersShouldWork() {
for (String label: new String[]{"Label with spaces", ":LabelWithColon", "label-with-dash", "LabelWithUmlautsÄÖÜ"}) {
Expand All @@ -220,6 +172,34 @@ public void testLabelsWithSpecialCharactersShouldWork() {
}
}

// MERGE RELATIONSHIPS
@Test
public void testMergeRelationships() {
db.executeTransactionally("create (:Person{name:'Foo'}), (:Person{name:'Bar'})");

testCall(db, "MERGE (s:Person{name:'Foo'}) MERGE (e:Person{name:'Bar'}) WITH s,e CALL apoc.merge.relationship(s, 'KNOWS', {rid:123}, {since:'Thu'}, e) YIELD rel RETURN rel",
(row) -> {
Relationship rel = (Relationship) row.get("rel");
assertEquals("KNOWS", rel.getType().name());
assertEquals(123L, rel.getProperty("rid"));
assertEquals("Thu", rel.getProperty("since"));
});

testCall(db, "MERGE (s:Person{name:'Foo'}) MERGE (e:Person{name:'Bar'}) WITH s,e CALL apoc.merge.relationship(s, 'KNOWS', {rid:123}, {since:'Fri'}, e) YIELD rel RETURN rel",
(row) -> {
Relationship rel = (Relationship) row.get("rel");
assertEquals("KNOWS", rel.getType().name());
assertEquals(123L, rel.getProperty("rid"));
assertEquals("Thu", rel.getProperty("since"));
});
testCall(db, "MERGE (s:Person{name:'Foo'}) MERGE (e:Person{name:'Bar'}) WITH s,e CALL apoc.merge.relationship(s, 'OTHER', null, null, e) YIELD rel RETURN rel",
(row) -> {
Relationship rel = (Relationship) row.get("rel");
assertEquals("OTHER", rel.getType().name());
assertTrue(rel.getAllProperties().isEmpty());
});
}

@Test
public void testRelationshipTypesWithSpecialCharactersShouldWork() {
for (String relType: new String[]{"Reltype with space", ":ReltypeWithCOlon", "rel-type-with-dash"}) {
Expand All @@ -229,10 +209,29 @@ public void testRelationshipTypesWithSpecialCharactersShouldWork() {
}
}

@Test
public void testMergeRelWithNullRelTypeShouldFail() {
try {
testCall(db, "MERGE (s:Person{name:'Foo'}) MERGE (e:Person{name:'Bar'}) WITH s,e CALL apoc.merge.relationship(s, null, null, null, e) YIELD rel RETURN rel",
row -> assertTrue(row.get("rel") instanceof Relationship));
fail();
} catch (QueryExecutionException e) {
assertTrue(e.getMessage().contains("It is not possible to merge a relationship without a relationship type."));
}
}

// MERGE EAGER TESTS

@Test
public void testMergeWithEmptyRelTypeShouldFail() {
try {
testCall(db, "MERGE (s:Person{name:'Foo'}) MERGE (e:Person{name:'Bar'}) WITH s,e CALL apoc.merge.relationship(s, '', null, null, e) YIELD rel RETURN rel",
row -> assertTrue(row.get("rel") instanceof Relationship));
fail();
} catch (QueryExecutionException e) {
assertTrue(e.getMessage().contains("It is not possible to merge a relationship without a relationship type."));
}
}

// MERGE EAGER TESTS
@Test
public void testMergeEagerNode() {
testMergeEagerCommon(false);
Expand Down

0 comments on commit 8b470ff

Please sign in to comment.