use of org.neo4j.ogm.domain.ingredients.Ingredient in project neo4j-ogm by neo4j.
the class IngredientsIntegrationTest method shouldBeAbleToLoadIngredientsWithoutPairings.
@Test
public void shouldBeAbleToLoadIngredientsWithoutPairings() {
Ingredient chicken = new Ingredient("Chicken");
session.save(chicken);
Ingredient carrot = new Ingredient("Carrot");
session.save(carrot);
Ingredient butter = new Ingredient("Butter");
session.save(butter);
Pairing pairing = new Pairing();
pairing.setFirst(chicken);
pairing.setSecond(carrot);
pairing.setAffinity("EXCELLENT");
carrot.addPairing(pairing);
session.save(chicken);
Pairing pairing2 = new Pairing();
pairing2.setFirst(chicken);
pairing2.setSecond(butter);
pairing2.setAffinity("EXCELLENT");
carrot.addPairing(pairing2);
session.save(chicken);
Pairing pairing3 = new Pairing();
pairing3.setFirst(carrot);
pairing3.setSecond(butter);
pairing3.setAffinity("EXCELLENT");
carrot.addPairing(pairing3);
// NullPointerException
session.save(carrot);
// it is important to clear the session if you intend the depth of the
// the objects you want returned to not be the same as the depth currently
// held in the mapping context.
session.clear();
Iterator<Ingredient> it = session.loadAll(Ingredient.class, 0).iterator();
while (it.hasNext()) {
Ingredient i = it.next();
assertThat(i.getPairings()).as(i.getName()).hasSize(0);
}
}
use of org.neo4j.ogm.domain.ingredients.Ingredient in project neo4j-ogm by neo4j.
the class IngredientsIntegrationTest method shouldBeAbleToLoadIngredientsWithFiltersPagingAndDepth.
/**
* @see Issue 97
*/
@Test
public void shouldBeAbleToLoadIngredientsWithFiltersPagingAndDepth() {
Ingredient chicken = new Ingredient("Chicken");
session.save(chicken);
Ingredient carrot = new Ingredient("Chicken");
session.save(carrot);
Ingredient butter = new Ingredient("Chicken");
session.save(butter);
Pairing pairing = new Pairing();
pairing.setFirst(chicken);
pairing.setSecond(carrot);
pairing.setAffinity("EXCELLENT");
carrot.addPairing(pairing);
session.save(chicken);
Pairing pairing2 = new Pairing();
pairing2.setFirst(chicken);
pairing2.setSecond(butter);
pairing2.setAffinity("EXCELLENT");
carrot.addPairing(pairing2);
session.save(chicken);
Pairing pairing3 = new Pairing();
pairing3.setFirst(carrot);
pairing3.setSecond(butter);
pairing3.setAffinity("EXCELLENT");
carrot.addPairing(pairing3);
session.save(carrot);
session.clear();
Collection<Ingredient> ingredients = session.loadAll(Ingredient.class, new Filter("name", ComparisonOperator.EQUALS, "Chicken"), new Pagination(0, 1));
assertThat(ingredients).hasSize(1);
session.clear();
ingredients = session.loadAll(Ingredient.class, new Filter("name", ComparisonOperator.EQUALS, "Chicken"), new Pagination(1, 1));
assertThat(ingredients).hasSize(1);
session.clear();
ingredients = session.loadAll(Ingredient.class, new Filter("name", ComparisonOperator.EQUALS, "Chicken"), new Pagination(0, 2));
assertThat(ingredients).hasSize(2);
ingredients = session.loadAll(Ingredient.class, new Filter("name", ComparisonOperator.EQUALS, "Chicken"), new Pagination(0, 3));
assertThat(ingredients).hasSize(3);
session.clear();
Collection<Pairing> pairings = session.loadAll(Pairing.class, new Filter("affinity", ComparisonOperator.EQUALS, "EXCELLENT"), new Pagination(0, 1));
assertThat(pairings).hasSize(1);
session.clear();
pairings = session.loadAll(Pairing.class, new Filter("affinity", ComparisonOperator.EQUALS, "EXCELLENT"), new Pagination(1, 1));
assertThat(pairings).hasSize(1);
session.clear();
pairings = session.loadAll(Pairing.class, new Filter("affinity", ComparisonOperator.EQUALS, "EXCELLENT"), new Pagination(0, 2));
assertThat(pairings).hasSize(2);
pairings = session.loadAll(Pairing.class, new Filter("affinity", ComparisonOperator.EQUALS, "EXCELLENT"), new Pagination(0, 3));
assertThat(pairings).hasSize(3);
}
use of org.neo4j.ogm.domain.ingredients.Ingredient in project neo4j-ogm by neo4j.
the class IngredientsIntegrationTest method shouldBeAbleToLoadPairingWithCustomDepth.
/**
* @see Issue #94
*/
@Test
public void shouldBeAbleToLoadPairingWithCustomDepth() {
Ingredient chicken = new Ingredient("Chicken");
session.save(chicken);
Ingredient carrot = new Ingredient("Carrot");
session.save(carrot);
Ingredient butter = new Ingredient("Butter");
session.save(butter);
Ingredient pineapple = new Ingredient("Pineapple");
session.save(pineapple);
Ingredient ham = new Ingredient("Ham");
session.save(ham);
Ingredient sage = new Ingredient("Sage");
session.save(sage);
Pairing pairing = new Pairing();
pairing.setFirst(chicken);
pairing.setSecond(carrot);
pairing.setAffinity("EXCELLENT");
session.save(pairing);
Pairing pairing2 = new Pairing();
pairing2.setFirst(chicken);
pairing2.setSecond(pineapple);
pairing2.setAffinity("GOOD");
session.save(pairing2);
Pairing pairing3 = new Pairing();
pairing3.setFirst(pineapple);
pairing3.setSecond(ham);
pairing3.setAffinity("TRIED AND TESTED");
session.save(pairing3);
Pairing pairing4 = new Pairing();
pairing4.setFirst(carrot);
pairing4.setSecond(butter);
pairing4.setAffinity("GOOD");
session.save(pairing4);
Pairing pairing5 = new Pairing();
pairing5.setFirst(butter);
pairing5.setSecond(sage);
pairing5.setAffinity("EXCELLENT");
session.save(pairing5);
session.clear();
// Load pairing (carrot-chicken) to default depth 1. Carrot and Chicken should be loaded to depth 1
Pairing carrotChicken = session.load(Pairing.class, pairing.getId());
assertThat(carrotChicken).isNotNull();
assertThat(carrotChicken.getAffinity()).isEqualTo("EXCELLENT");
assertThat(carrotChicken.getFirst()).isNotNull();
assertThat(carrotChicken.getFirst().getPairings()).hasSize(2);
assertThat(carrotChicken.getSecond()).isNotNull();
assertThat(carrotChicken.getSecond().getPairings()).hasSize(2);
Ingredient loadedChicken;
if (carrotChicken.getFirst().getName().equals("Chicken")) {
loadedChicken = carrotChicken.getFirst();
} else {
loadedChicken = carrotChicken.getSecond();
}
Ingredient loadedPineapple = null;
for (Pairing p : loadedChicken.getPairings()) {
if (p.getFirst().getName().equals("Pineapple")) {
loadedPineapple = p.getFirst();
}
if (p.getSecond().getName().equals("Pineapple")) {
loadedPineapple = p.getSecond();
}
}
assertThat(loadedPineapple).isNotNull();
assertThat(loadedPineapple.getPairings()).hasSize(1);
Ingredient loadedCarrot;
if (carrotChicken.getFirst().getName().equals("Carrot")) {
loadedCarrot = carrotChicken.getFirst();
} else {
loadedCarrot = carrotChicken.getSecond();
}
Ingredient loadedButter = null;
for (Pairing p : loadedCarrot.getPairings()) {
if (p.getFirst().getName().equals("Butter")) {
loadedButter = p.getFirst();
}
if (p.getSecond().getName().equals("Butter")) {
loadedButter = p.getSecond();
}
}
assertThat(loadedButter).isNotNull();
assertThat(loadedButter.getPairings()).hasSize(1);
session.clear();
// Load pairing (carrot-chicken) to depth 2. Carrot and chicken should be loaded to depth 2
carrotChicken = session.load(Pairing.class, pairing.getId(), 2);
assertThat(carrotChicken).isNotNull();
assertThat(carrotChicken.getAffinity()).isEqualTo("EXCELLENT");
assertThat(carrotChicken.getFirst()).isNotNull();
assertThat(carrotChicken.getFirst().getPairings()).hasSize(2);
assertThat(carrotChicken.getSecond()).isNotNull();
assertThat(carrotChicken.getSecond().getPairings()).hasSize(2);
if (carrotChicken.getFirst().getName().equals("Chicken")) {
loadedChicken = carrotChicken.getFirst();
} else {
loadedChicken = carrotChicken.getSecond();
}
loadedPineapple = null;
for (Pairing p : loadedChicken.getPairings()) {
if (p.getFirst().getName().equals("Pineapple")) {
loadedPineapple = p.getFirst();
}
if (p.getSecond().getName().equals("Pineapple")) {
loadedPineapple = p.getSecond();
}
}
assertThat(loadedPineapple).isNotNull();
assertThat(loadedPineapple.getPairings()).hasSize(2);
if (carrotChicken.getFirst().getName().equals("Carrot")) {
loadedCarrot = carrotChicken.getFirst();
} else {
loadedCarrot = carrotChicken.getSecond();
}
loadedButter = null;
for (Pairing p : loadedCarrot.getPairings()) {
if (p.getFirst().getName().equals("Butter")) {
loadedButter = p.getFirst();
}
if (p.getSecond().getName().equals("Butter")) {
loadedButter = p.getSecond();
}
}
assertThat(loadedButter).isNotNull();
assertThat(loadedButter.getPairings()).hasSize(2);
}
use of org.neo4j.ogm.domain.ingredients.Ingredient in project neo4j-ogm by neo4j.
the class IngredientsIntegrationTest method shouldBeAbleToAddInterrelatedPairings.
/**
* @see DATAGRAPH-639
*/
@Test
public void shouldBeAbleToAddInterrelatedPairings() {
Ingredient chicken = new Ingredient("Chicken");
session.save(chicken);
Ingredient carrot = new Ingredient("Carrot");
session.save(carrot);
Ingredient butter = new Ingredient("Butter");
session.save(butter);
Pairing pairing = new Pairing();
pairing.setFirst(chicken);
pairing.setSecond(carrot);
pairing.setAffinity("EXCELLENT");
carrot.addPairing(pairing);
session.save(chicken);
Pairing pairing2 = new Pairing();
pairing2.setFirst(chicken);
pairing2.setSecond(butter);
pairing2.setAffinity("EXCELLENT");
carrot.addPairing(pairing2);
session.save(chicken);
Pairing pairing3 = new Pairing();
pairing3.setFirst(carrot);
pairing3.setSecond(butter);
pairing3.setAffinity("EXCELLENT");
carrot.addPairing(pairing3);
// NullPointerException
session.save(carrot);
}
use of org.neo4j.ogm.domain.ingredients.Ingredient in project neo4j-ogm by neo4j.
the class IngredientsIntegrationTest method shouldBeAbleToLoadIngredientsWithPagingAndDepth.
/**
* @see Issue 97
*/
@Test
public void shouldBeAbleToLoadIngredientsWithPagingAndDepth() {
Ingredient chicken = new Ingredient("Chicken");
session.save(chicken);
Ingredient carrot = new Ingredient("Carrot");
session.save(carrot);
Ingredient butter = new Ingredient("Butter");
session.save(butter);
Pairing pairing = new Pairing();
pairing.setFirst(chicken);
pairing.setSecond(carrot);
pairing.setAffinity("EXCELLENT");
carrot.addPairing(pairing);
session.save(chicken);
Pairing pairing2 = new Pairing();
pairing2.setFirst(chicken);
pairing2.setSecond(butter);
pairing2.setAffinity("EXCELLENT");
carrot.addPairing(pairing2);
session.save(chicken);
Pairing pairing3 = new Pairing();
pairing3.setFirst(carrot);
pairing3.setSecond(butter);
pairing3.setAffinity("EXCELLENT");
carrot.addPairing(pairing3);
session.save(carrot);
session.clear();
Collection<Ingredient> ingredients = session.loadAll(Ingredient.class, new Pagination(0, 1));
assertThat(ingredients).hasSize(1);
session.clear();
ingredients = session.loadAll(Ingredient.class, new Pagination(1, 1));
assertThat(ingredients).hasSize(1);
session.clear();
ingredients = session.loadAll(Ingredient.class, new Pagination(0, 2));
assertThat(ingredients).hasSize(2);
ingredients = session.loadAll(Ingredient.class, new Pagination(0, 3));
assertThat(ingredients).hasSize(3);
session.clear();
Collection<Pairing> pairings = session.loadAll(Pairing.class, new Pagination(0, 1));
assertThat(pairings).hasSize(1);
session.clear();
pairings = session.loadAll(Pairing.class, new Pagination(1, 1));
assertThat(pairings).hasSize(1);
session.clear();
pairings = session.loadAll(Pairing.class, new Pagination(0, 2));
assertThat(pairings).hasSize(2);
session.clear();
pairings = session.loadAll(Pairing.class, new Pagination(0, 3));
assertThat(pairings).hasSize(3);
}
Aggregations