Search in sources :

Example 11 with Restaurant

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

the class RestaurantIntegrationTest method shouldUpdateLabelsCorrectly.

@Test
public void shouldUpdateLabelsCorrectly() throws Exception {
    Franchise franchise = new Franchise();
    Restaurant r1 = new Restaurant();
    r1.setName("La Strada Tooting");
    r1.labels = Arrays.asList("Delicious", "Foreign");
    Restaurant r2 = new Restaurant();
    r2.setName("La Strada Brno");
    r2.labels = Arrays.asList("Average", "Foreign");
    franchise.addBranch(new Branch(new Location(0.0, 0.0), franchise, r1));
    franchise.addBranch(new Branch(new Location(0.0, 0.0), franchise, r2));
    session.save(franchise);
    // remove labels, different label for each entity
    r1.labels = Arrays.asList("Foreign");
    r2.labels = Arrays.asList("Foreign");
    session.save(franchise);
    session.clear();
    Restaurant loadedR1 = session.load(Restaurant.class, r1.getId());
    assertThat(loadedR1.labels).containsOnly("Foreign");
    Restaurant loadedR2 = session.load(Restaurant.class, r2.getId());
    assertThat(loadedR2.labels).containsOnly("Foreign");
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Branch(org.neo4j.ogm.domain.restaurant.Branch) Franchise(org.neo4j.ogm.domain.restaurant.Franchise) Location(org.neo4j.ogm.domain.restaurant.Location) Test(org.junit.Test)

Example 12 with Restaurant

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

the class RestaurantIntegrationTest method shouldSyncMappedLabelsFromEntityToTheNode_and_NodeToEntity.

/**
 * @see issue #159
 */
@Test
public void shouldSyncMappedLabelsFromEntityToTheNode_and_NodeToEntity() {
    Restaurant restaurant = new Restaurant();
    restaurant.setName("House of Mushroom & Pepperoni");
    List<String> labels = new ArrayList<>();
    labels.add("Delicious");
    labels.add("Ambiance");
    labels.add("Convenience");
    restaurant.labels = labels;
    session.save(restaurant);
    session.clear();
    Restaurant loaded = session.load(Restaurant.class, restaurant.getId());
    assertThat(loaded.labels.contains("Delicious")).isTrue();
    assertThat(loaded.labels.contains("Ambiance")).isTrue();
    assertThat(loaded.labels.contains("Convenience")).isTrue();
    assertThat(loaded.labels).hasSize(3);
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with Restaurant

use of org.neo4j.ogm.domain.restaurant.Restaurant 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();
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Date(java.util.Date) Test(org.junit.Test)

Example 14 with Restaurant

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

the class RestaurantIntegrationTest method shouldFilterByIsNullOrNotNull.

/**
 * @see DATAGRAPH-904
 */
@Test
public void shouldFilterByIsNullOrNotNull() {
    Restaurant kuroda = new Restaurant("Kuroda", "Mainly Ramen");
    session.save(kuroda);
    Restaurant cyma = new Restaurant();
    cyma.setName("Cyma");
    session.save(cyma);
    session.clear();
    Filter descriptionIsNull = new Filter("description", ComparisonOperator.IS_NULL, null);
    Collection<Restaurant> results = session.loadAll(Restaurant.class, new Filters().add(descriptionIsNull));
    assertThat(results).hasSize(1);
    Restaurant restaurant = results.iterator().next();
    assertThat(restaurant.getName()).isEqualTo("Cyma");
    Filter descriptionIsNotNull = new Filter("description", ComparisonOperator.IS_NULL, null);
    descriptionIsNotNull.setNegated(true);
    results = session.loadAll(Restaurant.class, new Filters().add(descriptionIsNotNull));
    assertThat(results).hasSize(1);
    restaurant = results.iterator().next();
    assertThat(restaurant.getName()).isEqualTo("Kuroda");
}
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 15 with Restaurant

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

the class RestaurantIntegrationTest method shouldSaveBranchWitlCompositeLocationConverter.

@Test
public void shouldSaveBranchWitlCompositeLocationConverter() throws Exception {
    Franchise franchise = new Franchise();
    Restaurant restaurant = new Restaurant();
    Branch branch = new Branch(new Location(37.61649, -122.38681), franchise, restaurant);
    session.save(branch);
    session.clear();
    Branch loaded = session.load(Branch.class, branch.getId());
    assertThat(loaded.getLocation().getLatitude()).isCloseTo(37.61649, within(0.00001));
    assertThat(loaded.getLocation().getLongitude()).isCloseTo(-122.38681, within(0.00001));
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Branch(org.neo4j.ogm.domain.restaurant.Branch) Franchise(org.neo4j.ogm.domain.restaurant.Franchise) 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