use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class RestaurantIntegrationTest method shouldQueryByDistanceUsingFilter.
@Test
public void shouldQueryByDistanceUsingFilter() {
Restaurant restaurant = new Restaurant("San Francisco International Airport (SFO)", new Location(37.61649, -122.38681), 94128);
session.save(restaurant);
session.clear();
Filter filter = new Filter(new DistanceComparison(new DistanceFromPoint(37.61649, -122.38681, 1000 * 1000.0)), ComparisonOperator.LESS_THAN);
Collection<Restaurant> found = session.loadAll(Restaurant.class, filter);
assertThat(found).isNotNull();
assertThat(found.size() >= 1).isTrue();
}
use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class RestaurantIntegrationTest method shouldFilterByPropertyExists.
/**
* @see DATAGRAPH-904
*/
@Test
public void shouldFilterByPropertyExists() {
Restaurant sfo = new Restaurant("San Francisco International Airport (SFO)", 72.4);
sfo.setLaunchDate(new Date(1000));
session.save(sfo);
Restaurant kuroda = new Restaurant("Kuroda", 80.5);
kuroda.setLaunchDate(new Date(2000));
session.save(kuroda);
Filter exists = new Filter("name", ComparisonOperator.EXISTS);
Collection<Restaurant> results = session.loadAll(Restaurant.class, new Filters().add(exists));
assertThat(results).isNotNull();
assertThat(results).hasSize(2);
Filter notExists = new Filter("name", ComparisonOperator.EXISTS);
notExists.setNegated(true);
results = session.loadAll(Restaurant.class, new Filters().add(notExists));
assertThat(results).isNotNull();
assertThat(results).isEmpty();
}
use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class SocialIntegrationTest method shouldSaveIncomingKnownMortals.
/**
* @see DATAGRAPH-594
*/
@Test
public void shouldSaveIncomingKnownMortals() {
Mortal mortalA = new Mortal("A");
Mortal mortalB = new Mortal("B");
Mortal mortalC = new Mortal("C");
Mortal mortalD = new Mortal("D");
mortalA.getKnownBy().add(mortalB);
mortalA.getKnownBy().add(mortalC);
mortalD.getKnownBy().add(mortalA);
session.save(mortalA);
session.save(mortalB);
session.save(mortalC);
session.save(mortalD);
session.clear();
mortalA = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "A")).iterator().next();
assertThat(mortalA).isNotNull();
assertThat(mortalA.getKnownBy()).hasSize(2);
mortalB = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "B")).iterator().next();
assertThat(mortalB).isNotNull();
assertThat(mortalB.getKnownBy()).isEmpty();
mortalC = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "C")).iterator().next();
assertThat(mortalC).isNotNull();
assertThat(mortalC.getKnownBy()).isEmpty();
mortalD = session.loadAll(Mortal.class, new Filter("name", ComparisonOperator.EQUALS, "D")).iterator().next();
assertThat(mortalD).isNotNull();
assertThat(mortalD.getKnownBy()).hasSize(1);
assertThat(mortalD.getKnownBy().iterator().next().getName()).isEqualTo("A");
}
use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class SocialIntegrationTest method shouldFetchOnlyPeopleILike.
/**
* @see DATAGRAPH-594
*/
@Test
public void shouldFetchOnlyPeopleILike() {
session.query("create (p1:Person {name:'A'}) create (p2:Person {name:'B'}) create (p3:Person {name:'C'})" + " create (p4:Person {name:'D'}) create (p1)-[:LIKES]->(p2) create (p1)-[:LIKES]->(p3) create (p4)-[:LIKES]->(p1)", Collections.EMPTY_MAP);
Person personA = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "A")).iterator().next();
assertThat(personA).isNotNull();
assertThat(personA.getPeopleILike()).hasSize(2);
Person personD = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "D")).iterator().next();
assertThat(personD).isNotNull();
assertThat(personD.getPeopleILike()).hasSize(1);
assertThat(personD.getPeopleILike().get(0)).isEqualTo(personA);
}
use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class SocialIntegrationTest method shouldSaveUndirectedFriendsInBothDirections.
/**
* @see DATAGRAPH-594
*/
@Test
public void shouldSaveUndirectedFriendsInBothDirections() {
Person userA = new Person("A");
Person userB = new Person("B");
userA.getPeopleILike().add(userB);
userB.getPeopleILike().add(userA);
session.save(userA);
session.clear();
userA = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "A")).iterator().next();
assertThat(userA).isNotNull();
assertThat(userA.getPeopleILike()).hasSize(1);
session.clear();
userB = session.loadAll(Person.class, new Filter("name", ComparisonOperator.EQUALS, "B")).iterator().next();
assertThat(userB).isNotNull();
assertThat(userB.getPeopleILike()).hasSize(1);
}
Aggregations