Search in sources :

Example 1 with Folder

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

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

the class LifecycleTest method shouldSaveObjectUpdatedByPreSaveEventHandler.

@Test
public void shouldSaveObjectUpdatedByPreSaveEventHandler() {
    // not interested in the default one for this suite
    session.dispose(eventListener);
    session.register(uuidEventListener);
    Folder f = new Folder();
    f.setName("folder");
    assertThat(f.getUuid()).isNull();
    session.save(f);
    assertThat(f.getUuid()).isNotNull();
    session.clear();
    Folder f2 = session.load(Folder.class, f.getId());
    assertThat(f2.getName()).isNotNull();
    assertThat(f2.getUuid()).isNotNull();
}
Also used : Folder(org.neo4j.ogm.domain.filesystem.Folder) Test(org.junit.Test)

Example 3 with Folder

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

the class DegenerateEntityModelTests method testSaveChangedDocument.

@Test
public void testSaveChangedDocument() {
    // set a's f to a new f, but don't remove from the current f's list of documents
    a.setFolder(new Folder());
    a.getFolder().setName("g");
    session.save(a);
    session.clear();
    assertThat(session.query("MATCH (f:Folder { name: 'f' } ), " + "(g:Folder { name: 'g' } ), " + "(a:Document { name: 'a' }), " + "(b:Document { name: 'b' }) " + "WHERE (f)-[:CONTAINS]->(b) and" + "(g)-[:CONTAINS]->(a) return f, g, a, b", emptyMap()).queryResults()).hasSize(1);
}
Also used : Folder(org.neo4j.ogm.domain.filesystem.Folder) Test(org.junit.Test)

Example 4 with Folder

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

the class DirectRelationshipsTest method shouldBeAbleToRemoveAnyRegisteredRelationship.

@Test
public void shouldBeAbleToRemoveAnyRegisteredRelationship() {
    // given
    Folder folder = new Folder();
    Document doc1 = new Document();
    Document doc2 = new Document();
    folder.getDocuments().add(doc1);
    folder.getDocuments().add(doc2);
    doc1.setFolder(folder);
    doc2.setFolder(folder);
    folder.setId(0L);
    doc1.setId(1L);
    doc2.setId(2L);
    mappingContext.addNodeEntity(folder);
    mappingContext.addNodeEntity(doc1);
    mappingContext.addNodeEntity(doc2);
    mappingContext.addRelationship(new MappedRelationship(folder.getId(), "CONTAINS", doc1.getId(), null, Folder.class, Document.class));
    mappingContext.addRelationship(new MappedRelationship(folder.getId(), "CONTAINS", doc2.getId(), null, Folder.class, Document.class));
    // when
    doc2.setFolder(null);
    folder.getDocuments().remove(doc2);
    // then
    assertThat(folder.getDocuments()).hasSize(1);
    Compiler compiler = mapper.map(folder).getCompiler();
    compiler.useStatementFactory(new RowStatementFactory());
    List<Statement> statements = compiler.deleteRelationshipStatements();
    assertThat(statements).hasSize(1);
    assertThat(statements.get(0).getStatement()).isEqualTo("UNWIND $rows as row MATCH (startNode) WHERE ID(startNode) = row.startNodeId WITH row,startNode MATCH (endNode) WHERE ID(endNode) = row.endNodeId MATCH (startNode)-[rel:`CONTAINS`]->(endNode) DELETE rel");
    // we need to re-establish the relationship in the mapping context for this expectation, otherwise
    // the previous save will have de-registered the relationship.
    mappingContext.addRelationship(new MappedRelationship(folder.getId(), "CONTAINS", doc2.getId(), null, Folder.class, Document.class));
    compiler = mapper.map(doc1).getCompiler();
    compiler.useStatementFactory(new RowStatementFactory());
    statements = compiler.deleteRelationshipStatements();
    assertThat(statements).hasSize(1);
    assertThat(statements.get(0).getStatement()).isEqualTo("UNWIND $rows as row MATCH (startNode) WHERE ID(startNode) = row.startNodeId WITH row,startNode MATCH (endNode) WHERE ID(endNode) = row.endNodeId MATCH (startNode)-[rel:`CONTAINS`]->(endNode) DELETE rel");
    // we need to re-establish the relationship in the mapping context for this expectation, otherwise
    // the previous save will have de-registered the relationship.
    mappingContext.addRelationship(new MappedRelationship(folder.getId(), "CONTAINS", doc2.getId(), null, Folder.class, Document.class));
    compiler = mapper.map(doc2).getCompiler();
    compiler.useStatementFactory(new RowStatementFactory());
    statements = compiler.deleteRelationshipStatements();
    assertThat(statements).hasSize(1);
    assertThat(statements.get(0).getStatement()).isEqualTo("UNWIND $rows as row MATCH (startNode) WHERE ID(startNode) = row.startNodeId WITH row,startNode MATCH (endNode) WHERE ID(endNode) = row.endNodeId MATCH (startNode)-[rel:`CONTAINS`]->(endNode) DELETE rel");
}
Also used : Compiler(org.neo4j.ogm.cypher.compiler.Compiler) Statement(org.neo4j.ogm.request.Statement) MappedRelationship(org.neo4j.ogm.context.MappedRelationship) RowStatementFactory(org.neo4j.ogm.session.request.RowStatementFactory) Folder(org.neo4j.ogm.domain.filesystem.Folder) Document(org.neo4j.ogm.domain.filesystem.Document) Test(org.junit.Test)

Example 5 with Folder

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

the class AssociatedObjectsTest method shouldFireEventsWhenSetAssociatedObjectToNewAnonymousObject.

@Test
public void shouldFireEventsWhenSetAssociatedObjectToNewAnonymousObject() {
    a.setFolder(new Folder());
    folder.getDocuments().remove(a);
    session.save(a);
    // events for creation of new object
    assertThat(eventListener.captured(new Folder(), Event.TYPE.PRE_SAVE)).isTrue();
    assertThat(eventListener.captured(new Folder(), Event.TYPE.POST_SAVE)).isTrue();
    // events for update of a's folder relationship
    assertThat(eventListener.captured(a, Event.TYPE.PRE_SAVE)).isTrue();
    assertThat(eventListener.captured(a, Event.TYPE.POST_SAVE)).isTrue();
    // events for updates of folder's relationship to a
    assertThat(eventListener.captured(folder, Event.TYPE.PRE_SAVE)).isTrue();
    assertThat(eventListener.captured(folder, Event.TYPE.POST_SAVE)).isTrue();
    assertThat(eventListener.count()).isEqualTo(6);
}
Also used : Folder(org.neo4j.ogm.domain.filesystem.Folder) Test(org.junit.Test)

Aggregations

Folder (org.neo4j.ogm.domain.filesystem.Folder)15 Test (org.junit.Test)13 Document (org.neo4j.ogm.domain.filesystem.Document)10 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 MappedRelationship (org.neo4j.ogm.context.MappedRelationship)3 Before (org.junit.Before)2 Date (java.util.Date)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