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);
});
}
Aggregations