Search in sources :

Example 1 with RefField

use of org.neo4j.ogm.domain.gh609.RefField in project neo4j-ogm by neo4j.

the class CyclicStructureTest method testCyclicStructure.

/**
 * This issue was introduced by #407
 *
 * @see org.neo4j.ogm.persistence.examples.social.SocialIntegrationTest#shouldSaveObjectsToCorrectDepth
 * @see org.neo4j.ogm.persistence.examples.social.SocialIntegrationTest#shouldSaveAllDirectedRelationships
 */
// GH-609
@Test
public void testCyclicStructure() throws Exception {
    long numberOfNodes = 10;
    long numberOfRefFields = 100;
    List<CyclicNodeType> nodes = new ArrayList<>();
    for (long i = 0; i < numberOfNodes; ++i) {
        nodes.add(new CyclicNodeType());
    }
    List<RefField> refFields = new ArrayList<>();
    for (long i = 0; i < numberOfRefFields; i++) {
        RefField field = new RefField().setNodeTypes(nodes);
        refFields.add(field);
    }
    for (CyclicNodeType nodeType : nodes) {
        nodeType.setSubordinateNodeTypes(nodes);
        nodeType.setRefFields(refFields);
    }
    Session session = sessionFactory.openSession();
    // Make sure the number of builders fits the number of expected relationships
    MultiStatementCypherCompiler compiler = (MultiStatementCypherCompiler) mapAndCompile((Neo4jSession) session, nodes.get(0), -1);
    List<RelationshipBuilder> newRelationshipBuilders = extractRelationshipBuilder(compiler);
    assertThat(newRelationshipBuilders).size().isEqualTo(numberOfNodes * numberOfNodes + (numberOfNodes * numberOfRefFields * 2));
    // Make sure the session saves all relationships accordingly
    Transaction transaction = session.beginTransaction();
    session.save(nodes.get(0), -1);
    session.clear();
    transaction.commit();
    session = sessionFactory.openSession();
    Result result = session.query("" + " MATCH (c1:CyclicNodeType) - [s:SUBORDINATE] - (c2:CyclicNodeType)," + "       (c1) - [f:HAS_FIELD] -> (r:RefField)" + " RETURN count(distinct c1) as numberOfNodes, count(distinct s) as countRelCyc, " + "        count(distinct r)  as numberOfRefFields, count(distinct f) as countRelHasField", Collections.emptyMap());
    assertThat(result).hasSize(1);
    result.queryResults().forEach(record -> {
        assertThat(record.get("numberOfNodes")).isEqualTo(numberOfNodes);
        assertThat(record.get("numberOfRefFields")).isEqualTo(numberOfRefFields);
        assertThat(record.get("countRelCyc")).isEqualTo(numberOfNodes * numberOfNodes);
        assertThat(record.get("countRelHasField")).isEqualTo(numberOfNodes * numberOfRefFields);
    });
}
Also used : ArrayList(java.util.ArrayList) RefField(org.neo4j.ogm.domain.gh609.RefField) Result(org.neo4j.ogm.model.Result) Transaction(org.neo4j.ogm.transaction.Transaction) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) CyclicNodeType(org.neo4j.ogm.domain.gh609.CyclicNodeType) Session(org.neo4j.ogm.session.Session) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 CyclicNodeType (org.neo4j.ogm.domain.gh609.CyclicNodeType)1 RefField (org.neo4j.ogm.domain.gh609.RefField)1 Result (org.neo4j.ogm.model.Result)1 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)1 Session (org.neo4j.ogm.session.Session)1 Transaction (org.neo4j.ogm.transaction.Transaction)1