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