use of org.neo4j.ogm.domain.social.User in project neo4j-ogm by neo4j.
the class SocialIntegrationTest method shouldFetchFriendsUndirected.
@Test
public void shouldFetchFriendsUndirected() {
User adam = new User("Adam");
User daniela = new User("Daniela");
User michal = new User("Michal");
User vince = new User("Vince");
adam.befriend(daniela);
daniela.befriend(michal);
michal.befriend(vince);
session.save(adam);
session.clear();
adam = session.load(User.class, adam.getId());
assertThat(adam.getFriends()).hasSize(1);
daniela = session.load(User.class, daniela.getId());
assertThat(daniela.getFriends()).hasSize(2);
List<String> friendNames = new ArrayList<>();
for (User friend : daniela.getFriends()) {
friendNames.add(friend.getName());
}
assertThat(friendNames.contains("Adam")).isTrue();
assertThat(friendNames.contains("Michal")).isTrue();
session.clear();
michal = session.load(User.class, michal.getId());
assertThat(michal.getFriends()).hasSize(2);
session.clear();
vince = session.load(User.class, vince.getId());
assertThat(vince.getFriends()).hasSize(1);
}
use of org.neo4j.ogm.domain.social.User in project neo4j-ogm by neo4j.
the class SocialIntegrationTest method shouldFetchFriendsForUndirectedRelationship.
/**
* @see DATAGRAPH-594
*/
@Test
public void shouldFetchFriendsForUndirectedRelationship() {
session.query("create (p1:User {name:'A'}) create (p2:User {name:'B'}) create (p3:User {name:'C'})" + " create (p4:User {name:'D'}) create (p1)-[:FRIEND]->(p2) create (p1)-[:FRIEND]->(p3) create (p4)-[:FRIEND]->(p1)", Collections.EMPTY_MAP);
User userA = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "A")).iterator().next();
assertThat(userA).isNotNull();
assertThat(userA.getFriends()).hasSize(3);
User userB = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "B")).iterator().next();
assertThat(userB).isNotNull();
assertThat(userB.getFriends()).hasSize(1);
assertThat(userB.getFriends().get(0)).isEqualTo(userA);
User userD = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "D")).iterator().next();
assertThat(userD).isNotNull();
assertThat(userD.getFriends()).hasSize(1);
assertThat(userD.getFriends().get(0)).isEqualTo(userA);
}
use of org.neo4j.ogm.domain.social.User in project neo4j-ogm by neo4j.
the class SocialIntegrationTest method shouldSaveUndirectedFriends.
/**
* @see DATAGRAPH-594
*/
@Test
public void shouldSaveUndirectedFriends() {
User userA = new User("A");
User userB = new User("B");
User userC = new User("C");
User userD = new User("D");
userA.getFriends().add(userB);
userA.getFriends().add(userC);
userD.getFriends().add(userA);
session.save(userA);
session.save(userB);
session.save(userC);
session.save(userD);
session.clear();
userA = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "A")).iterator().next();
assertThat(userA).isNotNull();
assertThat(userA.getFriends()).hasSize(3);
userB = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "B")).iterator().next();
assertThat(userB).isNotNull();
assertThat(userB.getFriends()).hasSize(1);
assertThat(userB.getFriends().get(0).getName()).isEqualTo(userA.getName());
userD = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "D")).iterator().next();
assertThat(userD).isNotNull();
assertThat(userD.getFriends()).hasSize(1);
assertThat(userD.getFriends().get(0).getName()).isEqualTo(userA.getName());
}
use of org.neo4j.ogm.domain.social.User in project neo4j-ogm by neo4j.
the class SocialRelationshipsIntegrationTest method saveUndirectedSavesOutgoingRelationship.
// DATAGRAPH-594
@Test
public void saveUndirectedSavesOutgoingRelationship() {
User userA = new User("A");
User userB = new User("B");
userA.getFriends().add(userB);
session.save(userA);
session.clear();
assertThat(session.query("MATCH (a:User {name:'A'}), (b:User {name:'B'}) WHERE (a)-[:FRIEND]->(b) " + "return a,b", emptyMap()).queryResults()).hasSize(1);
}
use of org.neo4j.ogm.domain.social.User in project neo4j-ogm by neo4j.
the class SocialRelationshipsIntegrationTest method removeUndirectedRelationship.
// GH-112
@Test
public void removeUndirectedRelationship() {
User userA = new User("A");
User userB = new User("B");
userA.getFriends().add(userB);
session.save(userA);
assertThat(session.query("MATCH (a:User {name:'A'}), (b:User {name:'B'}) WHERE (a)-[:FRIEND]->(b) return a,b", emptyMap(), true).queryResults()).hasSize(1);
userA.unfriend(userB);
session.save(userA);
assertThat(session.query("MATCH (a:User {name:'A'}), (b:User {name:'B'}) WHERE (a)-[:FRIEND]->(b) return a, b", emptyMap(), true).queryResults()).hasSize(0);
}
Aggregations