use of org.neo4j.ogm.cypher.query.SortOrder in project neo4j-ogm by neo4j.
the class SatelliteIntegrationTest method shouldReturnSatellitesSortedByRefAsc.
@Test
public void shouldReturnSatellitesSortedByRefAsc() {
Collection<Satellite> satellites = session.loadAll(Satellite.class, new SortOrder().add("ref"));
Iterator<Satellite> iter = satellites.iterator();
Satellite first = iter.next();
while (iter.hasNext()) {
Satellite next = iter.next();
assertThat(first.getRef().compareTo(next.getRef()) < 0).isTrue();
first = next;
}
}
use of org.neo4j.ogm.cypher.query.SortOrder in project neo4j-ogm by neo4j.
the class MusicIntegrationTest method shouldSortByDomainPropertyName.
/**
* @see Issue 191
*/
@Test
public void shouldSortByDomainPropertyName() {
Studio emi = new Studio("EMI Studios, London");
Studio olympic = new Studio("Olympic Studios, London");
session.save(emi);
session.save(olympic);
session.clear();
SortOrder name = new SortOrder().add("name");
Collection<Studio> studios1 = session.loadAll(Studio.class, name);
Collection<Studio> studios2 = session.loadAll(Studio.class, name);
assertThat(studios1.iterator().next().getName()).isEqualTo("EMI Studios, London");
assertThat(studios2.iterator().next().getName()).isEqualTo("EMI Studios, London");
studios1 = session.loadAll(Studio.class, new SortOrder().add(SortOrder.Direction.DESC, "name"));
assertThat(studios1.iterator().next().getName()).isEqualTo("Olympic Studios, London");
}
use of org.neo4j.ogm.cypher.query.SortOrder in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldSortRatings.
@Test
public void shouldSortRatings() {
Movie movie = new Movie("Pulp Fiction", 1994);
session.save(movie);
User michal = new User();
michal.setName("Michal");
michal.setLogin("bachmania");
Rating awesome = new Rating();
awesome.setMovie(movie);
awesome.setUser(michal);
awesome.setStars(5);
michal.setRatings(Collections.singleton(awesome));
session.save(michal);
// Add a rating from luanne for the same movie
User luanne = new User();
luanne.setName("luanne");
luanne.setLogin("luanne");
luanne.setPassword("luanne");
Rating rating = new Rating();
rating.setMovie(movie);
rating.setUser(luanne);
rating.setStars(3);
luanne.setRatings(Collections.singleton(rating));
session.save(luanne);
session.clear();
Collection<Rating> ratings = session.loadAll(Rating.class, new SortOrder().add(SortOrder.Direction.ASC, "stars"));
assertThat(ratings).isNotNull();
int i = 0;
for (Rating r : ratings) {
if (i++ == 0) {
assertThat(r.getStars()).isEqualTo(3);
} else {
assertThat(r.getStars()).isEqualTo(5);
}
}
}
use of org.neo4j.ogm.cypher.query.SortOrder in project neo4j-ogm by neo4j.
the class LoadCapabilityTest method loadAllShouldRespectEntityType.
// DATAGRAPH-707
@Test
public void loadAllShouldRespectEntityType() {
Collection<Artist> artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId));
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
Collection<Album> albums = session.loadAll(Album.class, Collections.singletonList(beatlesId));
assertThat(albums).isEmpty();
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), 0);
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), 0);
assertThat(albums).isEmpty();
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"));
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"));
assertThat(albums).isEmpty();
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), 0);
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), 0);
assertThat(albums).isEmpty();
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new Pagination(0, 5));
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new Pagination(0, 5));
assertThat(albums).isEmpty();
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new Pagination(0, 5), 0);
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new Pagination(0, 5), 0);
assertThat(albums).isEmpty();
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5));
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5));
assertThat(albums).isEmpty();
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5), 0);
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo("The Beatles");
Artist bonJovi = new Artist("Bon Jovi");
session.save(bonJovi);
artists = session.loadAll(Artist.class, Arrays.asList(beatlesId, pleaseId, bonJovi.getId()), new SortOrder().add("name"), new Pagination(0, 5), 0);
assertThat(artists).hasSize(2);
artists = session.loadAll(Artist.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5), 0);
assertThat(artists).hasSize(1);
assertThat(artists.iterator().next().getName()).isEqualTo(// make sure Bon Jovi isn't returned as well
"The Beatles");
albums = session.loadAll(Album.class, Collections.singletonList(beatlesId), new SortOrder().add("name"), new Pagination(0, 5), 0);
assertThat(albums).isEmpty();
}
use of org.neo4j.ogm.cypher.query.SortOrder in project neo4j-ogm by neo4j.
the class LoadCapabilityTest method shouldKeepOrder.
// GH-368
@Test
public void shouldKeepOrder() {
User anna = new User("noone@nowhere.com", "Anna", "Doe");
User bob = new User("noone@nowhere.com", "Bob", "Doe");
User charlie = new User("noone@nowhere.com", "Charlie", "Doe");
session.save(charlie);
session.save(anna);
session.save(bob);
anna.setFriends(Collections.singleton(charlie));
session.save(anna);
Collection<User> allUsers = session.loadAll(User.class, new SortOrder().add("lastName").add("firstName"), 1);
assertThat(allUsers).extracting(User::getFirstName).containsExactly("Anna", "Bob", "Charlie");
}
Aggregations