Search in sources :

Example 16 with Album

use of org.neo4j.ogm.domain.music.Album 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 17 with Album

use of org.neo4j.ogm.domain.music.Album 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 18 with Album

use of org.neo4j.ogm.domain.music.Album 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 19 with Album

use of org.neo4j.ogm.domain.music.Album 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)

Example 20 with Album

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

the class SaveCapabilityTest method shouldSaveOnlyModifiedNodes.

@Test
public void shouldSaveOnlyModifiedNodes() {
    int depth = 1;
    Neo4jSession neo4jSession = (Neo4jSession) session;
    CompileContext context = null;
    Artist leann = new Artist("Leann Rimes");
    Album lost = new Album("Lost Highway");
    lost.setArtist(bonJovi);
    lost.setGuestArtist(leann);
    context = new EntityGraphMapper(neo4jSession.metaData(), neo4jSession.context()).map(lost, depth);
    assertThat(context.registry()).as("Should save 3 nodes and 2 relations (5 items)").hasSize(5);
    session.save(lost);
    context = new EntityGraphMapper(neo4jSession.metaData(), neo4jSession.context()).map(lost, depth);
    assertThat(context.registry()).as("Should have nothing to save").isEmpty();
    session.clear();
    Artist loadedLeann = session.load(Artist.class, leann.getId(), depth);
    context = new EntityGraphMapper(neo4jSession.metaData(), neo4jSession.context()).map(loadedLeann, depth);
    assertThat(context.registry()).as("Should have nothing to save").isEmpty();
    loadedLeann.setName("New name");
    context = new EntityGraphMapper(neo4jSession.metaData(), neo4jSession.context()).map(loadedLeann, depth);
    assertThat(context.registry()).as("Should have one node to save").hasSize(1);
    loadedLeann.getGuestAlbums().iterator().next().setName("New Album Name");
    context = new EntityGraphMapper(neo4jSession.metaData(), neo4jSession.context()).map(loadedLeann, depth);
    assertThat(context.registry()).as("Should have two node to save").hasSize(2);
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) EntityGraphMapper(org.neo4j.ogm.context.EntityGraphMapper) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Album(org.neo4j.ogm.domain.music.Album) CompileContext(org.neo4j.ogm.cypher.compiler.CompileContext) Test(org.junit.Test)

Aggregations

Album (org.neo4j.ogm.domain.music.Album)33 Test (org.junit.Test)30 Artist (org.neo4j.ogm.domain.music.Artist)27 Recording (org.neo4j.ogm.domain.music.Recording)21 Studio (org.neo4j.ogm.domain.music.Studio)21 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)9 Session (org.neo4j.ogm.session.Session)7 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Before (org.junit.Before)3 Filter (org.neo4j.ogm.cypher.Filter)3 Map (java.util.Map)2 MappingContext (org.neo4j.ogm.context.MappingContext)2 SessionFactory (org.neo4j.ogm.session.SessionFactory)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 Filters (org.neo4j.ogm.cypher.Filters)1