Search in sources :

Example 6 with Restaurant

use of org.neo4j.ogm.domain.restaurant.Restaurant in project neo4j-ogm by neo4j.

the class RestaurantIntegrationTest method shouldSaveRestaurantWithCompositeLocationConverter.

@Test
public void shouldSaveRestaurantWithCompositeLocationConverter() {
    Restaurant restaurant = new Restaurant("San Francisco International Airport (SFO)", new Location(37.61649, -122.38681), 94128);
    session.save(restaurant);
    session.clear();
    assertThat(session.query("MATCH (n:`Restaurant` {name: 'San Francisco International Airport (SFO)', latitude: 37.61649, " + "longitude: -122.38681, zip: 94128, score: 0.0, halal: false, specialities:[]}) return n", emptyMap()).queryResults()).hasSize(1);
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Location(org.neo4j.ogm.domain.restaurant.Location) Test(org.junit.Test)

Example 7 with Restaurant

use of org.neo4j.ogm.domain.restaurant.Restaurant in project neo4j-ogm by neo4j.

the class RestaurantIntegrationTest method saveAndRetrieveRestaurantWithLocation.

@Test
public void saveAndRetrieveRestaurantWithLocation() {
    Restaurant restaurant = new Restaurant("San Francisco International Airport (SFO)", new Location(37.61649, -122.38681), 94128);
    session.save(restaurant);
    session.clear();
    Collection<Restaurant> results = session.loadAll(Restaurant.class, new Filter("name", ComparisonOperator.EQUALS, "San Francisco International Airport (SFO)"));
    assertThat(results).hasSize(1);
    Restaurant result = results.iterator().next();
    assertThat(result.getLocation()).isNotNull();
    assertThat(result.getLocation().getLatitude()).isCloseTo(37.61649, within(0d));
    assertThat(result.getLocation().getLongitude()).isCloseTo(-122.38681, within(0d));
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Filter(org.neo4j.ogm.cypher.Filter) Location(org.neo4j.ogm.domain.restaurant.Location) Test(org.junit.Test)

Example 8 with Restaurant

use of org.neo4j.ogm.domain.restaurant.Restaurant in project neo4j-ogm by neo4j.

the class RestaurantIntegrationTest method shouldProvideUniqueParameterNamesForFilters.

/**
 * @see issue #137
 */
@Test
public void shouldProvideUniqueParameterNamesForFilters() {
    Restaurant restaurant = new Restaurant();
    restaurant.setName("La Cocina De Flaming Lips");
    session.save(restaurant);
    Restaurant another = new Restaurant();
    another.setName("Antica Pesa");
    session.save(another);
    Filters filters = new Filters();
    Filter firstFilter = new Filter("name", ComparisonOperator.EQUALS, "Foobar");
    firstFilter.setBooleanOperator(BooleanOperator.OR);
    filters.add(firstFilter);
    Filter secondFilter = new Filter("name", ComparisonOperator.EQUALS, "Antica Pesa");
    secondFilter.setBooleanOperator(BooleanOperator.OR);
    filters.add(secondFilter);
    Collection<Restaurant> results = session.loadAll(Restaurant.class, filters);
    assertThat(results.size() >= 1).isTrue();
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Test(org.junit.Test)

Example 9 with Restaurant

use of org.neo4j.ogm.domain.restaurant.Restaurant in project neo4j-ogm by neo4j.

the class RestaurantIntegrationTest method shouldFilterByCollectionContaining.

@Test
public void shouldFilterByCollectionContaining() {
    Restaurant sfo = new Restaurant("San Francisco International Airport (SFO)", 72.4);
    sfo.getSpecialities().add("burger");
    sfo.getSpecialities().add("pizza");
    session.save(sfo);
    Restaurant kuroda = new Restaurant("Kuroda", 80.5);
    kuroda.getSpecialities().add("sushi");
    session.save(kuroda);
    Filter f1 = new Filter("specialities", new ContainsAnyComparison(Arrays.asList("burger")));
    Collection<Restaurant> burgers = session.loadAll(Restaurant.class, new Filters(f1));
    assertThat(burgers).hasSize(1);
    assertThat(burgers.iterator().next().getName()).isEqualTo("San Francisco International Airport (SFO)");
    Filter f2 = new Filter("specialities", new ContainsAnyComparison(Arrays.asList("burger", "sushi")));
    Collection<Restaurant> all = session.loadAll(Restaurant.class, new Filters(f2));
    assertThat(all).hasSize(2);
    Filter f3 = new Filter("specialities", new ContainsAnyComparison(Arrays.asList("sushi", "other")));
    Collection<Restaurant> sushi = session.loadAll(Restaurant.class, new Filters(f3));
    assertThat(sushi).hasSize(1);
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) ContainsAnyComparison(org.neo4j.ogm.cypher.function.ContainsAnyComparison) Test(org.junit.Test)

Example 10 with Restaurant

use of org.neo4j.ogm.domain.restaurant.Restaurant 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();
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) DistanceComparison(org.neo4j.ogm.cypher.function.DistanceComparison) DistanceFromPoint(org.neo4j.ogm.cypher.function.DistanceFromPoint) Filter(org.neo4j.ogm.cypher.Filter) Location(org.neo4j.ogm.domain.restaurant.Location) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 Restaurant (org.neo4j.ogm.domain.restaurant.Restaurant)18 Filter (org.neo4j.ogm.cypher.Filter)12 Filters (org.neo4j.ogm.cypher.Filters)10 Location (org.neo4j.ogm.domain.restaurant.Location)7 Date (java.util.Date)6 Branch (org.neo4j.ogm.domain.restaurant.Branch)3 Franchise (org.neo4j.ogm.domain.restaurant.Franchise)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ContainsAnyComparison (org.neo4j.ogm.cypher.function.ContainsAnyComparison)1 DistanceComparison (org.neo4j.ogm.cypher.function.DistanceComparison)1 DistanceFromPoint (org.neo4j.ogm.cypher.function.DistanceFromPoint)1