Search in sources :

Example 1 with PostSaveEvent

use of org.neo4j.ogm.session.event.PostSaveEvent 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 2 with PostSaveEvent

use of org.neo4j.ogm.session.event.PostSaveEvent in project neo4j-ogm by neo4j.

the class NodeEntityTest method shouldFireEventsWhenCreatingNewEntity.

@Test
public void shouldFireEventsWhenCreatingNewEntity() {
    Document e = new Document();
    e.setName("e");
    session.save(e);
    assertThat(eventListener.count()).isEqualTo(2);
    Event captured = eventListener.get(e, Event.TYPE.PRE_SAVE);
    assertThat(captured).isNotNull();
    assertThat(((PreSaveEvent) captured).isNew()).isTrue();
    captured = eventListener.get(e, Event.TYPE.POST_SAVE);
    assertThat(captured).isNotNull();
    assertThat(((PostSaveEvent) captured).wasNew()).isTrue();
}
Also used : PostSaveEvent(org.neo4j.ogm.session.event.PostSaveEvent) Event(org.neo4j.ogm.session.event.Event) PreSaveEvent(org.neo4j.ogm.session.event.PreSaveEvent) PostSaveEvent(org.neo4j.ogm.session.event.PostSaveEvent) PreSaveEvent(org.neo4j.ogm.session.event.PreSaveEvent) Document(org.neo4j.ogm.domain.filesystem.Document) Test(org.junit.Test)

Example 3 with PostSaveEvent

use of org.neo4j.ogm.session.event.PostSaveEvent in project neo4j-ogm by neo4j.

the class NodeEntityTest method shouldFireEventsWhenUpdatingExistingEntity.

@Test
public void shouldFireEventsWhenUpdatingExistingEntity() {
    a.setName("newA");
    session.save(a);
    assertThat(eventListener.count()).isEqualTo(2);
    Event captured = eventListener.get(a, Event.TYPE.PRE_SAVE);
    assertThat(captured).isNotNull();
    assertThat(((PreSaveEvent) captured).isNew()).isFalse();
    captured = eventListener.get(a, Event.TYPE.POST_SAVE);
    assertThat(captured).isNotNull();
    assertThat(((PostSaveEvent) captured).wasNew()).isFalse();
}
Also used : PostSaveEvent(org.neo4j.ogm.session.event.PostSaveEvent) Event(org.neo4j.ogm.session.event.Event) PreSaveEvent(org.neo4j.ogm.session.event.PreSaveEvent) PostSaveEvent(org.neo4j.ogm.session.event.PostSaveEvent) PreSaveEvent(org.neo4j.ogm.session.event.PreSaveEvent) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 PostSaveEvent (org.neo4j.ogm.session.event.PostSaveEvent)3 PreSaveEvent (org.neo4j.ogm.session.event.PreSaveEvent)3 Event (org.neo4j.ogm.session.event.Event)2 Knows (org.neo4j.ogm.domain.cineasts.annotated.Knows)1 Document (org.neo4j.ogm.domain.filesystem.Document)1