Search in sources :

Example 1 with Knows

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();
}
Also used : Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Document(org.neo4j.ogm.domain.filesystem.Document) Folder(org.neo4j.ogm.domain.filesystem.Folder) Knows(org.neo4j.ogm.domain.cineasts.annotated.Knows) Date(java.util.Date) Before(org.junit.Before)

Example 2 with Knows

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);
}
Also used : PostSaveEvent(org.neo4j.ogm.session.event.PostSaveEvent) PreSaveEvent(org.neo4j.ogm.session.event.PreSaveEvent) Knows(org.neo4j.ogm.domain.cineasts.annotated.Knows) Test(org.junit.Test)

Example 3 with Knows

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");
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Knows(org.neo4j.ogm.domain.cineasts.annotated.Knows) Date(java.util.Date) Test(org.junit.Test)

Example 4 with Knows

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();
}
Also used : Knows(org.neo4j.ogm.domain.cineasts.annotated.Knows) Result(org.neo4j.ogm.model.Result) Test(org.junit.Test)

Example 5 with Knows

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();
}
Also used : Knows(org.neo4j.ogm.domain.cineasts.annotated.Knows) Test(org.junit.Test)

Aggregations

Knows (org.neo4j.ogm.domain.cineasts.annotated.Knows)9 Test (org.junit.Test)7 Actor (org.neo4j.ogm.domain.cineasts.annotated.Actor)6 Date (java.util.Date)4 Filter (org.neo4j.ogm.cypher.Filter)3 Before (org.junit.Before)2 Document (org.neo4j.ogm.domain.filesystem.Document)1 Folder (org.neo4j.ogm.domain.filesystem.Folder)1 Album (org.neo4j.ogm.domain.music.Album)1 Artist (org.neo4j.ogm.domain.music.Artist)1 Recording (org.neo4j.ogm.domain.music.Recording)1 Studio (org.neo4j.ogm.domain.music.Studio)1 Result (org.neo4j.ogm.model.Result)1 PostSaveEvent (org.neo4j.ogm.session.event.PostSaveEvent)1 PreSaveEvent (org.neo4j.ogm.session.event.PreSaveEvent)1 Transaction (org.neo4j.ogm.transaction.Transaction)1