Search in sources :

Example 6 with PreparedStatement

use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.

the class DynamicQueryMethodReturnTest method shouldReturnAnInstance.

@Test
public void shouldReturnAnInstance() throws NoSuchMethodException {
    PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
    Method method = getMethod(PersonRepository.class, "getInstance");
    Function<String, Stream<?>> stream = q -> Stream.of(new Person("Ada"));
    DynamicQueryMethodReturn dynamicReturn = DynamicQueryMethodReturn.builder().withTypeClass(Person.class).withMethod(method).withQueryConverter(stream).withPrepareConverter(s -> preparedStatement).build();
    Object execute = dynamicReturn.execute();
    Assertions.assertTrue(execute instanceof Person);
    Person person = (Person) execute;
    Assertions.assertEquals(new Person("Ada"), person);
}
Also used : NonUniqueResultException(jakarta.nosql.NonUniqueResultException) Collection(java.util.Collection) Set(java.util.Set) Function(java.util.function.Function) Query(jakarta.nosql.mapping.Query) Repository(jakarta.nosql.mapping.Repository) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) Queue(java.util.Queue) Method(java.lang.reflect.Method) Param(jakarta.nosql.mapping.Param) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Stream(java.util.stream.Stream) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 7 with PreparedStatement

use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.

the class DynamicQueryMethodReturnTest method shouldReturnCollection.

@Test
public void shouldReturnCollection() throws NoSuchMethodException {
    PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
    Method method = getMethod(PersonRepository.class, "getCollection");
    Function<String, Stream<?>> stream = q -> Stream.of(new Person("Ada"));
    DynamicQueryMethodReturn dynamicReturn = DynamicQueryMethodReturn.builder().withTypeClass(Person.class).withMethod(method).withQueryConverter(stream).withPrepareConverter(s -> preparedStatement).build();
    Object execute = dynamicReturn.execute();
    Assertions.assertTrue(execute instanceof Collection);
    Collection<Person> persons = (Collection) execute;
    Assertions.assertFalse(persons.isEmpty());
    Assertions.assertEquals(new Person("Ada"), persons.iterator().next());
}
Also used : NonUniqueResultException(jakarta.nosql.NonUniqueResultException) Collection(java.util.Collection) Set(java.util.Set) Function(java.util.function.Function) Query(jakarta.nosql.mapping.Query) Repository(jakarta.nosql.mapping.Repository) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) Queue(java.util.Queue) Method(java.lang.reflect.Method) Param(jakarta.nosql.mapping.Param) Collection(java.util.Collection) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Stream(java.util.stream.Stream) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 8 with PreparedStatement

use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.

the class DynamicQueryMethodReturnTest method shouldReturnOptionalError.

@Test
public void shouldReturnOptionalError() throws NoSuchMethodException {
    PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
    Method method = getMethod(PersonRepository.class, "getOptional");
    Function<String, Stream<?>> stream = q -> Stream.of(new Person("Poliana"), new Person("Otavio"));
    DynamicQueryMethodReturn dynamicReturn = DynamicQueryMethodReturn.builder().withTypeClass(Person.class).withMethod(method).withQueryConverter(stream).withPrepareConverter(s -> preparedStatement).build();
    Assertions.assertThrows(NonUniqueResultException.class, dynamicReturn::execute);
}
Also used : NonUniqueResultException(jakarta.nosql.NonUniqueResultException) Collection(java.util.Collection) Set(java.util.Set) Function(java.util.function.Function) Query(jakarta.nosql.mapping.Query) Repository(jakarta.nosql.mapping.Repository) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) Queue(java.util.Queue) Method(java.lang.reflect.Method) Param(jakarta.nosql.mapping.Param) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Stream(java.util.stream.Stream) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 9 with PreparedStatement

use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.

the class DynamicQueryMethodReturnTest method shouldReturnOptional.

@Test
public void shouldReturnOptional() throws NoSuchMethodException {
    PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
    Method method = getMethod(PersonRepository.class, "getOptional");
    Function<String, Stream<?>> stream = q -> Stream.of(new Person("Ada"));
    DynamicQueryMethodReturn dynamicReturn = DynamicQueryMethodReturn.builder().withTypeClass(Person.class).withMethod(method).withQueryConverter(stream).withPrepareConverter(s -> preparedStatement).build();
    Object execute = dynamicReturn.execute();
    Assertions.assertTrue(execute instanceof Optional);
    Optional<Person> optional = (Optional) execute;
    Assertions.assertTrue(optional.isPresent());
    Assertions.assertEquals(new Person("Ada"), optional.get());
}
Also used : NonUniqueResultException(jakarta.nosql.NonUniqueResultException) Collection(java.util.Collection) Set(java.util.Set) Function(java.util.function.Function) Query(jakarta.nosql.mapping.Query) Repository(jakarta.nosql.mapping.Repository) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) Queue(java.util.Queue) Method(java.lang.reflect.Method) Param(jakarta.nosql.mapping.Param) Optional(java.util.Optional) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Stream(java.util.stream.Stream) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 10 with PreparedStatement

use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.

the class AbstractGraphTemplateTest method shouldExecutePrepareStatementSingletonEmpty.

@Test
public void shouldExecutePrepareStatementSingletonEmpty() {
    PreparedStatement prepare = getGraphTemplate().prepare("g.V().hasLabel(param)");
    prepare.bind("param", "Person");
    Optional<Person> otavio = prepare.getSingleResult();
    assertFalse(otavio.isPresent());
}
Also used : PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Person(org.eclipse.jnosql.mapping.graph.model.Person) Test(org.junit.jupiter.api.Test)

Aggregations

PreparedStatement (jakarta.nosql.mapping.PreparedStatement)25 Test (org.junit.jupiter.api.Test)25 List (java.util.List)13 NonUniqueResultException (jakarta.nosql.NonUniqueResultException)11 Param (jakarta.nosql.mapping.Param)11 Query (jakarta.nosql.mapping.Query)11 Repository (jakarta.nosql.mapping.Repository)11 Method (java.lang.reflect.Method)11 Collection (java.util.Collection)11 Objects (java.util.Objects)11 Optional (java.util.Optional)11 Queue (java.util.Queue)11 Set (java.util.Set)11 Function (java.util.function.Function)11 Stream (java.util.stream.Stream)11 Assertions (org.junit.jupiter.api.Assertions)11 Mockito (org.mockito.Mockito)11 Person (org.eclipse.jnosql.mapping.graph.model.Person)3 Person (jakarta.nosql.tck.entities.Person)2 Arrays.asList (java.util.Arrays.asList)2