Search in sources :

Example 1 with PreparedStatement

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

the class DynamicQueryMethodReturnTest method shouldReturnQueue.

@Test
public void shouldReturnQueue() throws NoSuchMethodException {
    PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
    Method method = getMethod(PersonRepository.class, "getQueue");
    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 Queue);
    Queue<Person> persons = (Queue) 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) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Stream(java.util.stream.Stream) Method(java.lang.reflect.Method) Queue(java.util.Queue) Test(org.junit.jupiter.api.Test)

Example 2 with PreparedStatement

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

the class DynamicQueryMethodReturnTest method shouldReturnIterable.

@Test
public void shouldReturnIterable() throws NoSuchMethodException {
    PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
    Method method = getMethod(PersonRepository.class, "getIterable");
    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 Iterable);
    Iterable<Person> persons = (List) execute;
    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) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Stream(java.util.stream.Stream) List(java.util.List) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 3 with PreparedStatement

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

the class DynamicQueryMethodReturnTest method shouldReturnEmptyOptional.

@Test
public void shouldReturnEmptyOptional() throws NoSuchMethodException {
    PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
    Method method = getMethod(PersonRepository.class, "getOptional");
    Function<String, Stream<?>> stream = q -> Stream.empty();
    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.assertFalse(optional.isPresent());
}
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 4 with PreparedStatement

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

the class DynamicQueryMethodReturnTest method shouldReturnStream.

@Test
public void shouldReturnStream() throws NoSuchMethodException {
    PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
    Method method = getMethod(PersonRepository.class, "getStream");
    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 Stream);
    Stream<Person> persons = (Stream) execute;
    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) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Stream(java.util.stream.Stream) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 5 with PreparedStatement

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

the class DynamicQueryMethodReturnTest method shouldReturnList.

@Test
public void shouldReturnList() throws NoSuchMethodException {
    PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
    Method method = getMethod(PersonRepository.class, "getList");
    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 List);
    List<Person> persons = (List) execute;
    Assertions.assertFalse(persons.isEmpty());
    Assertions.assertEquals(new Person("Ada"), persons.get(0));
}
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) List(java.util.List) Method(java.lang.reflect.Method) 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