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