Search in sources :

Example 1 with Teacher

use of org.neo4j.ogm.domain.education.Teacher in project neo4j-ogm by neo4j.

the class EntityGraphMapperTest method testVariablePersistenceToDepthTwo.

@Test
public void testVariablePersistenceToDepthTwo() {
    School coalHillSchool = new School("Coal Hill");
    Teacher claraOswald = new Teacher("Clara Oswald");
    Teacher dannyPink = new Teacher("Danny Pink");
    Course english = new Course("English");
    Course maths = new Course("Maths");
    // do we need to set both sides?
    coalHillSchool.setTeachers(Arrays.asList(claraOswald, dannyPink));
    // do we need to set both sides?
    claraOswald.setCourses(Arrays.asList(english));
    dannyPink.setCourses(Arrays.asList(maths));
    session.save(coalHillSchool, 2);
    // we expect the school its teachers and the teachers courses to be persisted when persisting the school to depth 2
    session.clear();
    assertThat(session.query("MATCH" + "(school:School:DomainObject {name:'Coal Hill'}), " + "(clara:Teacher {name:'Clara Oswald'}), " + "(danny:Teacher {name:'Danny Pink'}), " + "(english:Course {name:'English'}), " + "(maths:Course {name:'Maths'}) " + "WHERE (school)-[:TEACHERS]->(clara)-[:SCHOOL]->(school) and " + "(school)-[:TEACHERS]->(danny)-[:SCHOOL]->(school) and " + "(danny)-[:COURSES]->(maths) and " + "(clara)-[:COURSES]->(english) return school, clara, danny, english, maths", emptyMap()).queryResults()).hasSize(1);
}
Also used : School(org.neo4j.ogm.domain.education.School) Teacher(org.neo4j.ogm.domain.education.Teacher) Course(org.neo4j.ogm.domain.education.Course) Test(org.junit.Test)

Example 2 with Teacher

use of org.neo4j.ogm.domain.education.Teacher in project neo4j-ogm by neo4j.

the class EntityGraphMapperTest method collectedListOfNodesFromPathsShouldNotCollapse.

// GH-902
@Test
@SuppressWarnings("unchecked")
public void collectedListOfNodesFromPathsShouldNotCollapse() {
    Teacher t = new Teacher("T0");
    School s = new School("Sß");
    Course c = new Course("C0");
    t.setSchool(s);
    t.setCourses(singletonList(c));
    Session writingSession = sessionFactory.openSession();
    writingSession.save(t);
    Result result = session.query("MATCH p=(:School) -[*]->(:Course) RETURN COLLECT (DISTINCT nodes(p)) AS paths", Collections.emptyMap());
    assertThat(result).hasSize(1).first().satisfies(row -> {
        Object nestedLists = row.get("paths");
        assertThat(nestedLists).isInstanceOf(List.class);
        assertThat((List<?>) nestedLists).hasSize(1).first().satisfies(v -> {
            assertThat(v).isInstanceOf(List.class);
            assertThat((List<?>) v).extracting(Object::getClass).extracting(Class::getSimpleName).containsExactly("School", "Teacher", "Course");
        });
    });
}
Also used : School(org.neo4j.ogm.domain.education.School) Teacher(org.neo4j.ogm.domain.education.Teacher) List(java.util.List) Course(org.neo4j.ogm.domain.education.Course) Session(org.neo4j.ogm.session.Session) Result(org.neo4j.ogm.model.Result) Test(org.junit.Test)

Example 3 with Teacher

use of org.neo4j.ogm.domain.education.Teacher in project neo4j-ogm by neo4j.

the class EntityGraphMapperTest method nestedListsWithDomainModel.

// GH-902
@Test
@SuppressWarnings("unchecked")
public void nestedListsWithDomainModel() {
    Session writingSession = sessionFactory.openSession();
    for (int i = 0; i < 2; ++i) {
        Teacher jim = new Teacher("T" + i);
        writingSession.save(jim);
    }
    Result result = session.query("match (m:Teacher) with collect(m) as x return collect(x) as listOfListsOfThings", Collections.emptyMap());
    assertThat(result).hasSize(1).first().satisfies(row -> {
        Object nestedLists = row.get("listOfListsOfThings");
        assertThat(nestedLists).isInstanceOf(List.class);
        assertThat((List<?>) nestedLists).hasSize(1).first().satisfies(EntityGraphMapperTest::assertContentOfList);
    });
}
Also used : Teacher(org.neo4j.ogm.domain.education.Teacher) List(java.util.List) Session(org.neo4j.ogm.session.Session) Result(org.neo4j.ogm.model.Result) Test(org.junit.Test)

Example 4 with Teacher

use of org.neo4j.ogm.domain.education.Teacher in project neo4j-ogm by neo4j.

the class EntityGraphMapperTest method nestedNestedLists.

// GH-902
@Test
@SuppressWarnings("unchecked")
public void nestedNestedLists() {
    Session writingSession = sessionFactory.openSession();
    for (int i = 0; i < 3; ++i) {
        Teacher jim = new Teacher("T" + i);
        writingSession.save(jim);
    }
    Result result = session.query("match (m:Teacher) where m.name = 'T0' or m.name = 'T1' with collect(m) as x \n" + "match (m:Teacher {name: \"T2\"}) with x, collect(m) as y\n" + "with [x,y] as x\n" + "return collect(x) as listOfListsOfThings", Collections.emptyMap());
    assertThat(result).hasSize(1).first().satisfies(row -> {
        Object nestedLists = row.get("listOfListsOfThings");
        assertThat(nestedLists).isInstanceOf(List.class);
        assertThat((List<?>) nestedLists).hasSize(1).first().satisfies(firstInnerList -> {
            assertThat(firstInnerList).isInstanceOf(List.class);
            assertThat((List<List<?>>) firstInnerList).hasSize(2).satisfies(EntityGraphMapperTest::assertContentOfList, Index.atIndex(0)).satisfies(l -> assertThat(l).hasSize(1).extracting(v -> ((Teacher) v).getName()).containsExactly("T2"), Index.atIndex(1));
        });
    });
}
Also used : Teacher(org.neo4j.ogm.domain.education.Teacher) List(java.util.List) Session(org.neo4j.ogm.session.Session) Result(org.neo4j.ogm.model.Result) Test(org.junit.Test)

Example 5 with Teacher

use of org.neo4j.ogm.domain.education.Teacher in project neo4j-ogm by neo4j.

the class EntityGraphMapperTest method testVariablePersistenceToDepthOne.

@Test
public void testVariablePersistenceToDepthOne() {
    School coalHillSchool = new School("Coal Hill");
    Teacher claraOswald = new Teacher("Clara Oswald");
    Teacher dannyPink = new Teacher("Danny Pink");
    Course english = new Course("English");
    Course maths = new Course("Maths");
    // do we need to set both sides?
    coalHillSchool.setTeachers(Arrays.asList(claraOswald, dannyPink));
    // do we need to set both sides?
    claraOswald.setCourses(Arrays.asList(english));
    dannyPink.setCourses(Arrays.asList(maths));
    session.save(coalHillSchool, 1);
    // we ONLY expect the school and its teachers to be persisted when persisting the school to depth 1
    session.clear();
    assertThat(session.query("MATCH " + "(s:School:DomainObject {name:'Coal Hill'}), " + "(c:Teacher {name:'Clara Oswald'}), " + "(d:Teacher {name:'Danny Pink'}) " + "WHERE (s)-[:TEACHERS]->(c) and " + "(s)-[:TEACHERS]->(d) return s,c,d", emptyMap())).hasSize(1);
    assertThat(session.query("MATCH (c:Course) return c", emptyMap())).hasSize(0);
}
Also used : School(org.neo4j.ogm.domain.education.School) Teacher(org.neo4j.ogm.domain.education.Teacher) Course(org.neo4j.ogm.domain.education.Course) Test(org.junit.Test)

Aggregations

Teacher (org.neo4j.ogm.domain.education.Teacher)25 Test (org.junit.Test)24 School (org.neo4j.ogm.domain.education.School)12 Course (org.neo4j.ogm.domain.education.Course)9 List (java.util.List)6 Student (org.neo4j.ogm.domain.education.Student)6 MappedRelationship (org.neo4j.ogm.context.MappedRelationship)4 Result (org.neo4j.ogm.model.Result)4 Statement (org.neo4j.ogm.request.Statement)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Session (org.neo4j.ogm.session.Session)3 Map (java.util.Map)2 RowStatementFactory (org.neo4j.ogm.session.request.RowStatementFactory)2 HashSet (java.util.HashSet)1 TeachesAt (org.neo4j.ogm.domain.education.TeachesAt)1