use of org.neo4j.ogm.domain.cineasts.annotated.Knows in project neo4j-ogm by neo4j.
the class SessionAndMappingContextTest method shouldRollbackRelationshipEntityWithDifferentStartAndEndNodes.
@Test
public void shouldRollbackRelationshipEntityWithDifferentStartAndEndNodes() {
Actor mary = new Actor("Mary");
Actor john = new Actor("John");
Knows maryKnowsJohn = new Knows();
maryKnowsJohn.setFirstActor(mary);
maryKnowsJohn.setSecondActor(john);
try (Transaction tx = session.beginTransaction()) {
session.save(maryKnowsJohn);
assertThat(mary.getUuid()).isNotNull();
assertThat(maryKnowsJohn.id).isNotNull();
assertThat(john.getUuid()).isNotNull();
tx.rollback();
assertThat(mary.getUuid()).isNull();
assertThat(maryKnowsJohn.id).isNull();
assertThat(john.getUuid()).isNull();
}
}
use of org.neo4j.ogm.domain.cineasts.annotated.Knows in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldSaveRelationshipEntityWithCamelCaseStartEndNodes.
// DATAGRAPH-567
@Test
public void shouldSaveRelationshipEntityWithCamelCaseStartEndNodes() {
Actor bruce = new Actor("Bruce");
Actor jim = new Actor("Jim");
Knows knows = new Knows();
knows.setFirstActor(bruce);
knows.setSecondActor(jim);
knows.setSince(new Date());
bruce.getKnows().add(knows);
session.save(bruce);
Actor actor = TestUtils.firstOrNull(session.loadAll(Actor.class, new Filter("name", ComparisonOperator.EQUALS, "Bruce")));
assertThat(actor).isNotNull();
assertThat(actor.getKnows()).hasSize(1);
assertThat(actor.getKnows().iterator().next().getSecondActor().getName()).isEqualTo("Jim");
}
use of org.neo4j.ogm.domain.cineasts.annotated.Knows in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldSaveRelationshipEntityWithNullProperty.
// DATAGRAPH-610
@Test
public void shouldSaveRelationshipEntityWithNullProperty() {
Actor bruce = new Actor("Bruce");
Actor jim = new Actor("Jim");
// since = null
Knows knows = new Knows();
knows.setFirstActor(bruce);
knows.setSecondActor(jim);
bruce.getKnows().add(knows);
session.save(bruce);
Actor actor = TestUtils.firstOrNull(session.loadAll(Actor.class, new Filter("name", ComparisonOperator.EQUALS, "Bruce")));
assertThat(actor).isNotNull();
assertThat(actor.getKnows()).hasSize(1);
assertThat(actor.getKnows().iterator().next().getSecondActor().getName()).isEqualTo("Jim");
bruce.getKnows().iterator().next().setSince(new Date());
session.save(bruce);
actor = TestUtils.firstOrNull(session.loadAll(Actor.class, new Filter("name", ComparisonOperator.EQUALS, "Bruce")));
assertThat(actor.getKnows()).hasSize(1);
assertThat(actor.getKnows().iterator().next().getSince()).isNotNull();
bruce.getKnows().iterator().next().setSince(null);
session.save(bruce);
actor = TestUtils.firstOrNull(session.loadAll(Actor.class, new Filter("name", ComparisonOperator.EQUALS, "Bruce")));
assertThat(actor.getKnows()).hasSize(1);
assertThat(actor.getKnows().iterator().next().getSince()).isNull();
}
use of org.neo4j.ogm.domain.cineasts.annotated.Knows in project neo4j-ogm by neo4j.
the class SessionAndMappingContextTest method init.
@Before
public void init() throws IOException {
session = (Neo4jSession) sessionFactory.openSession();
artist1 = new Artist();
artist1.setName("MainArtist");
Artist artist2 = new Artist();
artist2.setName("GuestArtist");
album1 = new Album();
album1.setName("First");
album1.setGuestArtist(artist2);
album2 = new Album();
album2.setName("Second");
album3 = new Album();
album3.setName("Third");
artist1.addAlbum(album1);
artist1.addAlbum(album2);
artist1.addAlbum(album3);
Studio studio = new Studio();
studio.setName("Studio");
Recording recording = new Recording();
recording.setAlbum(album1);
recording.setAlbum(album2);
recording.setAlbum(album3);
recording.setStudio(studio);
recording.setYear(2001);
session.save(artist1);
actor1 = new Actor("Actor1");
actor2 = new Actor("Actor2");
knows = new Knows();
knows.setFirstActor(actor1);
knows.setSecondActor(actor2);
actor1.knows.add(knows);
session.save(actor1);
Actor actor3 = new Actor("Actor3");
Actor actor4 = new Actor("Actor4");
knows2 = new Knows();
knows2.setFirstActor(actor3);
knows2.setSecondActor(actor4);
actor3.knows.add(knows2);
session.save(actor3);
}
Aggregations