Search in sources :

Example 1 with Studio

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);
}
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 Studio

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

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);
        }
    }
}
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 Studio

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");
}
Also used : SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Studio(org.neo4j.ogm.domain.music.Studio) Test(org.junit.Test)

Example 5 with Studio

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

Studio (org.neo4j.ogm.domain.music.Studio)29 Test (org.junit.Test)27 Album (org.neo4j.ogm.domain.music.Album)21 Recording (org.neo4j.ogm.domain.music.Recording)21 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)4 Transaction (org.neo4j.ogm.transaction.Transaction)3 List (java.util.List)2 Map (java.util.Map)2 Before (org.junit.Before)2 MappingContext (org.neo4j.ogm.context.MappingContext)1 Filters (org.neo4j.ogm.cypher.Filters)1 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)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