Search in sources :

Example 1 with Post

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

the class EntityAccessManagerTest method shouldDefaultToFieldThatMatchesTheParameterTypeIfRelationshipTypeCannotBeMatchedAndNoSetterExists.

@Test
public void shouldDefaultToFieldThatMatchesTheParameterTypeIfRelationshipTypeCannotBeMatchedAndNoSetterExists() {
    // 6th, try to find a field that shares the same type as the parameter
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    Post forumPost = new Post();
    FieldInfo objectAccess = EntityAccessManager.getRelationalWriter(classInfo, "UTTER_RUBBISH", Relationship.Direction.OUTGOING, forumPost);
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    DummyDomainObject domainObject = new DummyDomainObject();
    objectAccess.write(domainObject, forumPost);
    assertThat(forumPost).isEqualTo(domainObject.postWithoutAccessorMethods);
}
Also used : Post(org.neo4j.ogm.domain.forum.activity.Post) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 2 with Post

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

the class EntityAccessManagerTest method shouldReadFromFieldMatchingRelationshipTypeInObjectWithoutAnnotationsOrAccessorMethods.

@Test
public void shouldReadFromFieldMatchingRelationshipTypeInObjectWithoutAnnotationsOrAccessorMethods() {
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    DummyDomainObject domainObject = new DummyDomainObject();
    domainObject.postWithoutAccessorMethods = new Post();
    FieldInfo reader = EntityAccessManager.getRelationalReader(classInfo, "POST_WITHOUT_ACCESSOR_METHODS", Relationship.Direction.OUTGOING);
    assertThat(reader).as("The resultant object accessor shouldn't be null").isNotNull();
    assertThat(reader.read(domainObject)).isSameAs(domainObject.postWithoutAccessorMethods);
    assertThat(reader.relationshipType()).isEqualTo("POST_WITHOUT_ACCESSOR_METHODS");
}
Also used : Post(org.neo4j.ogm.domain.forum.activity.Post) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 3 with Post

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

the class EntityAccessManagerTest method shouldRetrieveAppropriateObjectAccessToAllRelationalAttributesForParticularClass.

@Test
public void shouldRetrieveAppropriateObjectAccessToAllRelationalAttributesForParticularClass() {
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    DummyDomainObject domainObject = new DummyDomainObject();
    domainObject.postWithoutAccessorMethods = new Post();
    domainObject.favouriteTopic = new Topic();
    domainObject.member = new Member();
    domainObject.readOnlyComment = new Comment();
    domainObject.registeredMember = new Member();
    domainObject.naturalSatellites = new ArrayList<>();
    domainObject.artificialSatellites = Collections.singletonList(new Satellite());
    Collection<FieldInfo> relationalAccessors = classInfo.relationshipFields();
    assertThat(relationalAccessors).as("The resultant list of object accessors shouldn't be null").isNotNull();
    assertThat(relationalAccessors).as("An unexpected number of accessors was returned").hasSize(7);
    Map<String, Class<? extends FieldInfo>> expectedRelationalReaders = new HashMap<>();
    expectedRelationalReaders.put("COMMENT", FieldInfo.class);
    expectedRelationalReaders.put("FAVOURITE_TOPIC", FieldInfo.class);
    expectedRelationalReaders.put("CONTAINS", FieldInfo.class);
    expectedRelationalReaders.put("POST_WITHOUT_ACCESSOR_METHODS", FieldInfo.class);
    expectedRelationalReaders.put("NATURAL", FieldInfo.class);
    expectedRelationalReaders.put("ARTIFICIAL", FieldInfo.class);
    expectedRelationalReaders.put("REGISTERED", FieldInfo.class);
    for (FieldInfo objectAccess : relationalAccessors) {
        String relType = objectAccess.relationshipType();
        assertThat(expectedRelationalReaders.containsKey(relType)).as("Relationship type " + relType + " wasn't expected").isTrue();
        assertThat(objectAccess.getClass()).isEqualTo(expectedRelationalReaders.get(relType));
        assertThat(objectAccess.read(domainObject)).isNotNull();
    }
}
Also used : Comment(org.neo4j.ogm.domain.forum.activity.Comment) HashMap(java.util.HashMap) Post(org.neo4j.ogm.domain.forum.activity.Post) Satellite(org.neo4j.ogm.domain.satellites.Satellite) Topic(org.neo4j.ogm.domain.forum.Topic) Member(org.neo4j.ogm.domain.forum.Member) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 4 with Post

use of org.neo4j.ogm.domain.forum.activity.Post 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

Test (org.junit.Test)4 Post (org.neo4j.ogm.domain.forum.activity.Post)4 ClassInfo (org.neo4j.ogm.metadata.ClassInfo)3 FieldInfo (org.neo4j.ogm.metadata.FieldInfo)3 Member (org.neo4j.ogm.domain.forum.Member)2 Comment (org.neo4j.ogm.domain.forum.activity.Comment)2 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)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