Search in sources :

Example 1 with Entity

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");
}
Also used : Entity(org.neo4j.ogm.domain.tree.Entity) Filter(org.neo4j.ogm.cypher.Filter) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with Entity

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();
}
Also used : Entity(org.neo4j.ogm.domain.tree.Entity) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with Entity

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();
}
Also used : Entity(org.neo4j.ogm.domain.tree.Entity) Filter(org.neo4j.ogm.cypher.Filter) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Entity (org.neo4j.ogm.domain.tree.Entity)3 Filter (org.neo4j.ogm.cypher.Filter)2