Search in sources :

Example 1 with Member

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

the class EntityAccessManagerTest method shouldPreferAnnotatedFieldToPlainSetterMatchingRelationshipTypeWhenSettingRelationshipObject.

@Test
public void shouldPreferAnnotatedFieldToPlainSetterMatchingRelationshipTypeWhenSettingRelationshipObject() {
    // 2nd, try to find a field annotated with with relationship type
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    Member parameter = new Member();
    FieldInfo objectAccess = EntityAccessManager.getRelationalWriter(classInfo, "CONTAINS", Relationship.Direction.OUTGOING, parameter);
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    DummyDomainObject domainObject = new DummyDomainObject();
    objectAccess.write(domainObject, parameter);
    assertThat(parameter).isEqualTo(domainObject.member);
    Member otherMember = new Member();
    objectAccess = EntityAccessManager.getRelationalWriter(classInfo, "REGISTERED", Relationship.Direction.OUTGOING, otherMember);
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    domainObject = new DummyDomainObject();
    objectAccess.write(domainObject, otherMember);
    assertThat(otherMember).isEqualTo(domainObject.registeredMember);
}
Also used : Member(org.neo4j.ogm.domain.forum.Member) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 2 with Member

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

the class EntityAccessManagerTest method shouldPreferAnnotatedFieldToPlainGetterMethodMatchingRelationshipType.

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

Example 3 with Member

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

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

the class EntityGraphMapperTest method shouldNotWriteReadOnlyProperties.

// GH-786
@Test
public void shouldNotWriteReadOnlyProperties() {
    Member test123 = new Member();
    test123.setUserName("Test123");
    test123.setSomeComputedValue("x");
    session.save(test123);
    Iterable<Member> members = sessionFactory.openSession().query(Member.class, "MATCH (n:User {userName: 'Test123'}) RETURN n", Collections.emptyMap());
    assertThat(members).hasSize(1).first().extracting(Member::getSomeComputedValue).isNull();
}
Also used : Member(org.neo4j.ogm.domain.forum.Member) Test(org.junit.Test)

Example 5 with Member

use of org.neo4j.ogm.domain.forum.Member 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)5 Member (org.neo4j.ogm.domain.forum.Member)5 ClassInfo (org.neo4j.ogm.metadata.ClassInfo)3 FieldInfo (org.neo4j.ogm.metadata.FieldInfo)3 Comment (org.neo4j.ogm.domain.forum.activity.Comment)2 Post (org.neo4j.ogm.domain.forum.activity.Post)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