use of org.neo4j.ogm.domain.music.Album in project neo4j-ogm by neo4j.
the class LoadCapabilityTest method shouldNotModifyPreviouslyLoadedNodesWhenDepthIsIncreased.
// GH-173
@Test
public void shouldNotModifyPreviouslyLoadedNodesWhenDepthIsIncreased() {
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 0 in the first session
Artist ledZeppelin = session.load(Artist.class, led.getId(), 0);
assertThat(ledZeppelin).isNotNull();
assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
assertThat(ledZeppelin.getAlbums()).isEmpty();
// 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 1
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();
}
use of org.neo4j.ogm.domain.music.Album in project neo4j-ogm by neo4j.
the class SessionAndMappingContextTest method disposeFromMappingContextOnDeleteWithTransientRelationshipTest.
@Test
public void disposeFromMappingContextOnDeleteWithTransientRelationshipTest() {
MappingContext mappingContext = session.context();
assertThat(mappingContext.getNodeEntity(artist1.getId()).getClass() == Artist.class).isTrue();
session.delete(artist1);
// check that the mapping context does not hold a reference to the deleted entity anymore
Object object = mappingContext.getNodeEntity(artist1.getId());
assertThat(object == null).isTrue();
// check that objects with references to the deleted object have been cleared
// check for TransientRelationship, where the object connected to the deleted object holds ref in a Set
Album retrievedAlbum1 = (Album) mappingContext.getNodeEntity(album1.getId());
assertThat(retrievedAlbum1.getArtist() == null).isTrue();
Album retrievedAlbum2 = (Album) mappingContext.getNodeEntity(album2.getId());
assertThat(retrievedAlbum2.getArtist() == null).isTrue();
Album retrievedAlbum3 = (Album) mappingContext.getNodeEntity(album3.getId());
assertThat(retrievedAlbum3.getArtist() == null).isTrue();
}
use of org.neo4j.ogm.domain.music.Album in project neo4j-ogm by neo4j.
the class TransactionTest method shouldBeAbleToRetrySaveOnTransactionRollback.
// GH-126
@Test
public void shouldBeAbleToRetrySaveOnTransactionRollback() {
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);
tx.rollback();
session.save(theBeatles);
session.clear();
theBeatles = session.loadAll(Artist.class, -1).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");
}
use of org.neo4j.ogm.domain.music.Album in project neo4j-ogm by neo4j.
the class CompilerTest method createSimpleRelationshipWithIllegalCharactersBetweenObjects.
// DATAGRAPH-589
@Test
public void createSimpleRelationshipWithIllegalCharactersBetweenObjects() {
Artist theBeatles = new Artist("The Beatles");
Album please = new Album("Please Please Me");
theBeatles.getAlbums().add(please);
please.setArtist(theBeatles);
Compiler compiler = mapAndCompile(theBeatles, -1);
List<Statement> statements = compiler.createNodesStatements();
assertThat(statements).extracting(Statement::getStatement).containsOnly("UNWIND $rows as row CREATE (n:`l'artiste`) SET n=row.props RETURN row.nodeRef as ref, ID(n) as id, $type as type", "UNWIND $rows as row CREATE (n:`l'album`) SET n=row.props RETURN row.nodeRef as ref, ID(n) as id, $type as type");
for (Statement statement : statements) {
List rows = (List) statement.getParameters().get("rows");
assertThat(rows).hasSize(1);
}
statements = compiler.createRelationshipsStatements();
assertThat(statements).extracting(Statement::getStatement).containsOnly("UNWIND $rows as row MATCH (startNode) WHERE ID(startNode) = row.startNodeId WITH row,startNode MATCH (endNode) WHERE ID(endNode) = row.endNodeId MERGE (startNode)-[rel:`HAS-ALBUM`]->(endNode) RETURN row.relRef as ref, ID(rel) as id, $type as type");
for (Statement statement : statements) {
List rows = (List) statement.getParameters().get("rows");
assertThat(rows).hasSize(1);
}
}
use of org.neo4j.ogm.domain.music.Album 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");
}
Aggregations