Search in sources :

Example 26 with ClassMapping

use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.

the class SelectQueryConverterTest method shouldRunQuery6.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "findByAgeGreaterThanEqual" })
public void shouldRunQuery6(String methodName) {
    Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals(methodName)).findFirst().get();
    graph.addVertex(T.label, "Person", "name", "Otavio", "age", 30);
    graph.addVertex(T.label, "Person", "name", "Ada", "age", 40);
    graph.addVertex(T.label, "Person", "name", "Poliana", "age", 25);
    ClassMapping mapping = mappings.get(Person.class);
    GraphQueryMethod queryMethod = new GraphQueryMethod(mapping, graph.traversal().V(), converters, method, new Object[] { 30 });
    List<Vertex> vertices = converter.apply(queryMethod, null).collect(Collectors.toList());
    assertEquals(2, vertices.size());
    assertNotEquals("Poliana", vertices.get(0).value("name"));
    assertNotEquals("Poliana", vertices.get(1).value("name"));
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Method(java.lang.reflect.Method) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with ClassMapping

use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.

the class SelectQueryConverterTest method shouldRunQuery9.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "findByAgeLessThanOrderByNameDesc" })
public void shouldRunQuery9(String methodName) {
    Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals(methodName)).findFirst().get();
    graph.addVertex(T.label, "Person", "name", "Otavio", "age", 30);
    graph.addVertex(T.label, "Person", "name", "Ada", "age", 40);
    graph.addVertex(T.label, "Person", "name", "Poliana", "age", 25);
    ClassMapping mapping = mappings.get(Person.class);
    GraphQueryMethod queryMethod = new GraphQueryMethod(mapping, graph.traversal().V(), converters, method, new Object[] { 100 });
    List<Vertex> vertices = converter.apply(queryMethod, null).collect(Collectors.toList());
    List<Object> names = vertices.stream().map(v -> v.value("name")).collect(Collectors.toList());
    assertEquals(3, vertices.size());
    MatcherAssert.assertThat(names, Matchers.contains("Poliana", "Otavio", "Ada"));
}
Also used : Person(org.eclipse.jnosql.mapping.graph.model.Person) ValueSource(org.junit.jupiter.params.provider.ValueSource) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) Graph(org.apache.tinkerpop.gremlin.structure.Graph) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Matchers(org.hamcrest.Matchers) Converters(jakarta.nosql.mapping.Converters) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) T(org.apache.tinkerpop.gremlin.structure.T) Collectors(java.util.stream.Collectors) Repository(jakarta.nosql.mapping.Repository) Inject(javax.inject.Inject) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) MatcherAssert(org.hamcrest.MatcherAssert) Stream(java.util.stream.Stream) CDIExtension(jakarta.nosql.tck.test.CDIExtension) ClassMappings(org.eclipse.jnosql.mapping.reflection.ClassMappings) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Method(java.lang.reflect.Method) Edge(org.apache.tinkerpop.gremlin.structure.Edge) ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Method(java.lang.reflect.Method) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with ClassMapping

use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.

the class DeleteQueryConverterTest method shouldRunQuery3.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "deleteByAgeLessThan" })
public void shouldRunQuery3(String methodName) {
    Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals(methodName)).findFirst().get();
    graph.addVertex(T.label, "Person", "name", "Otavio", "age", 30);
    graph.addVertex(T.label, "Person", "name", "Ada", "age", 40);
    graph.addVertex(T.label, "Person", "name", "Poliana", "age", 25);
    ClassMapping mapping = mappings.get(Person.class);
    GraphQueryMethod queryMethod = new GraphQueryMethod(mapping, graph.traversal().V(), converters, method, new Object[] { 30 });
    List<Vertex> vertices = converter.apply(queryMethod);
    assertEquals(1, vertices.size());
    assertEquals("Poliana", vertices.get(0).value("name"));
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Method(java.lang.reflect.Method) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with ClassMapping

use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.

the class DeleteQueryConverterTest method checkEquals.

private void checkEquals(String methodName) {
    Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals(methodName)).findFirst().get();
    graph.addVertex("Person").property("name", "Otavio");
    graph.addVertex("Person").property("name", "Ada");
    graph.addVertex("Person").property("name", "Poliana");
    ClassMapping mapping = mappings.get(Person.class);
    GraphQueryMethod queryMethod = new GraphQueryMethod(mapping, graph.traversal().V(), converters, method, new Object[] { "Ada" });
    List<Vertex> vertices = converter.apply(queryMethod);
    assertEquals(1, vertices.size());
    assertEquals("Ada", vertices.get(0).value("name"));
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Method(java.lang.reflect.Method)

Example 30 with ClassMapping

use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.

the class DeleteQueryConverterTest method shouldRunQuery12.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "deleteByNameIn" })
public void shouldRunQuery12(String methodName) {
    Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals(methodName)).findFirst().get();
    graph.addVertex(T.label, "Person", "name", "Otavio", "age", 30);
    graph.addVertex(T.label, "Person", "name", "Ada", "age", 40);
    graph.addVertex(T.label, "Person", "name", "Poliana", "age", 25);
    ClassMapping mapping = mappings.get(Person.class);
    GraphQueryMethod queryMethod = new GraphQueryMethod(mapping, graph.traversal().V(), converters, method, new Object[] { Arrays.asList("Otavio", "Ada", "Poliana") });
    List<Vertex> vertices = converter.apply(queryMethod);
    List<Object> names = vertices.stream().map(v -> v.value("name")).sorted().collect(Collectors.toList());
    assertEquals(3, vertices.size());
    MatcherAssert.assertThat(names, Matchers.contains("Ada", "Otavio", "Poliana"));
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Method(java.lang.reflect.Method) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ClassMapping (org.eclipse.jnosql.mapping.reflection.ClassMapping)60 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)31 Method (java.lang.reflect.Method)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 ValueSource (org.junit.jupiter.params.provider.ValueSource)19 FieldMapping (org.eclipse.jnosql.mapping.reflection.FieldMapping)12 List (java.util.List)10 Converters (jakarta.nosql.mapping.Converters)8 Edge (org.apache.tinkerpop.gremlin.structure.Edge)8 Graph (org.apache.tinkerpop.gremlin.structure.Graph)8 ClassMappings (org.eclipse.jnosql.mapping.reflection.ClassMappings)8 Collectors (java.util.stream.Collectors)7 Test (org.junit.jupiter.api.Test)7 Value (jakarta.nosql.Value)6 Optional (java.util.Optional)6 EntityNotFoundException (jakarta.nosql.mapping.EntityNotFoundException)5 SelectQuery (jakarta.nosql.query.SelectQuery)5 Iterator (java.util.Iterator)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 Function (java.util.function.Function)5