Search in sources :

Example 11 with Person

use of org.eclipse.jnosql.mapping.graph.model.Person in project jnosql-diana by eclipse.

the class AbstractGraphTemplateTest method shouldReturnErrorWhenGetEdgesHasNullDirection.

@Test
public void shouldReturnErrorWhenGetEdgesHasNullDirection() {
    assertThrows(NullPointerException.class, () -> {
        Person otavio = getGraphTemplate().insert(Person.builder().withAge().withName("Otavio").build());
        getGraphTemplate().getEdges(otavio, null);
    });
}
Also used : Person(org.eclipse.jnosql.mapping.graph.model.Person) Test(org.junit.jupiter.api.Test)

Example 12 with Person

use of org.eclipse.jnosql.mapping.graph.model.Person in project jnosql-diana by eclipse.

the class AbstractGraphTemplateTest method shouldDeleteEntities.

@Test
public void shouldDeleteEntities() {
    Person otavio = getGraphTemplate().insert(Person.builder().withAge().withName("Otavio").build());
    Person poliana = getGraphTemplate().insert(Person.builder().withAge().withName("Poliana").build());
    assertTrue(getGraphTemplate().find(otavio.getId()).isPresent());
    getGraphTemplate().delete(Arrays.asList(otavio.getId(), poliana.getId()));
    assertFalse(getGraphTemplate().find(otavio.getId()).isPresent());
    assertFalse(getGraphTemplate().find(poliana.getId()).isPresent());
}
Also used : Person(org.eclipse.jnosql.mapping.graph.model.Person) Test(org.junit.jupiter.api.Test)

Example 13 with Person

use of org.eclipse.jnosql.mapping.graph.model.Person in project jnosql-diana by eclipse.

the class AbstractGraphTemplateTest method shouldGetErrorWhenEntityIsNotSavedYet.

@Test
public void shouldGetErrorWhenEntityIsNotSavedYet() {
    assertThrows(EntityNotFoundException.class, () -> {
        Person person = Person.builder().withAge().withId(10L).withName("Otavio").build();
        getGraphTemplate().update(person);
    });
}
Also used : Person(org.eclipse.jnosql.mapping.graph.model.Person) Test(org.junit.jupiter.api.Test)

Example 14 with Person

use of org.eclipse.jnosql.mapping.graph.model.Person in project jnosql-diana by eclipse.

the class AbstractGraphTemplateTest method shouldReturnErrorWhenGetEdgesHasNullId2.

@Test
public void shouldReturnErrorWhenGetEdgesHasNullId2() {
    assertThrows(IllegalStateException.class, () -> {
        Person otavio = Person.builder().withAge().withName("Otavio").build();
        getGraphTemplate().getEdges(otavio, Direction.BOTH);
    });
}
Also used : Person(org.eclipse.jnosql.mapping.graph.model.Person) Test(org.junit.jupiter.api.Test)

Example 15 with Person

use of org.eclipse.jnosql.mapping.graph.model.Person 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)

Aggregations

Person (org.eclipse.jnosql.mapping.graph.model.Person)74 Test (org.junit.jupiter.api.Test)71 Book (org.eclipse.jnosql.mapping.graph.model.Book)27 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)10 Pagination (jakarta.nosql.mapping.Pagination)7 Edge (org.apache.tinkerpop.gremlin.structure.Edge)5 Animal (org.eclipse.jnosql.mapping.graph.model.Animal)5 PreparedStatement (jakarta.nosql.mapping.PreparedStatement)4 Arrays (java.util.Arrays)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Graph (org.apache.tinkerpop.gremlin.structure.Graph)4 MatcherAssert (org.hamcrest.MatcherAssert)4 Matchers (org.hamcrest.Matchers)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Converters (jakarta.nosql.mapping.Converters)3 Repository (jakarta.nosql.mapping.Repository)3 CDIExtension (jakarta.nosql.tck.test.CDIExtension)3 Method (java.lang.reflect.Method)3 Stream (java.util.stream.Stream)3