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());
}
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());
}
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());
}
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());
}
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));
}
Aggregations