use of org.neo4j.ogm.domain.election.Candidate in project neo4j-ogm by neo4j.
the class RelationshipMappingTest method shouldNotDropUnmappedRelationshipModels.
// GH-727
@Test
public void shouldNotDropUnmappedRelationshipModels() {
Session session = sessionFactory.openSession();
Voter voter = new Voter("V");
voter.candidateVotedFor = new Candidate("C");
session.save(voter);
session = sessionFactory.openSession();
Iterable<Map<String, Object>> results = session.query("MATCH (v) - [r] - (c) WHERE id(v) = $id RETURN r", Collections.singletonMap("id", voter.getId())).queryResults();
assertThat(results).hasSize(1);
Map<String, Object> row = results.iterator().next();
assertThat(row).containsKeys("r");
assertThat(row.get("r")).isNotNull().isInstanceOf(RelationshipModel.class);
}
use of org.neo4j.ogm.domain.election.Candidate in project neo4j-ogm by neo4j.
the class RelationshipMappingTest method shouldAllowVoterToChangeHerMind.
@Test
public void shouldAllowVoterToChangeHerMind() {
Iterable<Map<String, Object>> executionResult = session.query("CREATE " + "(a:Voter:Candidate {name:'A'}), " + "(b:Voter:Candidate {name:'B'}), " + "(v:Voter {name:'V'})-[:CANDIDATE_VOTED_FOR]->(b) " + "RETURN id(a) AS a_id, id(b) AS b_id, id(v) AS v_id", emptyMap()).queryResults();
Map<String, ?> results = executionResult.iterator().next();
Long aid = (Long) results.get("a_id");
Long bid = (Long) results.get("b_id");
Long vid = (Long) results.get("v_id");
session.clear();
Candidate a = session.load(Candidate.class, aid);
Candidate b = session.load(Candidate.class, bid);
Voter v = session.load(Voter.class, vid);
v.candidateVotedFor = a;
session.save(v);
session.clear();
assertThat(session.query("MATCH (a:Voter:Candidate {name:'A'}), " + "(b:Voter:Candidate {name:'B'}), " + "(v:Voter {name:'V'})-[:CANDIDATE_VOTED_FOR]->(a) return a, b, v", emptyMap()).queryResults()).hasSize(1);
}
use of org.neo4j.ogm.domain.election.Candidate in project neo4j-ogm by neo4j.
the class ElectionTest method shouldAllowVoterToChangeHerMind.
@Test
public void shouldAllowVoterToChangeHerMind() {
Candidate a = new Candidate("A");
Candidate b = new Candidate("B");
Voter v = new Voter("V");
v.candidateVotedFor = b;
session.save(a);
session.save(v);
MappingContext context = ((Neo4jSession) session).context();
assertThat(context.containsRelationship(new MappedRelationship(v.getId(), "CANDIDATE_VOTED_FOR", b.getId(), null, Voter.class, Candidate.class))).isTrue();
session.clear();
a = session.load(Candidate.class, a.getId());
v = session.load(Voter.class, v.getId());
assertThat(v.candidateVotedFor.getId()).isEqualTo(b.getId());
assertThat(context.containsRelationship(new MappedRelationship(v.getId(), "CANDIDATE_VOTED_FOR", b.getId(), null, Voter.class, Candidate.class))).isTrue();
v.candidateVotedFor = a;
session.save(v);
session.clear();
session.load(Candidate.class, b.getId());
session.load(Voter.class, v.getId());
assertThat(v.candidateVotedFor.getId()).isEqualTo(a.getId());
assertThat(context.containsRelationship(new MappedRelationship(v.getId(), "CANDIDATE_VOTED_FOR", a.getId(), null, Voter.class, Candidate.class))).isTrue();
assertThat(context.containsRelationship(new MappedRelationship(v.getId(), "CANDIDATE_VOTED_FOR", b.getId(), null, Voter.class, Candidate.class))).isFalse();
session.clear();
}
use of org.neo4j.ogm.domain.election.Candidate in project neo4j-ogm by neo4j.
the class ElectionTest method shouldAllowASelfReferenceToBeSavedFromTheReferredSide.
@Test
public void shouldAllowASelfReferenceToBeSavedFromTheReferredSide() {
Candidate candidate = new Candidate("Hilary Clinton");
candidate.candidateVotedFor = candidate;
session.save(candidate.candidateVotedFor);
session.clear();
Long voterId = candidate.candidateVotedFor.getId();
Voter voter = session.load(Voter.class, voterId);
assertThat(voter.getId()).isNotNull();
assertThat(voter.candidateVotedFor.getId()).isNotNull();
assertThat(voter.candidateVotedFor.getId()).isEqualTo(voter.getId());
}
use of org.neo4j.ogm.domain.election.Candidate in project neo4j-ogm by neo4j.
the class ElectionTest method shouldAllowACandidateToVoteForHerself.
@Test
public void shouldAllowACandidateToVoteForHerself() {
Candidate candidate = new Candidate("Hilary Clinton");
candidate.candidateVotedFor = candidate;
session.save(candidate);
assertThat(candidate.getId()).isNotNull();
assertThat(candidate.candidateVotedFor.getId()).isNotNull();
assertThat(candidate.candidateVotedFor.getId()).isEqualTo(candidate.getId());
session.clear();
Long voterId = candidate.getId();
Voter voter = session.load(Voter.class, voterId);
assertThat(voter.getId()).isNotNull();
assertThat(voter.candidateVotedFor.getId()).isNotNull();
assertThat(voter.candidateVotedFor.getId()).isEqualTo(voter.getId());
}
Aggregations