use of org.neo4j.ogm.domain.tree.Entity in project neo4j-ogm by neo4j.
the class TreeIntegrationTest method shouldMapElementsToTreeSetProperly.
// GH-88
@Test
public void shouldMapElementsToTreeSetProperly() {
String cypher = "CREATE (parent:Entity {name:'parent'}) CREATE (child1:Entity {name:'c1'}) CREATE (child2:Entity {name:'c2'}) CREATE (child1)-[:REL]->(parent) CREATE (child2)-[:REL]->(parent)";
session.query(cypher, Collections.emptyMap());
session.clear();
Entity parent = session.loadAll(Entity.class, new Filter("name", ComparisonOperator.EQUALS, "parent")).iterator().next();
assertThat(parent).isNotNull();
assertThat(parent.getChildren()).hasSize(2);
assertThat(parent.getParent()).isNull();
List<String> childNames = new ArrayList<>();
for (Entity child : parent.getChildren()) {
childNames.add(child.getName());
assertThat(child.getParent().getName()).isEqualTo(parent.getName());
}
assertThat(childNames.get(0)).isEqualTo("c1");
assertThat(childNames.get(1)).isEqualTo("c2");
}
use of org.neo4j.ogm.domain.tree.Entity in project neo4j-ogm by neo4j.
the class TreeIntegrationTest method shouldCreateTreeProperly.
// DATAGRAPH-731
@Test
public void shouldCreateTreeProperly() {
Entity parent = new Entity("parent");
Entity child01 = new Entity("child01").setParent(parent);
Entity child02 = new Entity("child02").setParent(parent);
session.save(parent);
session.clear();
parent = session.load(Entity.class, parent.getId());
assertThat(parent).isNotNull();
assertThat(parent.getChildren()).hasSize(2);
assertThat(parent.getParent()).isNull();
List<String> childNames = new ArrayList<>();
for (Entity child : parent.getChildren()) {
childNames.add(child.getName());
assertThat(child.getParent().getName()).isEqualTo(parent.getName());
}
assertThat(childNames.contains(child01.getName())).isTrue();
assertThat(childNames.contains(child02.getName())).isTrue();
}
use of org.neo4j.ogm.domain.tree.Entity in project neo4j-ogm by neo4j.
the class TreeIntegrationTest method shouldLoadTreeProperly.
// DATAGRAPH-731
@Test
public void shouldLoadTreeProperly() {
String cypher = "CREATE (parent:Entity {name:'parent'}) CREATE (child1:Entity {name:'c1'}) CREATE (child2:Entity {name:'c2'}) CREATE (child1)-[:REL]->(parent) CREATE (child2)-[:REL]->(parent)";
session.query(cypher, Collections.emptyMap());
session.clear();
Entity parent = session.loadAll(Entity.class, new Filter("name", ComparisonOperator.EQUALS, "parent")).iterator().next();
assertThat(parent).isNotNull();
assertThat(parent.getChildren()).hasSize(2);
assertThat(parent.getParent()).isNull();
List<String> childNames = new ArrayList<>();
for (Entity child : parent.getChildren()) {
childNames.add(child.getName());
assertThat(child.getParent().getName()).isEqualTo(parent.getName());
}
assertThat(childNames.contains("c1")).isTrue();
assertThat(childNames.contains("c2")).isTrue();
}