Search in sources :

Example 6 with ForumTopicLink

use of org.neo4j.ogm.domain.forum.ForumTopicLink in project neo4j-ogm by neo4j.

the class CompilerTest method shouldUpdatingExistingRelationshipEntity.

@Test
public void shouldUpdatingExistingRelationshipEntity() {
    Long forumId = 0L;
    Long topicId = 1L;
    Long relationshipId = 2L;
    Forum forum = new Forum();
    forum.setId(forumId);
    forum.setName("Spring Data Neo4j");
    Topic topic = new Topic();
    topic.setTopicId(topicId);
    topic.setInActive(Boolean.FALSE);
    ForumTopicLink link = new ForumTopicLink();
    link.setId(relationshipId);
    link.setForum(forum);
    link.setTopic(topic);
    forum.setTopicsInForum(Arrays.asList(link));
    mappingContext.addNodeEntity(forum);
    mappingContext.addNodeEntity(topic);
    mappingContext.addRelationshipEntity(link, relationshipId);
    MappedRelationship mappedRelationship = new MappedRelationship(forumId, "HAS_TOPIC", topicId, relationshipId, Forum.class, ForumTopicLink.class);
    mappingContext.addRelationship(mappedRelationship);
    // change the timestamp
    link.setTimestamp(327790L);
    // expect the property on the relationship entity to be updated on the graph relationship
    Compiler compiler = mapAndCompile(link, -1);
    List<Statement> statements = compiler.createNodesStatements();
    assertThat(statements).isEmpty();
    statements = compiler.updateRelationshipStatements();
    assertThat(statements).extracting(Statement::getStatement).containsOnly("UNWIND $rows AS row MATCH ()-[r]->() WHERE ID(r) = row.relId SET r += row.props RETURN ID(r) as ref, ID(r) as id, $type as type");
    assertThat((List) statements.get(0).getParameters().get("rows")).hasSize(1);
}
Also used : Statement(org.neo4j.ogm.request.Statement) MappedRelationship(org.neo4j.ogm.context.MappedRelationship) ForumTopicLink(org.neo4j.ogm.domain.forum.ForumTopicLink) ArrayList(java.util.ArrayList) List(java.util.List) Topic(org.neo4j.ogm.domain.forum.Topic) Forum(org.neo4j.ogm.domain.forum.Forum) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 ForumTopicLink (org.neo4j.ogm.domain.forum.ForumTopicLink)6 Topic (org.neo4j.ogm.domain.forum.Topic)6 Forum (org.neo4j.ogm.domain.forum.Forum)5 Statement (org.neo4j.ogm.request.Statement)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MappedRelationship (org.neo4j.ogm.context.MappedRelationship)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ClassInfo (org.neo4j.ogm.metadata.ClassInfo)1 FieldInfo (org.neo4j.ogm.metadata.FieldInfo)1