use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.
the class KeyValueRepositoryProxyTest method shouldFindByQueryWithParameter.
@Test
public void shouldFindByQueryWithParameter() {
PreparedStatement prepare = Mockito.mock(PreparedStatement.class);
when(template.prepare("get @id", User.class)).thenReturn(prepare);
userRepository.findByQuery("id");
verify(template).prepare("get @id", User.class);
}
use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.
the class DynamicQueryMethodReturnTest method shouldReturnNull.
@Test
public void shouldReturnNull() throws NoSuchMethodException {
PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
Method method = getMethod(PersonRepository.class, "getInstance");
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.assertNull(execute);
}
use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.
the class DynamicQueryMethodReturnTest method shouldReturnFromPrepareStatement.
@Test
public void shouldReturnFromPrepareStatement() throws NoSuchMethodException {
PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
Mockito.when(preparedStatement.<Person>getResult()).thenReturn(Stream.of(new Person("Ada")));
Method method = getMethod(PersonRepository.class, "query");
Function<String, Stream<?>> stream = q -> Stream.of(new Person("Ada"));
DynamicQueryMethodReturn dynamicReturn = DynamicQueryMethodReturn.builder().withTypeClass(Person.class).withMethod(method).withQueryConverter(stream).withArgs(new Object[] { "Ada" }).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 DefaultDocumentTemplateTest method shouldPreparedStatement.
@Test
public void shouldPreparedStatement() {
PreparedStatement preparedStatement = subject.prepare("select * from Person where name = @name");
preparedStatement.bind("name", "Ada");
preparedStatement.getResult();
ArgumentCaptor<DocumentQuery> queryCaptor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(managerMock).select(queryCaptor.capture());
DocumentQuery query = queryCaptor.getValue();
assertEquals("Person", query.getDocumentCollection());
}
use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.
the class AbstractGraphTemplateTest method shouldExecutePrepareStatementWithErrorWhenThereIsMoreThanOneResult.
@Test
public void shouldExecutePrepareStatementWithErrorWhenThereIsMoreThanOneResult() {
getGraphTemplate().insert(Person.builder().withAge().withName("Otavio").build());
getGraphTemplate().insert(Person.builder().withAge().withName("Poliana").build());
PreparedStatement prepare = getGraphTemplate().prepare("g.V().hasLabel(param)");
prepare.bind("param", "Person");
assertThrows(NonUniqueResultException.class, prepare::getSingleResult);
}
Aggregations