use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class DualTargetEntityRelationshipTest method shouldKeepAllRelations.
// DATAGRAPH-690
@Test
public void shouldKeepAllRelations() {
Category category = new Category("cat1");
Tag tag1 = new Tag("tag1");
Set<Tag> tags = new HashSet<>();
tags.add(tag1);
Event event = new Event("title");
event.setCategory(category);
event.setTags(tags);
session.save(event);
assertThat(event.getNodeId()).isNotNull();
assertThat(category.getNodeId()).isNotNull();
assertThat(tag1.getNodeId()).isNotNull();
session.clear();
Collection<Tag> tagsFound = session.loadAll(Tag.class, new Filter("name", ComparisonOperator.EQUALS, "tag1"));
assertThat(tagsFound).hasSize(1);
event.setTags(new HashSet<>(tagsFound));
Collection<Category> categoriesFound = session.loadAll(Category.class, new Filter("name", ComparisonOperator.EQUALS, "cat1"));
assertThat(categoriesFound).hasSize(1);
event.setCategory(categoriesFound.iterator().next());
assertThat(event.getTags().iterator().next()).isEqualTo(tag1);
assertThat(event.getCategory()).isEqualTo(category);
session.save(event);
session.clear();
Event eventFound = session.load(Event.class, event.getNodeId(), 1);
assertThat(eventFound.getNodeId()).isNotNull();
assertThat(eventFound.getCategory()).isEqualTo(category);
assertThat(eventFound.getTags().iterator().next()).isEqualTo(tag1);
}
use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class MultipleRelationshipsTest method shouldMapFromGraphToEntitiesCorrectly.
/**
* @see DATAGRAPH-636
*/
@Test
public void shouldMapFromGraphToEntitiesCorrectly() {
session.query("create (_5:`PersonX` {`name`:\"Jim\"})\n" + "create (_6:`PersonX` {`name`:\"Mary\"})\n" + "create (_7:`PersonX` {`name`:\"Bill\"})\n" + "create (_8:`Movie` {`name`:\"Die Hard\"})\n" + "create (_9:`Movie` {`name`:\"The Matrix\"})\n" + "create (_5)-[:`FOLLOWS`]->(_6)\n" + "create (_5)-[:`LIKES`]->(_6)\n" + "create (_5)-[:`RATED` {`value`:4}]->(_9)\n" + "create (_5)-[:`RATED` {`value`:5}]->(_8)\n" + "create (_6)-[:`FOLLOWS`]->(_5)\n" + "create (_6)-[:`FOLLOWS`]->(_7)\n" + "create (_6)-[:`LIKES`]->(_5)\n" + "create (_6)-[:`RATED` {`value`:5}]->(_8)\n" + "create (_7)-[:`FOLLOWS`]->(_5)\n" + "create (_7)-[:`LIKES`]->(_6)\n" + "create (_7)-[:`RATED` {`value`:4}]->(_9)\n" + "create (_7)-[:`RATED` {`value`:5}]->(_9)\n" + ";\n", Collections.EMPTY_MAP);
Person jim = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "Jim")).iterator().next();
assertThat(jim.movieRatings).hasSize(2);
assertThat(jim.peopleILike).hasSize(1);
assertThat(jim.peopleWhoLikeMe).hasSize(1);
assertThat(jim.peopleIFollow).hasSize(1);
assertThat(jim.peopleWhoFollowMe).hasSize(2);
assertThat(jim.peopleILike.get(0).name).isEqualTo("Mary");
Person bill = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "Bill")).iterator().next();
assertThat(bill.movieRatings).hasSize(2);
assertThat(bill.peopleILike).hasSize(1);
assertThat(bill.peopleWhoLikeMe).isEmpty();
assertThat(bill.peopleIFollow).hasSize(1);
assertThat(bill.peopleWhoFollowMe).hasSize(1);
Person mary = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "Mary")).iterator().next();
Movie dieHard = session.loadAll(Movie.class, new Filter("name", ComparisonOperator.EQUALS, "Die Hard")).iterator().next();
Movie matrix = session.loadAll(Movie.class, new Filter("name", ComparisonOperator.EQUALS, "The Matrix")).iterator().next();
assertThat(mary.movieRatings).hasSize(1);
assertThat(mary.peopleILike).hasSize(1);
assertThat(mary.peopleWhoLikeMe).hasSize(2);
assertThat(mary.peopleIFollow).hasSize(2);
assertThat(mary.peopleWhoFollowMe).hasSize(1);
assertThat(matrix.ratings).hasSize(3);
assertThat(dieHard.ratings).hasSize(2);
}
use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class EducationIntegrationTest method loadingCourseByPropertyShouldNotLoadOtherEntitiesWithSamePropertyValue.
@Test
public void loadingCourseByPropertyShouldNotLoadOtherEntitiesWithSamePropertyValue() {
// create a course
Course course = new Course("CompSci");
// create a student with the same name as the course
Student student = new Student("CompSci");
// relate them so they're both in the mappingContext
course.setStudents(Collections.singletonList(student));
session.save(course);
// fetch Courses by name
Collection<Course> courses = session.loadAll(Course.class, new Filter("name", ComparisonOperator.EQUALS, "CompSci"));
assertThat(courses).hasSize(1);
assertThat(courses.iterator().next()).isEqualTo(course);
assertThat(courses.iterator().next().getStudents()).hasSize(1);
}
use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class TreeIntegrationTest method shouldMapElementsToTreeSetProperly.
// GH-88
@Test
public void shouldMapElementsToTreeSetProperly() {
String cypher = "CREATE (parent:Entity {name:'parent'}) CREATE (child1:Entity {name:'c1'}) CREATE (child2:Entity {name:'c2'}) CREATE (child1)-[:REL]->(parent) CREATE (child2)-[:REL]->(parent)";
session.query(cypher, Collections.emptyMap());
session.clear();
Entity parent = session.loadAll(Entity.class, new Filter("name", ComparisonOperator.EQUALS, "parent")).iterator().next();
assertThat(parent).isNotNull();
assertThat(parent.getChildren()).hasSize(2);
assertThat(parent.getParent()).isNull();
List<String> childNames = new ArrayList<>();
for (Entity child : parent.getChildren()) {
childNames.add(child.getName());
assertThat(child.getParent().getName()).isEqualTo(parent.getName());
}
assertThat(childNames.get(0)).isEqualTo("c1");
assertThat(childNames.get(1)).isEqualTo("c2");
}
use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class ConvertibleIntegrationTest method shouldSaveAndRetrieveEnums.
// DATAGRAPH-550
@Test
public void shouldSaveAndRetrieveEnums() {
List<Education> completed = new ArrayList<>();
completed.add(Education.HIGHSCHOOL);
completed.add(Education.BACHELORS);
Person person = new Person();
person.setName("luanne");
person.setInProgressEducation(new Education[] { Education.MASTERS, Education.PHD });
person.setCompletedEducation(completed);
person.setGender(Gender.FEMALE);
session.save(person);
Person luanne = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "luanne")).iterator().next();
assertThat(luanne.getGender()).isEqualTo(Gender.FEMALE);
assertThat(luanne.getCompletedEducation().contains(Education.HIGHSCHOOL)).isTrue();
assertThat(luanne.getCompletedEducation().contains(Education.BACHELORS)).isTrue();
assertThat(luanne.getInProgressEducation().length).isEqualTo(2);
assertThat(luanne.getInProgressEducation()[0].equals(Education.MASTERS) || luanne.getInProgressEducation()[1].equals(Education.MASTERS)).isTrue();
assertThat(luanne.getInProgressEducation()[0].equals(Education.PHD) || luanne.getInProgressEducation()[1].equals(Education.PHD)).isTrue();
}
Aggregations