diff --git a/test/src/main/java/org/neo4j/ogm/testutil/TestUtils.java b/test/src/main/java/org/neo4j/ogm/testutil/TestUtils.java index 8f246f3487..e2fe29bf09 100644 --- a/test/src/main/java/org/neo4j/ogm/testutil/TestUtils.java +++ b/test/src/main/java/org/neo4j/ogm/testutil/TestUtils.java @@ -48,7 +48,11 @@ public static StringBuilder readCQLFile(String cqlFileName) { Thread.currentThread().getContextClassLoader().getResourceAsStream(cqlFileName))) { scanner.useDelimiter(System.getProperty("line.separator")); while (scanner.hasNext()) { - cypher.append(scanner.next()).append(' '); + String statement = scanner.next(); + if (statement.startsWith("//")) { + continue; + } + cypher.append(statement).append(' '); } } return cypher; diff --git a/test/src/test/java/org/neo4j/ogm/persistence/examples/nodes/NodeTest.java b/test/src/test/java/org/neo4j/ogm/persistence/examples/nodes/NodeTest.java new file mode 100644 index 0000000000..891ddddbdd --- /dev/null +++ b/test/src/test/java/org/neo4j/ogm/persistence/examples/nodes/NodeTest.java @@ -0,0 +1,96 @@ +package org.neo4j.ogm.persistence.examples.nodes; + +import static org.assertj.core.api.Assertions.*; + +import java.io.IOException; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.neo4j.ogm.cypher.ComparisonOperator; +import org.neo4j.ogm.cypher.Filter; +import org.neo4j.ogm.domain.nodes.DataItem; +import org.neo4j.ogm.domain.nodes.FormulaItem; +import org.neo4j.ogm.session.Session; +import org.neo4j.ogm.session.SessionFactory; +import org.neo4j.ogm.testutil.MultiDriverTestClass; +import org.neo4j.ogm.testutil.TestUtils; + +/** + * Test class reproducing issue #576 + * + * @author Andreas Berger + */ +@RunWith(Parameterized.class) +public class NodeTest extends MultiDriverTestClass { + + private static SessionFactory sessionFactory; + + private Session session; + private Integer additionalObjects; + + @BeforeClass + public static void oneTimeSetUp() { + sessionFactory = new SessionFactory(driver, "org.neo4j.ogm.domain.nodes"); + } + + @Parameterized.Parameters + public static List data() { + return IntStream + .range(0, 10) // change the number of pre stored objects here + .boxed() + .collect(Collectors.toList()); + } + + public NodeTest(Integer additionalObjects) { + this.additionalObjects = additionalObjects; + } + + @Before + public void init() throws IOException { + session = sessionFactory.openSession(); + session.purgeDatabase(); + session.clear(); + IntStream + .range(0, additionalObjects) + .forEach(i -> session.query("CREATE(:Foo)", Collections.emptyMap())); + session.query(TestUtils.readCQLFile("org/neo4j/ogm/cql/nodes.cql").toString(), Collections.emptyMap()); + } + + @After + public void tearDown() { + session.purgeDatabase(); + } + + @Test + public void test() { + Collection dataItems; + FormulaItem formulaItem; + + Filter filter = new Filter("nodeId", ComparisonOperator.EQUALS, "m1"); + + dataItems = session.loadAll(DataItem.class, filter); + assertThat(dataItems.size()).isEqualTo(1); + formulaItem = (FormulaItem) dataItems.iterator().next(); + assertThat(formulaItem.getVariables().size()).isEqualTo(3); + + formulaItem.getVariables() + .removeIf( + variable -> variable.getVariable().equals("A") && variable.getDataItem().getNodeId().equals("m2")); + session.save(formulaItem); + + dataItems = session.loadAll(DataItem.class, filter); + assertThat(dataItems.size()).isEqualTo(1); + formulaItem = (FormulaItem) dataItems.iterator().next(); + assertThat(formulaItem.getVariables().size()).isEqualTo(2); + } + +} diff --git a/test/src/test/resources/org/neo4j/ogm/cql/nodes.cql b/test/src/test/resources/org/neo4j/ogm/cql/nodes.cql new file mode 100644 index 0000000000..bf5b621e9d --- /dev/null +++ b/test/src/test/resources/org/neo4j/ogm/cql/nodes.cql @@ -0,0 +1,7 @@ +CREATE (m1:FormulaItem:DataItem {nodeId: 'm1'}) +CREATE (m2:DataItem {nodeId: 'm2'}) +CREATE (m3:DataItem {nodeId: 'm3'}) + +CREATE (m1)-[:USES {variable: 'A'}]->(m2) +CREATE (m1)-[:USES {variable: 'B'}]->(m2) +CREATE (m1)-[:USES {variable: 'A'}]->(m3)