Search in sources :

Example 21 with Recording

use of org.neo4j.ogm.domain.music.Recording in project neo4j-ogm by neo4j.

the class LoadCapabilityTest method shouldBeAbleToLoadEntityToDifferentDepthsInDifferentSessions.

// DATAGRAPH-642, GH-174
@Test
public void shouldBeAbleToLoadEntityToDifferentDepthsInDifferentSessions() {
    Artist led = new Artist("Led Zeppelin");
    Album album = new Album("Led Zeppelin IV");
    Studio studio = new Studio("Island Studios");
    Recording recording = new Recording(album, studio, 1970);
    led.addAlbum(album);
    album.setArtist(led);
    album.setRecording(recording);
    session.save(led);
    session.clear();
    // In the first session, load the artist to depth 2
    Artist ledZeppelin = session.load(Artist.class, led.getId(), 2);
    assertThat(ledZeppelin).isNotNull();
    assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
    assertThat(ledZeppelin.getAlbums()).hasSize(1);
    Album ledZeppelinIV = ledZeppelin.getAlbums().iterator().next();
    assertThat(ledZeppelinIV.getName()).isEqualTo(album.getName());
    assertThat(ledZeppelinIV.getArtist()).isEqualTo(ledZeppelin);
    assertThat(ledZeppelinIV.getRecording()).isNotNull();
    assertThat(ledZeppelinIV.getRecording().getStudio().getName()).isEqualTo(studio.getName());
    // In the second session, load the artist to depth 0
    Session session2 = sessionFactory.openSession();
    Artist ledZeppelin0 = session2.load(Artist.class, led.getId(), 0);
    assertThat(ledZeppelin0).isNotNull();
    assertThat(ledZeppelin0.getName()).isEqualTo(led.getName());
    assertThat(ledZeppelin0.getAlbums()).isEmpty();
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Album(org.neo4j.ogm.domain.music.Album) Recording(org.neo4j.ogm.domain.music.Recording) Studio(org.neo4j.ogm.domain.music.Studio) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Aggregations

Album (org.neo4j.ogm.domain.music.Album)21 Recording (org.neo4j.ogm.domain.music.Recording)21 Studio (org.neo4j.ogm.domain.music.Studio)21 Test (org.junit.Test)19 Artist (org.neo4j.ogm.domain.music.Artist)19 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)8 Session (org.neo4j.ogm.session.Session)7 Filter (org.neo4j.ogm.cypher.Filter)3 List (java.util.List)2 Map (java.util.Map)2 Before (org.junit.Before)2 Transaction (org.neo4j.ogm.transaction.Transaction)2 MappingContext (org.neo4j.ogm.context.MappingContext)1 Filters (org.neo4j.ogm.cypher.Filters)1 Actor (org.neo4j.ogm.domain.cineasts.annotated.Actor)1 Knows (org.neo4j.ogm.domain.cineasts.annotated.Knows)1 SessionFactory (org.neo4j.ogm.session.SessionFactory)1