Search in sources :

Example 1 with Activity

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

the class HierarchyRelsTest method shouldLoadRelationByAbstractParent.

// GH-404
@Test
public void shouldLoadRelationByAbstractParent() {
    Post post = new Post();
    post.setPost("sample post");
    Activity comment = new Comment();
    Date now = new Date();
    comment.setDate(now);
    Member member = new Member();
    member.setUserName("sample member");
    member.setActivityList(Arrays.asList(post, comment));
    session.save(member);
    session.clear();
    Member reloaded = session.load(Member.class, member.getId());
    assertThat(reloaded).isNotNull();
    assertThat(reloaded.getUserName()).isEqualTo("sample member");
    assertThat(reloaded.getActivityList()).hasSize(2);
    Post p = (Post) StreamSupport.stream(reloaded.getActivityList().spliterator(), false).filter(elt -> elt.getClass().equals(Post.class)).findFirst().get();
    assertThat(p.getPost()).isEqualTo("sample post");
    Comment c = (Comment) StreamSupport.stream(reloaded.getActivityList().spliterator(), false).filter(elt -> elt.getClass().equals(Comment.class)).findFirst().get();
    assertThat(c.getDate()).isEqualTo(now);
}
Also used : Comment(org.neo4j.ogm.domain.forum.activity.Comment) Arrays(java.util.Arrays) IElementImpl1(org.neo4j.ogm.domain.gh806.IElementImpl1) Date(java.util.Date) Type1(org.neo4j.ogm.domain.hierarchy.relations.Type1) Function(java.util.function.Function) Type2(org.neo4j.ogm.domain.hierarchy.relations.Type2) Type3(org.neo4j.ogm.domain.hierarchy.relations.Type3) HashSet(java.util.HashSet) Map(java.util.Map) After(org.junit.After) BiConsumer(java.util.function.BiConsumer) Assertions(org.assertj.core.api.Assertions) VeryConcreteElementA(org.neo4j.ogm.domain.gh806.VeryConcreteElementA) Transaction(org.neo4j.ogm.transaction.Transaction) StreamSupport(java.util.stream.StreamSupport) EvenMoreConcreteElement(org.neo4j.ogm.domain.gh806.EvenMoreConcreteElement) Result(org.neo4j.ogm.model.Result) Before(org.junit.Before) Session(org.neo4j.ogm.session.Session) Member(org.neo4j.ogm.domain.forum.Member) BaseEntity(org.neo4j.ogm.domain.hierarchy.relations.BaseEntity) Container(org.neo4j.ogm.domain.gh806.Container) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) IElementImpl1A(org.neo4j.ogm.domain.gh806.IElementImpl1A) List(java.util.List) Element(org.neo4j.ogm.domain.gh806.Element) Post(org.neo4j.ogm.domain.forum.activity.Post) SessionFactory(org.neo4j.ogm.session.SessionFactory) TestContainersTestBase(org.neo4j.ogm.testutil.TestContainersTestBase) Collections(java.util.Collections) ConcreteElement(org.neo4j.ogm.domain.gh806.ConcreteElement) Activity(org.neo4j.ogm.domain.forum.activity.Activity) Comment(org.neo4j.ogm.domain.forum.activity.Comment) Post(org.neo4j.ogm.domain.forum.activity.Post) Activity(org.neo4j.ogm.domain.forum.activity.Activity) Member(org.neo4j.ogm.domain.forum.Member) Date(java.util.Date) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 BiConsumer (java.util.function.BiConsumer)1 Function (java.util.function.Function)1 StreamSupport (java.util.stream.StreamSupport)1 Assertions (org.assertj.core.api.Assertions)1 After (org.junit.After)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Member (org.neo4j.ogm.domain.forum.Member)1 Activity (org.neo4j.ogm.domain.forum.activity.Activity)1 Comment (org.neo4j.ogm.domain.forum.activity.Comment)1 Post (org.neo4j.ogm.domain.forum.activity.Post)1 ConcreteElement (org.neo4j.ogm.domain.gh806.ConcreteElement)1