use of org.neo4j.ogm.domain.forum.Topic in project neo4j-ogm by neo4j.
the class EntityGraphMapperTest method shouldProduceCypherForUpdatingExistingRichRelationshipBetweenNodes.
@Test
public void shouldProduceCypherForUpdatingExistingRichRelationshipBetweenNodes() {
Iterable<Map<String, Object>> executionResult = session.query("CREATE (f:Forum {name:'Spring Data Neo4j'})-[r:HAS_TOPIC {timestamp:20000}]->(t:Topic {inActive:false}) " + "RETURN id(f) AS forumId, id(t) AS topicId, id(r) AS relId", emptyMap()).queryResults();
Map<String, Object> rs = executionResult.iterator().next();
Long forumId = (Long) rs.get("forumId");
Long topicId = (Long) rs.get("topicId");
Long relationshipId = (Long) rs.get("relId");
session.clear();
Forum forum = session.load(Forum.class, forumId);
Topic topic = session.load(Topic.class, topicId);
ForumTopicLink link = session.load(ForumTopicLink.class, relationshipId);
link.setTimestamp(327790L);
forum.setTopicsInForum(Arrays.asList(link));
session.save(forum);
session.clear();
assertThat(session.query("MATCH (f:Forum {name:'Spring Data Neo4j'})-[r:HAS_TOPIC {timestamp:327790}]->(t:Topic {inActive:false}) " + "return f", emptyMap()).queryResults()).hasSize(1);
}
use of org.neo4j.ogm.domain.forum.Topic in project neo4j-ogm by neo4j.
the class CompilerTest method shouldDeleteExistingRelationshipEntity.
@Test
public void shouldDeleteExistingRelationshipEntity() {
Long forumId = 0L;
Long topicId = 1L;
Long linkId = 2L;
Forum forum = new Forum();
forum.setId(forumId);
forum.setName("Spring Data Neo4j");
Topic topic = new Topic();
topic.setTopicId(topicId);
topic.setInActive(Boolean.FALSE);
ForumTopicLink link = new ForumTopicLink();
link.setId(linkId);
link.setForum(forum);
link.setTopic(topic);
forum.setTopicsInForum(Arrays.asList(link));
mappingContext.addNodeEntity(forum);
mappingContext.addNodeEntity(topic);
mappingContext.addRelationshipEntity(link, linkId);
// the mapping context remembers the relationship between the forum and the topic in the graph
mappingContext.addRelationship(new MappedRelationship(forumId, "HAS_TOPIC", topicId, null, Forum.class, ForumTopicLink.class));
// unlink the objects manually
forum.setTopicsInForum(null);
link.setTopic(null);
// expect the delete to be recognised when the forum is saved
Compiler compiler = mapAndCompile(forum, -1);
List<Statement> statements = compiler.createRelationshipsStatements();
assertThat(statements).isEmpty();
statements = compiler.deleteRelationshipStatements();
assertThat(statements).extracting(Statement::getStatement).containsOnly("UNWIND $rows as row MATCH (startNode) WHERE ID(startNode) = row.startNodeId WITH row,startNode MATCH (endNode) WHERE ID(endNode) = row.endNodeId MATCH (startNode)-[rel:`HAS_TOPIC`]->(endNode) DELETE rel");
assertThat(((List) statements.get(0).getParameters().get("rows"))).hasSize(1);
// expect the delete to be recognised if the RE is saved
// expectOnSave(link, "MATCH ($0)-[_0:HAS_TOPIC]->($1) WHERE id($0)=0 AND id($1)=1 DELETE _0");
//
// // expect nothing to happen if the topic is saved, because the domain model does not
// // permit navigation from the topic to the RE (topic has no reference to it)
// expectOnSave(topic, "");
// todo: more tests re saving deletes from REs marked as incoming relationships
}
use of org.neo4j.ogm.domain.forum.Topic in project neo4j-ogm by neo4j.
the class EntityAccessManagerTest method shouldRetrieveAppropriateObjectAccessToEndNodeAttributeOnRelationshipEntity.
@Test
public void shouldRetrieveAppropriateObjectAccessToEndNodeAttributeOnRelationshipEntity() {
ClassInfo relationshipEntityClassInfo = domainInfo.getClass(ForumTopicLink.class.getName());
FieldInfo endNodeReader = relationshipEntityClassInfo.getEndNodeReader();
assertThat(endNodeReader).as("The resultant end node reader shouldn't be null").isNotNull();
ForumTopicLink forumTopicLink = new ForumTopicLink();
Topic topic = new Topic();
forumTopicLink.setTopic(topic);
assertThat(endNodeReader.read(forumTopicLink)).as("The value wasn't read correctly").isSameAs(topic);
}
use of org.neo4j.ogm.domain.forum.Topic in project neo4j-ogm by neo4j.
the class EntityAccessManagerTest method shouldPreferFieldBasedOnRelationshipTypeToPlainSetterWithMatchingParameterType.
@Test
public void shouldPreferFieldBasedOnRelationshipTypeToPlainSetterWithMatchingParameterType() {
// 4th, try to find a "XYZ" field name where XYZ is derived from the relationship type
ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
Topic favouriteTopic = new Topic();
// NB: the setter is called setTopic here, so a relationship type of just "TOPIC" would choose the setter
FieldInfo objectAccess = EntityAccessManager.getRelationalWriter(classInfo, "FAVOURITE_TOPIC", Relationship.Direction.OUTGOING, favouriteTopic);
assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
DummyDomainObject domainObject = new DummyDomainObject();
objectAccess.write(domainObject, favouriteTopic);
assertThat(favouriteTopic).isEqualTo(domainObject.favouriteTopic);
assertThat(domainObject.topicAccessorWasCalled).as("The access should be via the field").isFalse();
}
use of org.neo4j.ogm.domain.forum.Topic 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();
}
}
Aggregations