public void testCreateUniqueRelationshipRelatedToVia() {
final Person p1 = storeInGraph(michael);
final Person p2 = storeInGraph(andres);
p1.setBestFriend(p2,"cypher");
template.save(p1);
final BestFriend bestFriend = p1.getBestFriend();
final Relationship bestFriendRel = template.getPersistentState(bestFriend);
assertEquals(bestFriendRel,((Node)template.getPersistentState(michael)).getSingleRelationship(DynamicRelationshipType.withName("BEST_FRIEND"), Direction.OUTGOING));
assertEquals(bestFriendRel.getEndNode(), template.getPersistentState(andres));
assertEquals("cypher",bestFriendRel.getProperty("secretName"));
assertEquals(bestFriendRel, getBestFriend());
final Person p3 = storeInGraph(emil);
p1.setBestFriend(p3,"cypher");
final BestFriend bestFriend2 = p1.getBestFriend();
template.save(bestFriend2);
final Relationship bestFriend2Rel = template.getPersistentState(bestFriend2);
assertEquals(bestFriend2Rel, bestFriendRel);
assertEquals(bestFriend2Rel.getEndNode(), template.getPersistentState(andres));
assertEquals(bestFriendRel, getBestFriend());
p1.setBestFriend(null,null);
template.save(p1);
assertEquals(null, ((Node) template.getPersistentState(michael)).getSingleRelationship(DynamicRelationshipType.withName("BEST_FRIEND"), Direction.OUTGOING));
p1.setBestFriend(p3, "cypher");
template.save(p1);
final BestFriend bestFriend3 = p1.getBestFriend();
final Relationship bestFriend3Rel = template.getPersistentState(bestFriend3);
assertNotSame(bestFriend3Rel, bestFriendRel);
assertEquals(bestFriend3Rel.getEndNode(), template.getPersistentState(emil));
assertEquals(bestFriend3Rel, getBestFriend());