Search in sources :

Example 1 with Document

use of org.neo4j.ogm.domain.filesystem.Document in project neo4j-ogm by neo4j.

the class AssociatedObjectsTest method shouldFireEventsWhenAddNewObjectInCollectionAndSaveCollection.

@Test
public void shouldFireEventsWhenAddNewObjectInCollectionAndSaveCollection() {
    // add a new document to an existing folder and save the document
    Document z = new Document();
    z.setFolder(folder);
    folder.getDocuments().add(z);
    session.save(folder);
    assertThat(eventListener.captured(z, Event.TYPE.PRE_SAVE)).isTrue();
    assertThat(eventListener.captured(z, Event.TYPE.POST_SAVE)).isTrue();
    assertThat(eventListener.captured(folder, Event.TYPE.PRE_SAVE)).isTrue();
    assertThat(eventListener.captured(folder, Event.TYPE.POST_SAVE)).isTrue();
    assertThat(eventListener.count()).isEqualTo(4);
}
Also used : Document(org.neo4j.ogm.domain.filesystem.Document) Test(org.junit.Test)

Example 2 with Document

use of org.neo4j.ogm.domain.filesystem.Document in project neo4j-ogm by neo4j.

the class AssociatedObjectsTest method shouldFireEventsWhenAddNewObjectToCollectionAndSaveNewObject.

@Test
public void shouldFireEventsWhenAddNewObjectToCollectionAndSaveNewObject() {
    // add a new document to an existing folder and save the document
    Document z = new Document();
    z.setFolder(folder);
    folder.getDocuments().add(z);
    session.save(z);
    assertThat(eventListener.captured(z, Event.TYPE.PRE_SAVE)).isTrue();
    assertThat(eventListener.captured(z, Event.TYPE.POST_SAVE)).isTrue();
    assertThat(eventListener.captured(folder, Event.TYPE.PRE_SAVE)).isTrue();
    assertThat(eventListener.captured(folder, Event.TYPE.POST_SAVE)).isTrue();
    assertThat(eventListener.count()).isEqualTo(4);
}
Also used : Document(org.neo4j.ogm.domain.filesystem.Document) Test(org.junit.Test)

Example 3 with Document

use of org.neo4j.ogm.domain.filesystem.Document 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 4 with Document

use of org.neo4j.ogm.domain.filesystem.Document in project neo4j-ogm by neo4j.

the class NodeEntityTest method shouldNotFireEventsWhenDeletingNonPersistedObject.

@Test
public void shouldNotFireEventsWhenDeletingNonPersistedObject() {
    Document unpersistedDocument = new Document();
    session.delete(unpersistedDocument);
    assertThat(eventListener.count()).isEqualTo(0);
}
Also used : Document(org.neo4j.ogm.domain.filesystem.Document) Test(org.junit.Test)

Example 5 with Document

use of org.neo4j.ogm.domain.filesystem.Document in project neo4j-ogm by neo4j.

the class DegenerateEntityModelTests method testSaveChangedFolder.

@Test
public void testSaveChangedFolder() {
    Document c = new Document();
    c.setName("c");
    f.getDocuments().add(c);
    f.getDocuments().remove(a);
    session.save(f);
    session.clear();
    assertThat(session.query("MATCH (f:Folder { name: 'f' }), " + "(a:Document { name: 'a' } ), " + "(b:Document { name: 'b' } ), " + "(c:Document { name: 'c' } ) " + "WHERE (f)-[:CONTAINS]->(b) and " + "(f)-[:CONTAINS]->(c) return f, a, b, c", emptyMap()).queryResults()).hasSize(1);
}
Also used : Document(org.neo4j.ogm.domain.filesystem.Document) Test(org.junit.Test)

Aggregations

Document (org.neo4j.ogm.domain.filesystem.Document)26 Test (org.junit.Test)23 Folder (org.neo4j.ogm.domain.filesystem.Folder)11 Compiler (org.neo4j.ogm.cypher.compiler.Compiler)7 RowStatementFactory (org.neo4j.ogm.session.request.RowStatementFactory)7 Statement (org.neo4j.ogm.request.Statement)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Before (org.junit.Before)3 MappedRelationship (org.neo4j.ogm.context.MappedRelationship)3 Date (java.util.Date)1 Map (java.util.Map)1 EntityGraphMapper (org.neo4j.ogm.context.EntityGraphMapper)1 Actor (org.neo4j.ogm.domain.cineasts.annotated.Actor)1 Knows (org.neo4j.ogm.domain.cineasts.annotated.Knows)1 SessionFactory (org.neo4j.ogm.session.SessionFactory)1 Event (org.neo4j.ogm.session.event.Event)1 PostSaveEvent (org.neo4j.ogm.session.event.PostSaveEvent)1 PreSaveEvent (org.neo4j.ogm.session.event.PreSaveEvent)1