Search in sources :

Example 1 with Book

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());
}
Also used : Animal(org.eclipse.jnosql.mapping.graph.model.Animal) Book(org.eclipse.jnosql.mapping.graph.model.Book) Person(org.eclipse.jnosql.mapping.graph.model.Person) Test(org.junit.jupiter.api.Test)

Example 2 with Book

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));
}
Also used : Animal(org.eclipse.jnosql.mapping.graph.model.Animal) Book(org.eclipse.jnosql.mapping.graph.model.Book) Person(org.eclipse.jnosql.mapping.graph.model.Person) Test(org.junit.jupiter.api.Test)

Example 3 with Book

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());
}
Also used : Status(org.apache.tinkerpop.gremlin.structure.Transaction.Status) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) Book(org.eclipse.jnosql.mapping.graph.model.Book) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 4 with Book

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);
    });
}
Also used : Book(org.eclipse.jnosql.mapping.graph.model.Book) Person(org.eclipse.jnosql.mapping.graph.model.Person) Test(org.junit.jupiter.api.Test)

Example 5 with 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);
    });
}
Also used : Book(org.eclipse.jnosql.mapping.graph.model.Book) Person(org.eclipse.jnosql.mapping.graph.model.Person) Test(org.junit.jupiter.api.Test)

Aggregations

Book (org.eclipse.jnosql.mapping.graph.model.Book)29 Test (org.junit.jupiter.api.Test)29 Person (org.eclipse.jnosql.mapping.graph.model.Person)26 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Transaction (org.apache.tinkerpop.gremlin.structure.Transaction)3 Status (org.apache.tinkerpop.gremlin.structure.Transaction.Status)3 Animal (org.eclipse.jnosql.mapping.graph.model.Animal)3 Value (jakarta.nosql.Value)1