use of org.neo4j.ogm.domain.cineasts.annotated.Knows in project neo4j-ogm by neo4j.
the class EventTestBaseClass method init.
@Before
public void init() throws IOException {
session = sessionFactory.openSession();
session.purgeDatabase();
a = new Document();
a.setName("a");
b = new Document();
b.setName("b");
c = new Document();
c.setName("c");
d = new Document();
d.setName("d");
e = new Document();
e.setName("e");
folder = new Folder();
folder.setName("folder");
folder.getDocuments().add(a);
folder.getDocuments().add(b);
folder.getDocuments().add(c);
a.setFolder(folder);
b.setFolder(folder);
c.setFolder(folder);
session.save(d);
session.save(e);
session.save(folder);
jim = new Actor("Jim");
bruce = new Actor("Bruce");
lee = new Actor("Lee");
stan = new Actor("Stan");
knowsJB = new Knows();
knowsJB.setFirstActor(jim);
knowsJB.setSecondActor(bruce);
knowsJB.setSince(new Date());
jim.getKnows().add(knowsJB);
knowsJL = new Knows();
knowsJL.setFirstActor(jim);
knowsJL.setSecondActor(lee);
knowsJL.setSince(new Date());
jim.getKnows().add(knowsJL);
knowsLS = new Knows();
knowsLS.setFirstActor(lee);
knowsLS.setSecondActor(stan);
knowsLS.setSince(new Date());
lee.getKnows().add(knowsLS);
session.save(jim);
eventListener.clear();
}
use of org.neo4j.ogm.domain.cineasts.annotated.Knows in project neo4j-ogm by neo4j.
the class RelationshipEntityTest method shouldFireEventsWhenCreatingRelationshipEntity.
@Test
public void shouldFireEventsWhenCreatingRelationshipEntity() {
Knows knowsBS = new Knows();
knowsBS.setFirstActor(bruce);
knowsBS.setSecondActor(stan);
bruce.getKnows().add(knowsBS);
session.save(bruce);
assertThat(eventListener.captured(knowsBS, Event.TYPE.PRE_SAVE)).isTrue();
assertThat(((PreSaveEvent) eventListener.get(knowsBS, Event.TYPE.PRE_SAVE)).isNew()).isTrue();
assertThat(eventListener.captured(knowsBS, Event.TYPE.POST_SAVE)).isTrue();
assertThat(((PostSaveEvent) eventListener.get(knowsBS, Event.TYPE.POST_SAVE)).wasNew()).isTrue();
assertThat(eventListener.captured(bruce, Event.TYPE.PRE_SAVE)).isTrue();
assertThat(((PreSaveEvent) eventListener.get(bruce, Event.TYPE.PRE_SAVE)).isNew()).isFalse();
assertThat(eventListener.captured(bruce, Event.TYPE.POST_SAVE)).isTrue();
assertThat(((PostSaveEvent) eventListener.get(bruce, Event.TYPE.POST_SAVE)).wasNew()).isFalse();
assertThat(eventListener.captured(stan, Event.TYPE.PRE_SAVE)).isTrue();
assertThat(((PreSaveEvent) eventListener.get(stan, Event.TYPE.PRE_SAVE)).isNew()).isFalse();
assertThat(eventListener.captured(stan, Event.TYPE.POST_SAVE)).isTrue();
assertThat(((PostSaveEvent) eventListener.get(stan, Event.TYPE.POST_SAVE)).wasNew()).isFalse();
assertThat(eventListener.count()).isEqualTo(6);
}
use of org.neo4j.ogm.domain.cineasts.annotated.Knows in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldLoadRelationshipEntityWithSameStartEndNodeType.
// DATAGRAPH-616
@Test
public void shouldLoadRelationshipEntityWithSameStartEndNodeType() {
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);
session.clear();
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().getFirstActor().getName()).isEqualTo("Bruce");
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 SessionAndMappingContextTest method disposeFromMappingContextOnDeleteWithRelationshipEntityTest.
@Test
public void disposeFromMappingContextOnDeleteWithRelationshipEntityTest() {
long actorId = session.context().nativeId(actor1);
assertThat(session.context().getNodeEntity(actorId).getClass() == Actor.class).isTrue();
Object objectRel = session.context().getRelationshipEntity(knows.id);
assertThat(objectRel.getClass() == Knows.class).isTrue();
session.delete(actor1);
Result result = session.query("MATCH (n) RETURN n", Collections.EMPTY_MAP);
// check that the mapping context does not hold a reference to the deleted entity anymore
Object object = session.context().getNodeEntity(actorId);
assertThat(object == null).isTrue();
// check for a defined RelationshipEntity; the relationship should also be removed from the mappingContext
objectRel = session.context().getRelationshipEntity(knows.id);
assertThat(objectRel == null).isTrue();
assertThat(session.context().getNodeEntity(actorId) == null).isTrue();
// does it exist in the session?
Knows inSessionKnows = session.load(Knows.class, knows.id);
assertThat(inSessionKnows == null).isTrue();
// the other knows relationship should not have been deleted
Knows inSessionKnows2 = session.load(Knows.class, knows2.id);
assertThat(inSessionKnows2 != null).isTrue();
}
use of org.neo4j.ogm.domain.cineasts.annotated.Knows in project neo4j-ogm by neo4j.
the class SessionAndMappingContextTest method testEntityRelationshipProperlyRemoved.
@Test
public void testEntityRelationshipProperlyRemoved() {
session.delete(knows);
Knows testKnows = session.load(Knows.class, knows.id);
assertThat(testKnows == null).isTrue();
}
Aggregations