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