Search in sources :

Example 1 with Artist

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

the class SaveCapabilityTest method init.

@Before
public void init() throws IOException {
    SessionFactory sessionFactory = new SessionFactory(getDriver(), "org.neo4j.ogm.domain.music", "org.neo4j.ogm.domain.gh787", "org.neo4j.ogm.domain.gh789");
    session = sessionFactory.openSession();
    session.purgeDatabase();
    aerosmith = new Artist("Aerosmith");
    bonJovi = new Artist("Bon Jovi");
    defLeppard = new Artist("Def Leppard");
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) Artist(org.neo4j.ogm.domain.music.Artist) Before(org.junit.Before)

Example 2 with Artist

use of org.neo4j.ogm.domain.music.Artist 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 Artist

use of org.neo4j.ogm.domain.music.Artist 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 Artist

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

the class LoadCapabilityTest method loadAllShouldRespectEntityType.

// DATAGRAPH-707
@Test
public void loadAllShouldRespectEntityType() {
    Collection<Artist> artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId));
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    Collection<Album> albums = session.loadAll(Album.class, Collections.singletonList(beatlesId));
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), 0);
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), 0);
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"));
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"));
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), 0);
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), 0);
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new Pagination(0, 5));
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new Pagination(0, 5));
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new Pagination(0, 5), 0);
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new Pagination(0, 5), 0);
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5));
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5));
    assertThat(albums).isEmpty();
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5), 0);
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
    Artist bonJovi = new Artist("Bon Jovi");
    session.save(bonJovi);
    artists = session.loadAll(Artist.class, Arrays.asList(beatlesId, pleaseId, bonJovi.getId()), new SortOrder().add("name"), new Pagination(0, 5), 0);
    assertThat(artists).hasSize(2);
    artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5), 0);
    assertThat(artists).hasSize(1);
    assertThat(artists.iterator().next().getName()).isEqualTo(// make sure Bon Jovi isn't returned as well
    "The Beatles");
    albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5), 0);
    assertThat(albums).isEmpty();
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Pagination(org.neo4j.ogm.cypher.query.Pagination) Album(org.neo4j.ogm.domain.music.Album) SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Test(org.junit.Test)

Example 5 with Artist

use of org.neo4j.ogm.domain.music.Artist 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

Artist (org.neo4j.ogm.domain.music.Artist)33 Test (org.junit.Test)29 Album (org.neo4j.ogm.domain.music.Album)27 Recording (org.neo4j.ogm.domain.music.Recording)19 Studio (org.neo4j.ogm.domain.music.Studio)19 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)11 Session (org.neo4j.ogm.session.Session)8 Before (org.junit.Before)4 List (java.util.List)3 Filter (org.neo4j.ogm.cypher.Filter)3 SessionFactory (org.neo4j.ogm.session.SessionFactory)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 MappingContext (org.neo4j.ogm.context.MappingContext)2 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)2 Transaction (org.neo4j.ogm.transaction.Transaction)2 LocalDate (java.time.LocalDate)1 ZoneId (java.time.ZoneId)1 Date (java.util.Date)1 EntityGraphMapper (org.neo4j.ogm.context.EntityGraphMapper)1