use of org.neo4j.ogm.domain.music.Artist in project neo4j-ogm by neo4j.
the class MusicIntegrationTest method shouldSaveAndRetrieveArtistWithTwoRelationshipTypesToAlbums.
/**
* @see DATAGRAPH-637
*/
@Test
public void shouldSaveAndRetrieveArtistWithTwoRelationshipTypesToAlbums() {
Studio emi = new Studio("EMI Studios, London");
Studio olympic = new Studio("Olympic Studios, London");
Artist theBeatles = new Artist("The Beatles");
Artist eric = new Artist("Eric Clapton");
Album slowhand = new Album("Slowhand");
Recording slowRecording = new Recording(slowhand, olympic, 1977);
slowhand.setRecording(slowRecording);
slowhand.setArtist(eric);
session.save(slowhand);
session.clear();
Album theBeatlesAlbum = new Album("The Beatles");
Recording pleaseRecording = new Recording(theBeatlesAlbum, emi, 1968);
theBeatlesAlbum.setRecording(pleaseRecording);
theBeatles.getAlbums().add(theBeatlesAlbum);
theBeatlesAlbum.setArtist(theBeatles);
theBeatlesAlbum.setGuestArtist(eric);
session.save(theBeatlesAlbum);
theBeatles = session.loadAll(Artist.class, new Filters().add(new Filter("name", ComparisonOperator.EQUALS, "The Beatles"))).iterator().next();
assertThat(theBeatles.getName()).isEqualTo("The Beatles");
assertThat(theBeatles.getAlbums()).hasSize(1);
assertThat(theBeatles.getAlbums().iterator().next().getName()).isEqualTo("The Beatles");
assertThat(theBeatles.getAlbums().iterator().next().getRecording().getStudio().getName()).isEqualTo("EMI Studios, London");
assertThat(theBeatles.getAlbums().iterator().next().getGuestArtist()).isEqualTo(eric);
// Eric has 2 albums now
session.clear();
Artist loadedEric = session.loadAll(Artist.class, new Filters().add(new Filter("name", ComparisonOperator.EQUALS, "Eric Clapton"))).iterator().next();
assertThat(loadedEric).isNotNull();
assertThat(loadedEric.getGuestAlbums().iterator().next().getName()).isEqualTo("The Beatles");
assertThat(loadedEric.getAlbums().iterator().next().getName()).isEqualTo("Slowhand");
}
use of org.neo4j.ogm.domain.music.Artist in project neo4j-ogm by neo4j.
the class MusicIntegrationTest method shouldBeAbleToQueryForLiteralMapWithAlias.
/**
* Issue #83
*/
@Test
public void shouldBeAbleToQueryForLiteralMapWithAlias() {
Studio emi = new Studio("EMI Studios, London");
Artist theBeatles = new Artist("The Beatles");
Album theBeatlesAlbum = new Album("The Beatles");
Recording theBeatlesRec = new Recording(theBeatlesAlbum, emi, 1968);
theBeatlesAlbum.setRecording(theBeatlesRec);
theBeatles.getAlbums().add(theBeatlesAlbum);
theBeatlesAlbum.setArtist(theBeatles);
session.save(theBeatlesAlbum);
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);
Iterator<Map<String, Object>> resultIterator = session.query("MATCH (n:`l'artiste`)-[:`HAS-ALBUM`]-(a) return {artist: collect(distinct n.name), albums: collect(a.name)} as result", Collections.EMPTY_MAP).queryResults().iterator();
assertThat(resultIterator.hasNext()).isTrue();
Map<String, Object> row = resultIterator.next();
Map data = (Map) row.get("result");
List<String> albums = (List<String>) data.get("albums");
List<String> artist = (List<String>) data.get("artist");
assertThat(artist).hasSize(1);
assertThat(artist.get(0)).isEqualTo("The Beatles");
assertThat(albums).hasSize(2);
assertThat(albums.contains("The Beatles")).isTrue();
assertThat(albums.contains("Please Please Me")).isTrue();
assertThat(resultIterator.hasNext()).isFalse();
}
use of org.neo4j.ogm.domain.music.Artist in project neo4j-ogm by neo4j.
the class MusicIntegrationTest method shouldBeAbleToQueryForLiteralMapWithoutAlias.
/**
* Issue #83
*/
@Test
public void shouldBeAbleToQueryForLiteralMapWithoutAlias() {
Studio emi = new Studio("EMI Studios, London");
Artist theBeatles = new Artist("The Beatles");
Album theBeatlesAlbum = new Album("The Beatles");
Recording theBeatlesRec = new Recording(theBeatlesAlbum, emi, 1968);
theBeatlesAlbum.setRecording(theBeatlesRec);
theBeatles.getAlbums().add(theBeatlesAlbum);
theBeatlesAlbum.setArtist(theBeatles);
session.save(theBeatlesAlbum);
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);
Iterator<Map<String, Object>> resultIterator = session.query("MATCH (n:`l'artiste`)-[:`HAS-ALBUM`]-(a) return {artist: collect(distinct n.name), albums: collect(a.name)}", Collections.EMPTY_MAP).queryResults().iterator();
assertThat(resultIterator.hasNext()).isTrue();
Map<String, Object> row = resultIterator.next();
Map data = (Map) row.get("{artist: collect(distinct n.name), albums: collect(a.name)}");
List<String> albums = (List<String>) data.get("albums");
List<String> artist = (List<String>) data.get("artist");
assertThat(artist).hasSize(1);
assertThat(artist.get(0)).isEqualTo("The Beatles");
assertThat(albums).hasSize(2);
assertThat(albums.contains("The Beatles")).isTrue();
assertThat(albums.contains("Please Please Me")).isTrue();
assertThat(resultIterator.hasNext()).isFalse();
}
use of org.neo4j.ogm.domain.music.Artist in project neo4j-ogm by neo4j.
the class SaveCapabilityTest method saveCollectionShouldSaveLists.
// GH-84
@Test
public void saveCollectionShouldSaveLists() {
Album nineLives = new Album("Nine Lives");
aerosmith.addAlbum(nineLives);
Album crossRoad = new Album("Cross Road");
bonJovi.addAlbum(crossRoad);
List<Artist> artists = Arrays.asList(aerosmith, bonJovi, defLeppard);
session.save(artists);
session.clear();
assertThat(session.countEntitiesOfType(Artist.class)).isEqualTo(3);
assertThat(session.countEntitiesOfType(Album.class)).isEqualTo(2);
}
use of org.neo4j.ogm.domain.music.Artist in project neo4j-ogm by neo4j.
the class SaveCapabilityTest method shouldSaveNewNodesAndNewRelationships.
@Test
public void shouldSaveNewNodesAndNewRelationships() {
Artist leann = new Artist("Leann Rimes");
Album lost = new Album("Lost Highway");
lost.setArtist(bonJovi);
lost.setGuestArtist(leann);
session.save(lost);
session.clear();
Artist loadedLeann = session.load(Artist.class, leann.getId());
assertThat(loadedLeann).isNotNull();
assertThat(loadedLeann.getName()).isEqualTo("Leann Rimes");
assertThat(loadedLeann.getGuestAlbums().iterator().next().getName()).isEqualTo(lost.getName());
Artist loadedBonJovi = session.load(Artist.class, bonJovi.getId());
assertThat(loadedBonJovi).isNotNull();
assertThat(loadedBonJovi.getName()).isEqualTo("Bon Jovi");
assertThat(loadedBonJovi.getAlbums().iterator().next().getName()).isEqualTo(lost.getName());
Album loadedLost = session.load(Album.class, lost.getId());
assertThat(loadedLost).isNotNull();
assertThat(loadedLost.getName()).isEqualTo("Lost Highway");
assertThat(loadedLost.getGuestArtist()).isEqualTo(loadedLeann);
assertThat(loadedLost.getArtist().getName()).isEqualTo(loadedBonJovi.getName());
}
Aggregations