Skip to content

Commit

Permalink
Add failing test for filter and pagination, reproduce #384
Browse files Browse the repository at this point in the history
  • Loading branch information
frant-hartm committed Jul 8, 2017
1 parent d87cd36 commit 39a5203
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package org.neo4j.ogm.persistence.examples.cineasts.annotated;

import static com.google.common.collect.Sets.newHashSet;
import static org.junit.Assert.*;

import java.net.MalformedURLException;
Expand All @@ -24,6 +25,7 @@
import org.junit.Test;
import org.neo4j.ogm.cypher.ComparisonOperator;
import org.neo4j.ogm.cypher.Filter;
import org.neo4j.ogm.cypher.query.Pagination;
import org.neo4j.ogm.cypher.query.SortOrder;
import org.neo4j.ogm.domain.cineasts.annotated.*;
import org.neo4j.ogm.session.Session;
Expand Down Expand Up @@ -803,6 +805,59 @@ public void shouldBeAbleToSetREPropertiesToNull() throws MalformedURLException {
assertNull(movie.getRatings().iterator().next().getComment());
}

@Test
public void testFilterOnRelationshipEntity() throws Exception {
Movie pulpFiction = new Movie("Pulp Fiction", 1994);

Movie ootf = new Movie("Harry Potter and the Order of the Phoenix", 2009);

User frantisek = new User();
frantisek.setName("Frantisek");
frantisek.setLogin("frantisek");

Rating pulpRating = new Rating();
pulpRating.setStars(3);
pulpRating.setMovie(pulpFiction);
pulpRating.setUser(frantisek);
pulpFiction.setRatings(newHashSet(pulpRating));

Rating ootfRating = new Rating();
ootfRating.setStars(3);
ootfRating.setMovie(ootf);
ootfRating.setUser(frantisek);

frantisek.setRatings(newHashSet(ootfRating, pulpRating));

User otto = new User();
otto.setName("Otto");
otto.setLogin("otto");

Rating pulpRating2 = new Rating();
pulpRating2.setStars(3);
pulpRating2.setMovie(pulpFiction);
pulpRating2.setUser(otto);

Rating ootfRating2 = new Rating();
ootfRating2.setStars(3);
ootfRating2.setMovie(ootf);
ootfRating2.setUser(otto);

pulpFiction.setRatings(newHashSet(pulpRating, pulpRating2));
ootf.setRatings(newHashSet(ootfRating, ootfRating2));
otto.setRatings(newHashSet(pulpRating2, ootfRating2));
session.save(otto);

session.clear();

Filter filter = new Filter("stars", ComparisonOperator.EQUALS, 3);
filter.setNestedPropertyName("ratings");
filter.setNestedPropertyType(Rating.class);
filter.setNestedRelationshipEntity(true);
Collection<User> users = session.loadAll(User.class, filter, new Pagination(0, 2));

assertEquals(2, users.size());
}

private void bootstrap(String cqlFileName) {
session.query(TestUtils.readCQLFile(cqlFileName).toString(), Utils.map());
}
Expand Down

0 comments on commit 39a5203

Please sign in to comment.