Skip to content

Commit

Permalink
test case for neo4j#576 (neo4j#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy2003 committed Dec 20, 2018
1 parent e2ee13e commit f45b5fd
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
6 changes: 5 additions & 1 deletion test/src/main/java/org/neo4j/ogm/testutil/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Integer> 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<DataItem> 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);
}

}
7 changes: 7 additions & 0 deletions test/src/test/resources/org/neo4j/ogm/cql/nodes.cql
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit f45b5fd

Please sign in to comment.