Search in sources :

Example 1 with Person

use of org.neo4j.ogm.domain.social.Person in project neo4j-ogm by neo4j.

the class SocialIntegrationTest method shouldFetchOnlyPeopleILike.

/**
 * @see DATAGRAPH-594
 */
@Test
public void shouldFetchOnlyPeopleILike() {
    session.query("create (p1:Person {name:'A'}) create (p2:Person {name:'B'}) create (p3:Person {name:'C'})" + " create (p4:Person {name:'D'}) create (p1)-[:LIKES]->(p2) create (p1)-[:LIKES]->(p3) create (p4)-[:LIKES]->(p1)", Collections.EMPTY_MAP);
    Person personA = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "A")).iterator().next();
    assertThat(personA).isNotNull();
    assertThat(personA.getPeopleILike()).hasSize(2);
    Person personD = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "D")).iterator().next();
    assertThat(personD).isNotNull();
    assertThat(personD.getPeopleILike()).hasSize(1);
    assertThat(personD.getPeopleILike().get(0)).isEqualTo(personA);
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Person(org.neo4j.ogm.domain.social.Person) Test(org.junit.Test)

Example 2 with Person

use of org.neo4j.ogm.domain.social.Person in project neo4j-ogm by neo4j.

the class SocialIntegrationTest method shouldSaveUndirectedFriendsInBothDirections.

/**
 * @see DATAGRAPH-594
 */
@Test
public void shouldSaveUndirectedFriendsInBothDirections() {
    Person userA = new Person("A");
    Person userB = new Person("B");
    userA.getPeopleILike().add(userB);
    userB.getPeopleILike().add(userA);
    session.save(userA);
    session.clear();
    userA = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "A")).iterator().next();
    assertThat(userA).isNotNull();
    assertThat(userA.getPeopleILike()).hasSize(1);
    session.clear();
    userB = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "B")).iterator().next();
    assertThat(userB).isNotNull();
    assertThat(userB.getPeopleILike()).hasSize(1);
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Person(org.neo4j.ogm.domain.social.Person) Test(org.junit.Test)

Example 3 with Person

use of org.neo4j.ogm.domain.social.Person in project neo4j-ogm by neo4j.

the class SocialIntegrationTest method shouldSaveAllDirectedRelationships.

@Test
public void shouldSaveAllDirectedRelationships() throws Exception {
    Person a = new Person("A");
    Person b = new Person("B");
    Person c = new Person("C");
    Person d = new Person("D");
    Person e = new Person("E");
    a.addPersonILike(b);
    b.addPersonILike(c);
    a.addPersonILike(d);
    d.addPersonILike(e);
    b.addPersonILike(d);
    d.addPersonILike(b);
    session.save(a);
    session.clear();
    Person loadedB = session.load(Person.class, b.getId());
    assertThat(loadedB.getPeopleILike()).hasSize(2);
    Person loadedD = session.load(Person.class, d.getId());
    assertThat(loadedD.getPeopleILike()).hasSize(2);
}
Also used : Person(org.neo4j.ogm.domain.social.Person) Test(org.junit.Test)

Example 4 with Person

use of org.neo4j.ogm.domain.social.Person in project neo4j-ogm by neo4j.

the class SocialRelationshipsIntegrationTest method updateOutgoingRelInListSavesOutgoingRelationshipInBothDirections.

// DATAGRAPH-594
@Test
public void updateOutgoingRelInListSavesOutgoingRelationshipInBothDirections() {
    Person personA = new Person("A");
    Person personB = new Person("B");
    Person personC = new Person("C");
    Person personD = new Person("D");
    personA.getPeopleILike().add(personB);
    personA.getPeopleILike().add(personC);
    personB.getPeopleILike().add(personA);
    personD.getPeopleILike().add(personA);
    session.save(personA);
    session.save(personB);
    session.save(personC);
    session.save(personD);
    session.clear();
    assertThat(session.query("MATCH (a:Person {name:'A'}), (b:Person {name:'B'}), " + "(c:Person {name:'C'}), (d:Person {name:'D'}) " + "WHERE (a)-[:LIKES]->(b) and (a)-[:LIKES]->(c) and (b)-[:LIKES]->(a) and (d)-[:LIKES]->(a) " + "return a, b, c, d", emptyMap()).queryResults()).hasSize(1);
}
Also used : Person(org.neo4j.ogm.domain.social.Person) Test(org.junit.Test)

Example 5 with Person

use of org.neo4j.ogm.domain.social.Person in project neo4j-ogm by neo4j.

the class SocialRelationshipsIntegrationTest method saveOutgoingToExistingNodesSavesOutgoingRelationshipInBothDirections.

// DATAGRAPH-594
@Test
public void saveOutgoingToExistingNodesSavesOutgoingRelationshipInBothDirections() {
    Person personA = new Person("A");
    Person personB = new Person("B");
    session.save(personA);
    session.save(personB);
    personA.getPeopleILike().add(personB);
    personB.getPeopleILike().add(personA);
    session.save(personA);
    session.clear();
    assertThat(session.query("MATCH (a:Person {name:'A'}), (b:Person {name:'B'}) " + "WHERE (a)-[:LIKES]->(b) and (b)-[:LIKES]->(a) return a,b", emptyMap()).queryResults()).hasSize(1);
}
Also used : Person(org.neo4j.ogm.domain.social.Person) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 Person (org.neo4j.ogm.domain.social.Person)11 Filter (org.neo4j.ogm.cypher.Filter)3 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Predicate (java.util.function.Predicate)1 Stream (java.util.stream.Stream)1 Assertions (org.assertj.core.api.Assertions)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 Ignore (org.junit.Ignore)1 WriteProtectionTarget (org.neo4j.ogm.context.WriteProtectionTarget)1 ComparisonOperator (org.neo4j.ogm.cypher.ComparisonOperator)1 Immortal (org.neo4j.ogm.domain.social.Immortal)1 User (org.neo4j.ogm.domain.social.User)1 CypherException (org.neo4j.ogm.exception.CypherException)1 TransactionException (org.neo4j.ogm.exception.TransactionException)1