use of org.eclipse.jnosql.mapping.graph.model.Book in project jnosql-diana by eclipse.
the class AbstractGraphTemplateTest method shouldDeleteEdges.
@Test
public void shouldDeleteEdges() {
Person otavio = getGraphTemplate().insert(Person.builder().withAge().withName("Otavio").build());
Animal dog = getGraphTemplate().insert(new Animal("Ada"));
Book cleanCode = getGraphTemplate().insert(Book.builder().withName("Clean code").build());
EdgeEntity likes = getGraphTemplate().edge(otavio, "likes", dog);
EdgeEntity reads = getGraphTemplate().edge(otavio, "reads", cleanCode);
final Optional<EdgeEntity> edge = getGraphTemplate().edge(likes.getId());
Assertions.assertTrue(edge.isPresent());
getGraphTemplate().deleteEdge(Arrays.asList(likes.getId(), reads.getId()));
assertFalse(getGraphTemplate().edge(likes.getId()).isPresent());
assertFalse(getGraphTemplate().edge(reads.getId()).isPresent());
}
use of org.eclipse.jnosql.mapping.graph.model.Book in project jnosql-diana by eclipse.
the class AbstractGraphTemplateTest method shouldReturnEdges.
@Test
public void shouldReturnEdges() {
Person otavio = getGraphTemplate().insert(Person.builder().withAge().withName("Otavio").build());
Animal dog = getGraphTemplate().insert(new Animal("dog"));
Book cleanCode = getGraphTemplate().insert(Book.builder().withName("Clean code").build());
EdgeEntity likes = getGraphTemplate().edge(otavio, "likes", dog);
EdgeEntity reads = getGraphTemplate().edge(otavio, "reads", cleanCode);
Collection<EdgeEntity> edgesById = getGraphTemplate().getEdges(otavio, Direction.BOTH);
Collection<EdgeEntity> edgesById1 = getGraphTemplate().getEdges(otavio, Direction.BOTH, "reads");
Collection<EdgeEntity> edgesById2 = getGraphTemplate().getEdges(otavio, Direction.BOTH, () -> "likes");
Collection<EdgeEntity> edgesById3 = getGraphTemplate().getEdges(otavio, Direction.OUT);
Collection<EdgeEntity> edgesById4 = getGraphTemplate().getEdges(cleanCode, Direction.IN);
assertEquals(edgesById, edgesById3);
assertThat(edgesById, Matchers.containsInAnyOrder(likes, reads));
assertThat(edgesById1, containsInAnyOrder(reads));
assertThat(edgesById2, containsInAnyOrder(likes));
assertThat(edgesById4, containsInAnyOrder(reads));
}
use of org.eclipse.jnosql.mapping.graph.model.Book in project jnosql-diana by eclipse.
the class BookTemplateTest method shouldSaveWithTransaction.
@Test
public void shouldSaveWithTransaction() {
AtomicReference<Status> status = new AtomicReference<>();
Book book = Book.builder().withName("The Book").build();
Transaction transaction = graph.tx();
transaction.addTransactionListener(status::set);
template.insert(book);
assertFalse(transaction.isOpen());
assertEquals(COMMIT, status.get());
}
use of org.eclipse.jnosql.mapping.graph.model.Book in project jnosql-diana by eclipse.
the class EdgeEntityTest method shouldReturnErrorWhenOutboundIsNull.
@Test
public void shouldReturnErrorWhenOutboundIsNull() {
Assertions.assertThrows(IllegalStateException.class, () -> {
Person person = Person.builder().withName("Poliana").withAge().build();
Book book = Book.builder().withAge(2007).withName("The Shack").build();
graphTemplate.edge(person, "reads", book);
});
}
use of org.eclipse.jnosql.mapping.graph.model.Book in project jnosql-diana by eclipse.
the class EdgeEntityTest method shouldReturnErrorWhenRemoveNullKeyProperty.
@Test
public void shouldReturnErrorWhenRemoveNullKeyProperty() {
assertThrows(NullPointerException.class, () -> {
Person person = graphTemplate.insert(Person.builder().withName("Poliana").withAge().build());
Book book = graphTemplate.insert(Book.builder().withAge(2007).withName("The Shack").build());
EdgeEntity edge = graphTemplate.edge(person, "reads", book);
edge.add("where", "Brazil");
assertFalse(edge.isEmpty());
edge.remove(null);
});
}
Aggregations