use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class SocialIntegrationTest method shouldFetchFriendsInBothDirections.
/**
* @see DATAGRAPH-594
*/
@Test
public void shouldFetchFriendsInBothDirections() {
session.query("create (p1:Individual {name:'A'}) create (p2:Individual {name:'B'}) create (p3:Individual {name:'C'})" + " create (p4:Individual {name:'D'}) create (p1)-[:FRIENDS]->(p2) create (p1)-[:FRIENDS]->(p3) create (p4)-[:FRIENDS]->(p1)", Collections.EMPTY_MAP);
Individual individualA = session.loadAll(Individual.class, new Filter("name", ComparisonOperator.EQUALS, "A")).iterator().next();
assertThat(individualA).isNotNull();
assertThat(individualA.getFriends()).hasSize(2);
}
use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class IngredientsIntegrationTest method shouldBeAbleToLoadIngredientsWithFiltersPagingAndDepth.
/**
* @see Issue 97
*/
@Test
public void shouldBeAbleToLoadIngredientsWithFiltersPagingAndDepth() {
Ingredient chicken = new Ingredient("Chicken");
session.save(chicken);
Ingredient carrot = new Ingredient("Chicken");
session.save(carrot);
Ingredient butter = new Ingredient("Chicken");
session.save(butter);
Pairing pairing = new Pairing();
pairing.setFirst(chicken);
pairing.setSecond(carrot);
pairing.setAffinity("EXCELLENT");
carrot.addPairing(pairing);
session.save(chicken);
Pairing pairing2 = new Pairing();
pairing2.setFirst(chicken);
pairing2.setSecond(butter);
pairing2.setAffinity("EXCELLENT");
carrot.addPairing(pairing2);
session.save(chicken);
Pairing pairing3 = new Pairing();
pairing3.setFirst(carrot);
pairing3.setSecond(butter);
pairing3.setAffinity("EXCELLENT");
carrot.addPairing(pairing3);
session.save(carrot);
session.clear();
Collection<Ingredient> ingredients = session.loadAll(Ingredient.class, new Filter("name", ComparisonOperator.EQUALS, "Chicken"), new Pagination(0, 1));
assertThat(ingredients).hasSize(1);
session.clear();
ingredients = session.loadAll(Ingredient.class, new Filter("name", ComparisonOperator.EQUALS, "Chicken"), new Pagination(1, 1));
assertThat(ingredients).hasSize(1);
session.clear();
ingredients = session.loadAll(Ingredient.class, new Filter("name", ComparisonOperator.EQUALS, "Chicken"), new Pagination(0, 2));
assertThat(ingredients).hasSize(2);
ingredients = session.loadAll(Ingredient.class, new Filter("name", ComparisonOperator.EQUALS, "Chicken"), new Pagination(0, 3));
assertThat(ingredients).hasSize(3);
session.clear();
Collection<Pairing> pairings = session.loadAll(Pairing.class, new Filter("affinity", ComparisonOperator.EQUALS, "EXCELLENT"), new Pagination(0, 1));
assertThat(pairings).hasSize(1);
session.clear();
pairings = session.loadAll(Pairing.class, new Filter("affinity", ComparisonOperator.EQUALS, "EXCELLENT"), new Pagination(1, 1));
assertThat(pairings).hasSize(1);
session.clear();
pairings = session.loadAll(Pairing.class, new Filter("affinity", ComparisonOperator.EQUALS, "EXCELLENT"), new Pagination(0, 2));
assertThat(pairings).hasSize(2);
pairings = session.loadAll(Pairing.class, new Filter("affinity", ComparisonOperator.EQUALS, "EXCELLENT"), new Pagination(0, 3));
assertThat(pairings).hasSize(3);
}
use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class MusicIntegrationTest method shouldSaveAndRetrieveEntitiesWithInvalidCharsInLabelsAndRels.
/**
* @see DATAGRAPH-589
*/
@Test
public void shouldSaveAndRetrieveEntitiesWithInvalidCharsInLabelsAndRels() {
Studio emi = new Studio("EMI Studios, London");
Artist theBeatles = new Artist("The Beatles");
Album please = new Album("Please Please Me");
Recording pleaseRecording = new Recording(please, emi, 1963);
please.setRecording(pleaseRecording);
theBeatles.getAlbums().add(please);
please.setArtist(theBeatles);
session.save(theBeatles);
theBeatles = session.loadAll(Artist.class).iterator().next();
assertThat(theBeatles.getName()).isEqualTo("The Beatles");
assertThat(theBeatles.getAlbums()).hasSize(1);
assertThat(theBeatles.getAlbums().iterator().next().getName()).isEqualTo("Please Please Me");
assertThat(theBeatles.getAlbums().iterator().next().getRecording().getStudio().getName()).isEqualTo("EMI Studios, London");
please = session.loadAll(Album.class, new Filter("name", ComparisonOperator.EQUALS, "Please Please Me")).iterator().next();
assertThat(please.getArtist().getName()).isEqualTo("The Beatles");
Album hard = new Album("A Hard Day's Night");
hard.setArtist(theBeatles);
Recording hardRecording = new Recording(hard, emi, 1964);
hard.setRecording(hardRecording);
theBeatles.getAlbums().add(hard);
session.save(hard);
Collection<Album> albums = session.loadAll(Album.class);
assertThat(albums).hasSize(2);
for (Album album : albums) {
if (album.getName().equals("Please Please Me")) {
assertThat(album.getRecording().getYear()).isEqualTo(1963);
} else {
assertThat(album.getRecording().getYear()).isEqualTo(1964);
}
}
}
use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class CineastsIntegrationTest method nestedFilteringCanBeTheOneAndOnlyOredFilter.
@Test
public void nestedFilteringCanBeTheOneAndOnlyOredFilter() {
Filter filterB = new Filter("name", ComparisonOperator.EQUALS, "Catty");
filterB.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("pets", Pet.class));
filterB.setBooleanOperator(BooleanOperator.OR);
Filters filters = new Filters(filterB);
Collection<Movie> films = session.loadAll(Movie.class, filters);
assertThat(films).hasSize(2);
}
use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class CineastsIntegrationTest method loadFilmByRatingUsersPet.
@Test
public void loadFilmByRatingUsersPet() {
// Pulp Fiction and Top Gear rated by Michal who owns Catty
Filter filter = new Filter("name", ComparisonOperator.EQUALS, "Catty");
filter.setOwnerEntityType(Movie.class);
filter.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("pets", Pet.class));
Collection<Movie> films = session.loadAll(Movie.class, filter);
assertThat(films).hasSize(2);
}
Aggregations