use of org.neo4j.ogm.domain.music.Album in project neo4j-ogm by neo4j.
the class LoadCapabilityTest method shouldMapNewNodesAndRelationshipsWhenEntityIsReloaded.
// GH-173
@Test
public void shouldMapNewNodesAndRelationshipsWhenEntityIsReloaded() {
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 the Artist to depth 2 in the first session
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 session 2, add an album and recording
Session session2 = sessionFactory.openSession();
Artist ledZepp = session2.load(Artist.class, led.getId());
Album houses = new Album("Houses of the Holy");
Studio studio2 = new Studio("Island Studios");
Recording housesRec = new Recording(houses, studio2, 1972);
ledZepp.addAlbum(houses);
houses.setArtist(ledZepp);
houses.setRecording(housesRec);
session2.save(ledZepp);
// Reload the artist in the first session
ledZeppelin = session.load(Artist.class, led.getId(), 2);
assertThat(ledZeppelin).isNotNull();
assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
assertThat(ledZeppelin.getAlbums()).hasSize(2);
for (Album loadedAlbum : ledZeppelin.getAlbums()) {
assertThat(loadedAlbum.getArtist()).isEqualTo(ledZeppelin);
assertThat(loadedAlbum.getRecording()).isNotNull();
assertThat(loadedAlbum.getRecording().getStudio()).isNotNull();
}
}
use of org.neo4j.ogm.domain.music.Album in project neo4j-ogm by neo4j.
the class LoadCapabilityTest method shouldNotModifyPreviouslyLoadedNodesWhenDepthIsReduced.
// GH-173
@Test
public void shouldNotModifyPreviouslyLoadedNodesWhenDepthIsReduced() {
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 the Artist to depth 1 in the first session
Artist 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();
// In session 2, update the name of the artist
Session session2 = sessionFactory.openSession();
Artist ledZepp = session2.load(Artist.class, led.getId(), 0);
ledZepp.setName("Led Zepp");
session2.save(ledZepp);
// Back in the first session, load the artist 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);
}
use of org.neo4j.ogm.domain.music.Album in project neo4j-ogm by neo4j.
the class LoadCapabilityTest method shouldNotModifyPreviouslyLoadedNodesWhenEntityIsReloaded.
// GH-173
@Test
public void shouldNotModifyPreviouslyLoadedNodesWhenEntityIsReloaded() {
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 the Artist to depth 1 in the first session
Artist 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();
// In session 2, update the name of the artist
Session session2 = sessionFactory.openSession();
Artist ledZepp = session2.load(Artist.class, led.getId(), 0);
ledZepp.setName("Led Zepp");
session2.save(ledZepp);
// Reload the artist in the first session
ledZeppelin = session.load(Artist.class, led.getId(), 1);
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()).isNull();
}
use of org.neo4j.ogm.domain.music.Album in project neo4j-ogm by neo4j.
the class LoadCapabilityTest method shouldBeAbleToLoadEntitiesToDifferentDepthsInDifferentSessions.
// GH-170
@Test
public void shouldBeAbleToLoadEntitiesToDifferentDepthsInDifferentSessions() {
Artist pinkFloyd = new Artist("Pink Floyd");
Album divisionBell = new Album("The Division Bell");
divisionBell.setArtist(pinkFloyd);
Studio studio = new Studio("Britannia Row Studios");
Recording recording = new Recording(divisionBell, studio, 1994);
divisionBell.setRecording(recording);
pinkFloyd.addAlbum(divisionBell);
session.save(pinkFloyd);
session.clear();
// Load Pink Floyd to depth 1 in a new session
Session session1 = sessionFactory.openSession();
Artist pinkfloyd1 = session1.load(Artist.class, pinkFloyd.getId(), 1);
assertThat(pinkfloyd1).isNotNull();
assertThat(pinkfloyd1.getAlbums()).hasSize(1);
assertThat(pinkfloyd1.getAlbums().iterator().next().getRecording()).isNull();
// Load Pink Floyd to depth -1 in a new session
Session session2 = sessionFactory.openSession();
Artist pinkfloyd2 = session2.load(Artist.class, pinkFloyd.getId(), -1);
assertThat(pinkfloyd2).isNotNull();
assertThat(pinkfloyd2.getAlbums()).hasSize(1);
assertThat(pinkfloyd2.getAlbums().iterator().next().getRecording()).isNotNull();
// Load Pink Floyd to depth -1 in an existing session which has loaded it to depth 1 previously
Artist pinkfloyd_1_1 = session1.load(Artist.class, pinkFloyd.getId(), -1);
assertThat(pinkfloyd_1_1).isNotNull();
assertThat(pinkfloyd_1_1.getAlbums()).hasSize(1);
assertThat(pinkfloyd2.getAlbums().iterator().next().getRecording()).isNotNull();
}
use of org.neo4j.ogm.domain.music.Album in project neo4j-ogm by neo4j.
the class LoadCapabilityTest method shouldRefreshEntityStateWhenReloadedOnCleanSession.
// GH-173
@Test
public void shouldRefreshEntityStateWhenReloadedOnCleanSession() {
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 the Artist to depth 1 in the first session
Artist 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();
// In session 2, update the name of the artist, delete the album
Session session2 = sessionFactory.openSession();
Artist ledZepp = session2.load(Artist.class, led.getId(), 1);
ledZepp.setName("Led Zepp");
ledZepp.getAlbums().iterator().next().setArtist(null);
ledZepp.getAlbums().clear();
session2.save(ledZepp);
// Reload the artist in a clean session
session.clear();
ledZeppelin = session.load(Artist.class, led.getId(), 1);
assertThat(ledZeppelin).isNotNull();
assertThat(ledZeppelin.getName()).isEqualTo(ledZepp.getName());
assertThat(ledZeppelin.getAlbums()).isEmpty();
}
Aggregations