use of org.neo4j.ogm.domain.music.Studio in project neo4j-ogm by neo4j.
the class SaveCapabilityTest method shouldCountRelationshipEntities.
@Test
public void shouldCountRelationshipEntities() {
Album greatestHits = new Album("Greatest Hits");
Studio chessRecordsStudios = new Studio("Chess Records");
Studio mercuryStudios = new Studio("Mercury");
Recording recording1 = new Recording(greatestHits, chessRecordsStudios, 1962);
Recording recording2 = new Recording(greatestHits, mercuryStudios, 1967);
greatestHits.setRecording(recording1);
greatestHits.setRecording(recording2);
session.save(recording1);
session.save(recording2);
assertThat(session.countEntitiesOfType(Recording.class)).isEqualTo(2);
}
use of org.neo4j.ogm.domain.music.Studio in project neo4j-ogm by neo4j.
the class MusicIntegrationTest method shouldRetrieveEntityByPropertyWithZeroDepth.
/**
* @see DATAGRAPH-629
*/
@Test
public void shouldRetrieveEntityByPropertyWithZeroDepth() {
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);
theBeatles = session.loadAll(Artist.class).iterator().next();
assertThat(theBeatles.getName()).isEqualTo("The Beatles");
assertThat(theBeatles.getAlbums()).hasSize(1);
assertThat(theBeatles.getAlbums().iterator().next().getName()).isEqualTo("Please Please Me");
assertThat(theBeatles.getAlbums().iterator().next().getRecording().getStudio().getName()).isEqualTo("EMI Studios, London");
session.clear();
please = session.loadAll(Album.class, new Filter("name", ComparisonOperator.EQUALS, "Please Please Me"), 0).iterator().next();
assertThat(please.getName()).isEqualTo("Please Please Me");
assertThat(please.getArtist()).isNull();
assertThat(please.getRecording()).isNull();
}
use of org.neo4j.ogm.domain.music.Studio in project neo4j-ogm by neo4j.
the class MusicIntegrationTest method shouldSaveAndRetrieveEntitiesWithInvalidCharsInLabelsAndRels.
/**
* @see DATAGRAPH-589
*/
@Test
public void shouldSaveAndRetrieveEntitiesWithInvalidCharsInLabelsAndRels() {
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);
theBeatles = session.loadAll(Artist.class).iterator().next();
assertThat(theBeatles.getName()).isEqualTo("The Beatles");
assertThat(theBeatles.getAlbums()).hasSize(1);
assertThat(theBeatles.getAlbums().iterator().next().getName()).isEqualTo("Please Please Me");
assertThat(theBeatles.getAlbums().iterator().next().getRecording().getStudio().getName()).isEqualTo("EMI Studios, London");
please = session.loadAll(Album.class, new Filter("name", ComparisonOperator.EQUALS, "Please Please Me")).iterator().next();
assertThat(please.getArtist().getName()).isEqualTo("The Beatles");
Album hard = new Album("A Hard Day's Night");
hard.setArtist(theBeatles);
Recording hardRecording = new Recording(hard, emi, 1964);
hard.setRecording(hardRecording);
theBeatles.getAlbums().add(hard);
session.save(hard);
Collection<Album> albums = session.loadAll(Album.class);
assertThat(albums).hasSize(2);
for (Album album : albums) {
if (album.getName().equals("Please Please Me")) {
assertThat(album.getRecording().getYear()).isEqualTo(1963);
} else {
assertThat(album.getRecording().getYear()).isEqualTo(1964);
}
}
}
use of org.neo4j.ogm.domain.music.Studio in project neo4j-ogm by neo4j.
the class MusicIntegrationTest method shouldSortByDomainPropertyName.
/**
* @see Issue 191
*/
@Test
public void shouldSortByDomainPropertyName() {
Studio emi = new Studio("EMI Studios, London");
Studio olympic = new Studio("Olympic Studios, London");
session.save(emi);
session.save(olympic);
session.clear();
SortOrder name = new SortOrder().add("name");
Collection<Studio> studios1 = session.loadAll(Studio.class, name);
Collection<Studio> studios2 = session.loadAll(Studio.class, name);
assertThat(studios1.iterator().next().getName()).isEqualTo("EMI Studios, London");
assertThat(studios2.iterator().next().getName()).isEqualTo("EMI Studios, London");
studios1 = session.loadAll(Studio.class, new SortOrder().add(SortOrder.Direction.DESC, "name"));
assertThat(studios1.iterator().next().getName()).isEqualTo("Olympic Studios, London");
}
use of org.neo4j.ogm.domain.music.Studio in project neo4j-ogm by neo4j.
the class LoadCapabilityTest method shouldMapNewNodesAndRelationshipsWhenEntityIsReloaded.
// GH-173
@Test
public void shouldMapNewNodesAndRelationshipsWhenEntityIsReloaded() {
Artist led = new Artist("Led Zeppelin");
Album album = new Album("Led Zeppelin IV");
Studio studio = new Studio("Island Studios");
Recording recording = new Recording(album, studio, 1970);
led.addAlbum(album);
album.setArtist(led);
album.setRecording(recording);
session.save(led);
session.clear();
// Load the Artist to depth 2 in the first session
Artist ledZeppelin = session.load(Artist.class, led.getId(), 2);
assertThat(ledZeppelin).isNotNull();
assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
assertThat(ledZeppelin.getAlbums()).hasSize(1);
Album ledZeppelinIV = ledZeppelin.getAlbums().iterator().next();
assertThat(ledZeppelinIV.getName()).isEqualTo(album.getName());
assertThat(ledZeppelinIV.getArtist()).isEqualTo(ledZeppelin);
assertThat(ledZeppelinIV.getRecording()).isNotNull();
assertThat(ledZeppelinIV.getRecording().getStudio().getName()).isEqualTo(studio.getName());
// In session 2, add an album and recording
Session session2 = sessionFactory.openSession();
Artist ledZepp = session2.load(Artist.class, led.getId());
Album houses = new Album("Houses of the Holy");
Studio studio2 = new Studio("Island Studios");
Recording housesRec = new Recording(houses, studio2, 1972);
ledZepp.addAlbum(houses);
houses.setArtist(ledZepp);
houses.setRecording(housesRec);
session2.save(ledZepp);
// Reload the artist in the first session
ledZeppelin = session.load(Artist.class, led.getId(), 2);
assertThat(ledZeppelin).isNotNull();
assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
assertThat(ledZeppelin.getAlbums()).hasSize(2);
for (Album loadedAlbum : ledZeppelin.getAlbums()) {
assertThat(loadedAlbum.getArtist()).isEqualTo(ledZeppelin);
assertThat(loadedAlbum.getRecording()).isNotNull();
assertThat(loadedAlbum.getRecording().getStudio()).isNotNull();
}
}
Aggregations