Search in sources :

Example 1 with Person

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

the class FriendshipsRelationshipEntityTest method shouldSaveAndReloadAllSetsAllObjectIdsAndReferencesCorrectly.

@Test
public void shouldSaveAndReloadAllSetsAllObjectIdsAndReferencesCorrectly() {
    Person mike = new Person("Mike");
    Person dave = new Person("Dave");
    dave.getFriends().add(new Friendship(dave, mike, 5));
    session.save(dave);
    Collection<Person> personList = session.loadAll(Person.class);
    int expected = 2;
    assertThat(personList.size()).isEqualTo(expected);
    for (Person person : personList) {
        if (person.getName().equals("Dave")) {
            expected--;
            assertThat(person.getFriends().get(0).getFriend().getName()).isEqualTo("Mike");
        } else if (person.getName().equals("Mike")) {
            expected--;
            assertThat(person.getFriends().get(0).getPerson().getName()).isEqualTo("Dave");
        }
    }
    assertThat(expected).isEqualTo(0);
}
Also used : Friendship(org.neo4j.ogm.domain.friendships.Friendship) Person(org.neo4j.ogm.domain.friendships.Person) Test(org.junit.Test)

Example 2 with Person

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

the class FriendshipsRelationshipEntityTest method shouldSaveFromRelationshipEntitySetsAllObjectIds.

@Test
public void shouldSaveFromRelationshipEntitySetsAllObjectIds() {
    Person mike = new Person("Mike");
    Person dave = new Person("Dave");
    Friendship friendship = new Friendship(dave, mike, 5);
    dave.getFriends().add(friendship);
    session.save(friendship);
    assertThat(dave.getId()).isNotNull();
    assertThat(mike.getId()).isNotNull();
    assertThat(dave.getFriends().get(0).getId()).isNotNull();
}
Also used : Friendship(org.neo4j.ogm.domain.friendships.Friendship) Person(org.neo4j.ogm.domain.friendships.Person) Test(org.junit.Test)

Example 3 with Person

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

the class FriendshipsRelationshipEntityTest method shouldSaveFromStartObjectSetsAllObjectIds.

@Test
public void shouldSaveFromStartObjectSetsAllObjectIds() {
    Person mike = new Person("Mike");
    Person dave = new Person("Dave");
    // could use addFriend(...) but hey
    dave.getFriends().add(new Friendship(dave, mike, 5));
    session.save(dave);
    assertThat(dave.getId()).isNotNull();
    assertThat(mike.getId()).isNotNull();
    assertThat(dave.getFriends().get(0).getId()).isNotNull();
}
Also used : Friendship(org.neo4j.ogm.domain.friendships.Friendship) Person(org.neo4j.ogm.domain.friendships.Person) Test(org.junit.Test)

Example 4 with Person

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

the class FriendshipsRelationshipEntityTest method shouldLoadStartObjectHydratesProperly.

@Test
public void shouldLoadStartObjectHydratesProperly() {
    Person mike = new Person("Mike");
    Person dave = new Person("Dave");
    Friendship friendship = new Friendship(dave, mike, 5);
    dave.getFriends().add(friendship);
    session.save(dave);
    Person daveCopy = session.load(Person.class, dave.getId());
    Friendship friendshipCopy = daveCopy.getFriends().get(0);
    Person mikeCopy = friendshipCopy.getFriend();
    assertThat(daveCopy.getId()).isNotNull();
    assertThat(mikeCopy.getId()).isNotNull();
    assertThat(friendshipCopy.getId()).isNotNull();
    assertThat(daveCopy.getName()).isEqualTo("Dave");
    assertThat(mikeCopy.getName()).isEqualTo("Mike");
    assertThat(friendshipCopy.getStrength()).isEqualTo(5);
}
Also used : Friendship(org.neo4j.ogm.domain.friendships.Friendship) Person(org.neo4j.ogm.domain.friendships.Person) Test(org.junit.Test)

Example 5 with Person

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

the class FriendshipsRelationshipEntityTest method shouldLoadRelationshipEntityObjectHydratesProperly.

@Test
public void shouldLoadRelationshipEntityObjectHydratesProperly() {
    Person mike = new Person("Mike");
    Person dave = new Person("Dave");
    Friendship friendship = new Friendship(dave, mike, 5);
    dave.getFriends().add(friendship);
    session.save(dave);
    Friendship friendshipCopy = session.load(Friendship.class, friendship.getId());
    Person daveCopy = friendshipCopy.getPerson();
    Person mikeCopy = friendshipCopy.getFriend();
    assertThat(daveCopy.getId()).isNotNull();
    assertThat(mikeCopy.getId()).isNotNull();
    assertThat(friendshipCopy.getId()).isNotNull();
    assertThat(daveCopy.getName()).isEqualTo("Dave");
    assertThat(mikeCopy.getName()).isEqualTo("Mike");
    assertThat(friendshipCopy.getStrength()).isEqualTo(5);
}
Also used : Friendship(org.neo4j.ogm.domain.friendships.Friendship) Person(org.neo4j.ogm.domain.friendships.Person) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 Person (org.neo4j.ogm.domain.friendships.Person)7 Friendship (org.neo4j.ogm.domain.friendships.Friendship)6 HashSet (java.util.HashSet)1 Transaction (org.neo4j.ogm.transaction.Transaction)1