Search in sources :

Example 1 with Rider

use of org.neo4j.ogm.domain.gh817.Rider in project neo4j-ogm by neo4j.

the class SessionAndMappingContextTest method shouldRefreshUpdatedRelationshipEntities.

// GH-817
@Test
public void shouldRefreshUpdatedRelationshipEntities() {
    sessionFactory.openSession().purgeDatabase();
    Session sessionForCreation = sessionFactory.openSession();
    Rider rider = new Rider("Michael");
    Bike bike1 = new Bike("Bike1");
    Bike bike2 = new Bike("Bike2");
    rider.getTrips().add(new Trip(rider, bike1, "n/a"));
    rider.getTrips().add(new Trip(rider, bike2, "n/a"));
    try (Transaction tx = sessionForCreation.beginTransaction()) {
        sessionForCreation.save(rider);
        tx.commit();
    }
    Session sessionForLoadingAndUpdate = sessionFactory.openSession();
    Iterable<Trip> loadedBikes = sessionForLoadingAndUpdate.loadAll(Trip.class);
    assertThat(loadedBikes).hasSize(2).extracting(Trip::getName).containsOnly("n/a");
    String name = "A nice trip";
    Iterable<Trip> updatedBikes = sessionForLoadingAndUpdate.query(Trip.class, "MATCH (r:Rider) - [t:RODE] -> (c:Bike) SET t.name = $newName RETURN *", Collections.singletonMap("newName", name));
    Rider loadedRider = sessionForLoadingAndUpdate.load(Rider.class, rider.getId());
    assertThat(updatedBikes).hasSize(2).extracting(Trip::getName).containsOnly(name);
    assertThat(loadedRider.getTrips()).hasSize(2).extracting(Trip::getName).containsOnly(name);
}
Also used : Trip(org.neo4j.ogm.domain.gh817.Trip) Transaction(org.neo4j.ogm.transaction.Transaction) Rider(org.neo4j.ogm.domain.gh817.Rider) Bike(org.neo4j.ogm.domain.gh817.Bike) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Bike (org.neo4j.ogm.domain.gh817.Bike)1 Rider (org.neo4j.ogm.domain.gh817.Rider)1 Trip (org.neo4j.ogm.domain.gh817.Trip)1 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)1 Session (org.neo4j.ogm.session.Session)1 Transaction (org.neo4j.ogm.transaction.Transaction)1