Search in sources :

Example 16 with Artist

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");
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) 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 17 with Artist

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();
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Album(org.neo4j.ogm.domain.music.Album) List(java.util.List) Recording(org.neo4j.ogm.domain.music.Recording) Studio(org.neo4j.ogm.domain.music.Studio) Map(java.util.Map) Test(org.junit.Test)

Example 18 with Artist

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();
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Album(org.neo4j.ogm.domain.music.Album) List(java.util.List) Recording(org.neo4j.ogm.domain.music.Recording) Studio(org.neo4j.ogm.domain.music.Studio) Map(java.util.Map) Test(org.junit.Test)

Example 19 with Artist

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);
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Album(org.neo4j.ogm.domain.music.Album) Test(org.junit.Test)

Example 20 with Artist

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());
}
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