Search in sources :

Example 26 with Artist

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

the class LoadCapabilityTest method shouldAddRelationshipsWhenDepthIsIncreased.

// DATAGRAPH-642, GH-174
@Test
public void shouldAddRelationshipsWhenDepthIsIncreased() {
    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();
    // Load to depth 0
    Artist ledZeppelin = session.load(Artist.class, led.getId(), 0);
    assertThat(ledZeppelin).isNotNull();
    assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
    assertThat(ledZeppelin.getAlbums()).isEmpty();
    // Load to depth 1
    ledZeppelin = session.load(Artist.class, led.getId(), 1);
    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()).isNull();
    // Load to depth 2
    ledZeppelin = session.load(Artist.class, led.getId(), 2);
    assertThat(ledZeppelin).isNotNull();
    assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
    assertThat(ledZeppelin.getAlbums()).hasSize(1);
    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());
}
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) Test(org.junit.Test)

Example 27 with Artist

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

the class LoadCapabilityTest method init.

@Before
public void init() throws IOException {
    sessionFactory = new SessionFactory(getDriver(), "org.neo4j.ogm.domain.music", "org.neo4j.ogm.domain.gh368");
    session = sessionFactory.openSession();
    session.purgeDatabase();
    // Create some data
    Artist theBeatles = new Artist("The Beatles");
    Album please = new Album("Please Please Me");
    theBeatles.getAlbums().add(please);
    please.setArtist(theBeatles);
    session.save(theBeatles);
    pleaseId = please.getId();
    beatlesId = theBeatles.getId();
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) Artist(org.neo4j.ogm.domain.music.Artist) Album(org.neo4j.ogm.domain.music.Album) Before(org.junit.Before)

Example 28 with Artist

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

the class LoadCapabilityTest method shouldNotBeDirtyOnLoadEntityThenSaveThenReload.

// GH-177
@Test
public void shouldNotBeDirtyOnLoadEntityThenSaveThenReload() {
    MappingContext context = ((Neo4jSession) session).context();
    Artist pinkFloyd = new Artist("Pink Floyd");
    // new object not saved is always dirty
    assertThat(context.isDirty(pinkFloyd)).isTrue();
    session.save(pinkFloyd);
    // object hash updated by save.
    assertThat(context.isDirty(pinkFloyd)).isFalse();
    // forget everything we've done
    session.clear();
    pinkFloyd = session.load(Artist.class, pinkFloyd.getId());
    // a freshly loaded object is never dirty
    assertThat(context.isDirty(pinkFloyd)).isFalse();
    pinkFloyd.setName("Purple Floyd");
    // we changed the name so it is now dirty
    assertThat(context.isDirty(pinkFloyd)).isTrue();
    session.save(pinkFloyd);
    // object saved, no longer dirty
    assertThat(context.isDirty(pinkFloyd)).isFalse();
    // load the same identity, but to a copy ref
    Artist purpleFloyd = session.load(Artist.class, pinkFloyd.getId());
    // nothing has changed, so it should not be dirty
    assertThat(context.isDirty(purpleFloyd)).isFalse();
    // two refs pointing to the same object
    assertThat(pinkFloyd == purpleFloyd).isTrue();
}
Also used : MappingContext(org.neo4j.ogm.context.MappingContext) Artist(org.neo4j.ogm.domain.music.Artist) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Test(org.junit.Test)

Example 29 with Artist

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

the class LoadCapabilityTest method shouldRetainPreviouslyLoadedRelationshipsWhenDepthIsReduced.

// DATAGRAPH-642, GH-174
@Test
public void shouldRetainPreviouslyLoadedRelationshipsWhenDepthIsReduced() {
    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();
    // Load 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());
    // Now load to depth 1
    ledZeppelin = session.load(Artist.class, led.getId(), 0);
    assertThat(ledZeppelin).isNotNull();
    assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
    assertThat(ledZeppelin.getAlbums()).hasSize(1);
    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());
    // Now load to depth 0
    ledZeppelin = session.load(Artist.class, led.getId(), 0);
    assertThat(ledZeppelin).isNotNull();
    assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
    assertThat(ledZeppelin.getAlbums()).hasSize(1);
    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());
}
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) Test(org.junit.Test)

Example 30 with Artist

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

the class LoadCapabilityTest method loadOneShouldRespectEntityType.

// DATAGRAPH-707
@Test
public void loadOneShouldRespectEntityType() {
    Artist artist = session.load(Artist.class, beatlesId);
    assertThat(artist.getName()).isEqualTo("The Beatles");
    Album album = session.load(Album.class, beatlesId);
    assertThat(album).isNull();
    artist = session.load(Artist.class, beatlesId, 0);
    assertThat(artist.getName()).isEqualTo("The Beatles");
    album = session.load(Album.class, beatlesId, 0);
    assertThat(album).isNull();
    // ID does not exist
    artist = session.load(Artist.class, Long.MAX_VALUE);
    assertThat(artist).isNull();
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Album(org.neo4j.ogm.domain.music.Album) Test(org.junit.Test)

Aggregations

Artist (org.neo4j.ogm.domain.music.Artist)33 Test (org.junit.Test)29 Album (org.neo4j.ogm.domain.music.Album)27 Recording (org.neo4j.ogm.domain.music.Recording)19 Studio (org.neo4j.ogm.domain.music.Studio)19 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)11 Session (org.neo4j.ogm.session.Session)8 Before (org.junit.Before)4 List (java.util.List)3 Filter (org.neo4j.ogm.cypher.Filter)3 SessionFactory (org.neo4j.ogm.session.SessionFactory)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 MappingContext (org.neo4j.ogm.context.MappingContext)2 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)2 Transaction (org.neo4j.ogm.transaction.Transaction)2 LocalDate (java.time.LocalDate)1 ZoneId (java.time.ZoneId)1 Date (java.util.Date)1 EntityGraphMapper (org.neo4j.ogm.context.EntityGraphMapper)1