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