use of org.neo4j.ogm.domain.music.Artist in project neo4j-ogm by neo4j.
the class SaveCapabilityTest method init.
@Before
public void init() throws IOException {
SessionFactory sessionFactory = new SessionFactory(getDriver(), "org.neo4j.ogm.domain.music", "org.neo4j.ogm.domain.gh787", "org.neo4j.ogm.domain.gh789");
session = sessionFactory.openSession();
session.purgeDatabase();
aerosmith = new Artist("Aerosmith");
bonJovi = new Artist("Bon Jovi");
defLeppard = new Artist("Def Leppard");
}
use of org.neo4j.ogm.domain.music.Artist in project neo4j-ogm by neo4j.
the class MusicIntegrationTest method shouldRetrieveEntityByPropertyWithZeroDepth.
/**
* @see DATAGRAPH-629
*/
@Test
public void shouldRetrieveEntityByPropertyWithZeroDepth() {
Studio emi = new Studio("EMI Studios, London");
Artist theBeatles = new Artist("The Beatles");
Album please = new Album("Please Please Me");
Recording pleaseRecording = new Recording(please, emi, 1963);
please.setRecording(pleaseRecording);
theBeatles.getAlbums().add(please);
please.setArtist(theBeatles);
session.save(theBeatles);
theBeatles = session.loadAll(Artist.class).iterator().next();
assertThat(theBeatles.getName()).isEqualTo("The Beatles");
assertThat(theBeatles.getAlbums()).hasSize(1);
assertThat(theBeatles.getAlbums().iterator().next().getName()).isEqualTo("Please Please Me");
assertThat(theBeatles.getAlbums().iterator().next().getRecording().getStudio().getName()).isEqualTo("EMI Studios, London");
session.clear();
please = session.loadAll(Album.class, new Filter("name", ComparisonOperator.EQUALS, "Please Please Me"), 0).iterator().next();
assertThat(please.getName()).isEqualTo("Please Please Me");
assertThat(please.getArtist()).isNull();
assertThat(please.getRecording()).isNull();
}
use of org.neo4j.ogm.domain.music.Artist in project neo4j-ogm by neo4j.
the class MusicIntegrationTest method shouldSaveAndRetrieveEntitiesWithInvalidCharsInLabelsAndRels.
/**
* @see DATAGRAPH-589
*/
@Test
public void shouldSaveAndRetrieveEntitiesWithInvalidCharsInLabelsAndRels() {
Studio emi = new Studio("EMI Studios, London");
Artist theBeatles = new Artist("The Beatles");
Album please = new Album("Please Please Me");
Recording pleaseRecording = new Recording(please, emi, 1963);
please.setRecording(pleaseRecording);
theBeatles.getAlbums().add(please);
please.setArtist(theBeatles);
session.save(theBeatles);
theBeatles = session.loadAll(Artist.class).iterator().next();
assertThat(theBeatles.getName()).isEqualTo("The Beatles");
assertThat(theBeatles.getAlbums()).hasSize(1);
assertThat(theBeatles.getAlbums().iterator().next().getName()).isEqualTo("Please Please Me");
assertThat(theBeatles.getAlbums().iterator().next().getRecording().getStudio().getName()).isEqualTo("EMI Studios, London");
please = session.loadAll(Album.class, new Filter("name", ComparisonOperator.EQUALS, "Please Please Me")).iterator().next();
assertThat(please.getArtist().getName()).isEqualTo("The Beatles");
Album hard = new Album("A Hard Day's Night");
hard.setArtist(theBeatles);
Recording hardRecording = new Recording(hard, emi, 1964);
hard.setRecording(hardRecording);
theBeatles.getAlbums().add(hard);
session.save(hard);
Collection<Album> albums = session.loadAll(Album.class);
assertThat(albums).hasSize(2);
for (Album album : albums) {
if (album.getName().equals("Please Please Me")) {
assertThat(album.getRecording().getYear()).isEqualTo(1963);
} else {
assertThat(album.getRecording().getYear()).isEqualTo(1964);
}
}
}
use of org.neo4j.ogm.domain.music.Artist in project neo4j-ogm by neo4j.
the class LoadCapabilityTest method loadAllShouldRespectEntityType.
// DATAGRAPH-707
@Test
public void loadAllShouldRespectEntityType() {
Collection<Artist> artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId));
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
Collection<Album> albums = session.loadAll(Album.class, Collections.singletonList(beatlesId));
assertThat(albums).isEmpty();
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), 0);
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), 0);
assertThat(albums).isEmpty();
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"));
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"));
assertThat(albums).isEmpty();
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), 0);
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), 0);
assertThat(albums).isEmpty();
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new Pagination(0, 5));
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new Pagination(0, 5));
assertThat(albums).isEmpty();
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new Pagination(0, 5), 0);
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new Pagination(0, 5), 0);
assertThat(albums).isEmpty();
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5));
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5));
assertThat(albums).isEmpty();
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5), 0);
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
Artist bonJovi = new Artist("Bon Jovi");
session.save(bonJovi);
artists = session.loadAll(Artist.class, Arrays.asList(beatlesId, pleaseId, bonJovi.getId()), new SortOrder().add("name"), new Pagination(0, 5), 0);
assertThat(artists).hasSize(2);
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5), 0);
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo(// make sure Bon Jovi isn't returned as well
"The Beatles");
albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5), 0);
assertThat(albums).isEmpty();
}
use of org.neo4j.ogm.domain.music.Artist 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();
}
}
Aggregations