Search in sources :

Example 1 with Recording

use of org.neo4j.ogm.domain.music.Recording 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);
}
Also used : 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 2 with Recording

use of org.neo4j.ogm.domain.music.Recording 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();
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) 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 3 with Recording

use of org.neo4j.ogm.domain.music.Recording 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);
        }
    }
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) 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 4 with Recording

use of org.neo4j.ogm.domain.music.Recording 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();
    }
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Album(org.neo4j.ogm.domain.music.Album) Recording(org.neo4j.ogm.domain.music.Recording) Studio(org.neo4j.ogm.domain.music.Studio) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Example 5 with Recording

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

the class LoadCapabilityTest method shouldNotModifyPreviouslyLoadedNodesWhenDepthIsReduced.

// GH-173
@Test
public void shouldNotModifyPreviouslyLoadedNodesWhenDepthIsReduced() {
    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 1 in the first session
    Artist ledZeppelin = session.load(Artist.class, led.getId(), 1);
    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()).isNull();
    // In session 2, update the name of the artist
    Session session2 = sessionFactory.openSession();
    Artist ledZepp = session2.load(Artist.class, led.getId(), 0);
    ledZepp.setName("Led Zepp");
    session2.save(ledZepp);
    // Back in the first session, load the artist to depth 0
    ledZeppelin = session.load(Artist.class, led.getId(), 0);
    assertThat(ledZeppelin).isNotNull();
    assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
    assertThat(ledZeppelin.getAlbums()).hasSize(1);
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Album(org.neo4j.ogm.domain.music.Album) Recording(org.neo4j.ogm.domain.music.Recording) Studio(org.neo4j.ogm.domain.music.Studio) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Aggregations

Album (org.neo4j.ogm.domain.music.Album)21 Recording (org.neo4j.ogm.domain.music.Recording)21 Studio (org.neo4j.ogm.domain.music.Studio)21 Test (org.junit.Test)19 Artist (org.neo4j.ogm.domain.music.Artist)19 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)8 Session (org.neo4j.ogm.session.Session)7 Filter (org.neo4j.ogm.cypher.Filter)3 List (java.util.List)2 Map (java.util.Map)2 Before (org.junit.Before)2 Transaction (org.neo4j.ogm.transaction.Transaction)2 MappingContext (org.neo4j.ogm.context.MappingContext)1 Filters (org.neo4j.ogm.cypher.Filters)1 Actor (org.neo4j.ogm.domain.cineasts.annotated.Actor)1 Knows (org.neo4j.ogm.domain.cineasts.annotated.Knows)1 SessionFactory (org.neo4j.ogm.session.SessionFactory)1