use of org.neo4j.ogm.domain.music.Recording 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.Recording 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.Recording 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.Recording in project neo4j-ogm by neo4j.
the class SessionAndMappingContextTest method init.
@Before
public void init() throws IOException {
session = (Neo4jSession) sessionFactory.openSession();
artist1 = new Artist();
artist1.setName("MainArtist");
Artist artist2 = new Artist();
artist2.setName("GuestArtist");
album1 = new Album();
album1.setName("First");
album1.setGuestArtist(artist2);
album2 = new Album();
album2.setName("Second");
album3 = new Album();
album3.setName("Third");
artist1.addAlbum(album1);
artist1.addAlbum(album2);
artist1.addAlbum(album3);
Studio studio = new Studio();
studio.setName("Studio");
Recording recording = new Recording();
recording.setAlbum(album1);
recording.setAlbum(album2);
recording.setAlbum(album3);
recording.setStudio(studio);
recording.setYear(2001);
session.save(artist1);
actor1 = new Actor("Actor1");
actor2 = new Actor("Actor2");
knows = new Knows();
knows.setFirstActor(actor1);
knows.setSecondActor(actor2);
actor1.knows.add(knows);
session.save(actor1);
Actor actor3 = new Actor("Actor3");
Actor actor4 = new Actor("Actor4");
knows2 = new Knows();
knows2.setFirstActor(actor3);
knows2.setSecondActor(actor4);
actor3.knows.add(knows2);
session.save(actor3);
}
use of org.neo4j.ogm.domain.music.Recording in project neo4j-ogm by neo4j.
the class TransactionTest method shouldNotCommitWhenTransactionIsManaged.
@Test
public void shouldNotCommitWhenTransactionIsManaged() {
Transaction tx = session.beginTransaction();
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);
// the previous saves shouldn't have been committed
tx.rollback();
assertThat(session.countEntitiesOfType(Artist.class)).isEqualTo(0);
}
Aggregations