Search in sources :

Example 1 with Branch

use of org.neo4j.ogm.domain.restaurant.Branch 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 2 with Branch

use of org.neo4j.ogm.domain.restaurant.Branch 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)

Example 3 with Branch

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

the class CompilerTest method createSingleStatementForLabelsInDifferentOrder.

@Test
public void createSingleStatementForLabelsInDifferentOrder() 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("Foreign", "Delicious");
    franchise.addBranch(new Branch(new Location(0.0, 0.0), franchise, r1));
    franchise.addBranch(new Branch(new Location(0.0, 0.0), franchise, r2));
    Compiler compiler = mapAndCompile(franchise, -1);
    assertThat(compiler.createNodesStatements()).extracting(Statement::getStatement).containsOnly("UNWIND $rows as row CREATE (n:`Franchise`) SET n=row.props RETURN row.nodeRef as ref, ID(n) as id, $type as type", // the point is only one query for this combination of labels
    "UNWIND $rows as row CREATE (n:`Delicious`:`Foreign`:`Restaurant`) SET n=row.props RETURN row.nodeRef as ref, ID(n) as id, $type as type");
}
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)3 Branch (org.neo4j.ogm.domain.restaurant.Branch)3 Franchise (org.neo4j.ogm.domain.restaurant.Franchise)3 Location (org.neo4j.ogm.domain.restaurant.Location)3 Restaurant (org.neo4j.ogm.domain.restaurant.Restaurant)3