Search in sources :

Example 1 with Mortal

use of org.neo4j.ogm.domain.social.Mortal in project neo4j-ogm by neo4j.

the class SocialIntegrationTest method shouldSaveIncomingKnownMortals.

/**
 * @see DATAGRAPH-594
 */
@Test
public void shouldSaveIncomingKnownMortals() {
    Mortal mortalA = new Mortal("A");
    Mortal mortalB = new Mortal("B");
    Mortal mortalC = new Mortal("C");
    Mortal mortalD = new Mortal("D");
    mortalA.getKnownBy().add(mortalB);
    mortalA.getKnownBy().add(mortalC);
    mortalD.getKnownBy().add(mortalA);
    session.save(mortalA);
    session.save(mortalB);
    session.save(mortalC);
    session.save(mortalD);
    session.clear();
    mortalA = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "A")).iterator().next();
    assertThat(mortalA).isNotNull();
    assertThat(mortalA.getKnownBy()).hasSize(2);
    mortalB = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "B")).iterator().next();
    assertThat(mortalB).isNotNull();
    assertThat(mortalB.getKnownBy()).isEmpty();
    mortalC = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "C")).iterator().next();
    assertThat(mortalC).isNotNull();
    assertThat(mortalC.getKnownBy()).isEmpty();
    mortalD = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "D")).iterator().next();
    assertThat(mortalD).isNotNull();
    assertThat(mortalD.getKnownBy()).hasSize(1);
    assertThat(mortalD.getKnownBy().iterator().next().getName()).isEqualTo("A");
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Mortal(org.neo4j.ogm.domain.social.Mortal) Test(org.junit.Test)

Example 2 with Mortal

use of org.neo4j.ogm.domain.social.Mortal in project neo4j-ogm by neo4j.

the class SocialRelationshipsIntegrationTest method saveIncomingSavesIncomingRelationship.

// DATAGRAPH-594
@Test
public void saveIncomingSavesIncomingRelationship() {
    Mortal mortalA = new Mortal("A");
    Mortal mortalB = new Mortal("B");
    mortalA.getKnownBy().add(mortalB);
    session.save(mortalA);
    session.clear();
    assertThat(session.query("MATCH (a:Mortal {name:'A'}), (b:Mortal {name:'B'}) WHERE (a)<-[:KNOWN_BY]-(b) " + "return a,b", emptyMap()).queryResults()).hasSize(1);
}
Also used : Mortal(org.neo4j.ogm.domain.social.Mortal) Test(org.junit.Test)

Example 3 with Mortal

use of org.neo4j.ogm.domain.social.Mortal in project neo4j-ogm by neo4j.

the class CompilerTest method createIncomingRelationWhenSpecified.

// DATAGRAPH-594
@Test
public void createIncomingRelationWhenSpecified() {
    Mortal adam = new Mortal("Adam");
    Mortal vince = new Mortal("Vince");
    adam.getKnownBy().add(vince);
    Compiler compiler = mapAndCompile(adam, -1);
    List<Statement> statements = compiler.createNodesStatements();
    assertThat(statements).extracting(Statement::getStatement).containsOnly("UNWIND $rows as row CREATE (n:`Mortal`) SET n=row.props RETURN row.nodeRef as ref, ID(n) as id, $type as type");
    for (Statement statement : statements) {
        List rows = (List) statement.getParameters().get("rows");
        assertThat(rows).hasSize(2);
    }
    statements = compiler.createRelationshipsStatements();
    assertThat(statements).extracting(Statement::getStatement).containsOnly("UNWIND $rows as row MATCH (startNode) WHERE ID(startNode) = row.startNodeId WITH row,startNode MATCH (endNode) WHERE ID(endNode) = row.endNodeId MERGE (startNode)-[rel:`KNOWN_BY`]->(endNode) RETURN row.relRef as ref, ID(rel) as id, $type as type");
    List rows = (List) statements.get(0).getParameters().get("rows");
    assertThat(rows).hasSize(1);
    Map row = (Map) rows.get(0);
    assertThat(row.get("startNodeId")).isEqualTo(mappingContext.nativeId(vince));
    assertThat(row.get("endNodeId")).isEqualTo(mappingContext.nativeId(adam));
}
Also used : Statement(org.neo4j.ogm.request.Statement) Mortal(org.neo4j.ogm.domain.social.Mortal) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 4 with Mortal

use of org.neo4j.ogm.domain.social.Mortal in project neo4j-ogm by neo4j.

the class SocialIntegrationTest method shouldFetchIncomingKnownMortals.

/**
 * @see DATAGRAPH-594
 */
@Test
public void shouldFetchIncomingKnownMortals() {
    session.query("create (m1:Mortal {name:'A'}) create (m2:Mortal {name:'B'}) create (m3:Mortal {name:'C'})" + " create (m4:Mortal {name:'D'}) create (m1)<-[:KNOWN_BY]-(m2) create (m1)<-[:KNOWN_BY]-(m3) create (m4)<-[:KNOWN_BY]-(m1)", Collections.EMPTY_MAP);
    Mortal mortalA = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "A")).iterator().next();
    assertThat(mortalA).isNotNull();
    assertThat(mortalA.getKnownBy()).hasSize(2);
    Mortal mortalB = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "B")).iterator().next();
    assertThat(mortalB).isNotNull();
    assertThat(mortalB.getKnownBy()).isEmpty();
    Mortal mortalC = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "C")).iterator().next();
    assertThat(mortalC).isNotNull();
    assertThat(mortalC.getKnownBy()).isEmpty();
    Mortal mortalD = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "D")).iterator().next();
    assertThat(mortalD).isNotNull();
    assertThat(mortalD.getKnownBy()).hasSize(1);
    assertThat(mortalD.getKnownBy().iterator().next().getName()).isEqualTo("A");
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Mortal(org.neo4j.ogm.domain.social.Mortal) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 Mortal (org.neo4j.ogm.domain.social.Mortal)4 Filter (org.neo4j.ogm.cypher.Filter)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Statement (org.neo4j.ogm.request.Statement)1