use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.
the class DefaultKeyValueTemplateTest method shouldExecutePrepare.
@Test
public void shouldExecutePrepare() {
KeyValuePreparedStatement prepare = Mockito.mock(KeyValuePreparedStatement.class);
when(prepare.getResult()).thenReturn(Stream.of(Value.of("12")));
when(prepare.getSingleResult()).thenReturn(Optional.of(Value.of("12")));
when(manager.prepare("get @id")).thenReturn(prepare);
PreparedStatement statement = subject.prepare("get @id", Integer.class);
statement.bind("id", 12);
List<Integer> resultList = statement.<Integer>getResult().collect(toList());
MatcherAssert.assertThat(resultList, Matchers.contains(12));
Optional<Object> singleResult = statement.getSingleResult();
assertTrue(singleResult.isPresent());
assertEquals(12, singleResult.get());
}
use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.
the class ColumnRepositoryProxyTest method shouldExecuteJNoSQLPrepare.
@Test
public void shouldExecuteJNoSQLPrepare() {
PreparedStatement statement = Mockito.mock(PreparedStatement.class);
when(template.prepare(Mockito.anyString())).thenReturn(statement);
personRepository.findByQuery("Ada");
verify(statement).bind("id", "Ada");
}
use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.
the class GraphRepositoryProxyTest method shouldExecuteQuery2.
@Test
public void shouldExecuteQuery2() {
PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
when(template.prepare(Mockito.anyString())).thenReturn(preparedStatement);
personRepository.findByQuery("Ada");
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(template).prepare(captor.capture());
assertEquals("g.V().hasLabel('Person').has('name', name).toList()", captor.getValue());
verify(preparedStatement).bind("name", "Ada");
}
use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.
the class DefaultColumnTemplateTest method shouldPreparedStatement.
@Test
public void shouldPreparedStatement() {
PreparedStatement preparedStatement = subject.prepare("select * from Person where name = @name");
preparedStatement.bind("name", "Ada");
preparedStatement.getResult();
ArgumentCaptor<ColumnQuery> queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class);
verify(managerMock).select(queryCaptor.capture());
ColumnQuery query = queryCaptor.getValue();
assertEquals("Person", query.getColumnFamily());
}
use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.
the class DocumentReactiveRepositoryProxyTest method shouldExecuteJNoSQLPrepare.
@Test
public void shouldExecuteJNoSQLPrepare() {
PreparedStatement statement = Mockito.mock(PreparedStatement.class);
when(template.prepare(Mockito.anyString())).thenReturn(statement);
final Publisher<Person> publisher = personRepository.findByQuery("Ada");
final CompletionSubscriber<Person, List<Person>> subscriber = ReactiveStreams.<Person>builder().toList().build();
publisher.subscribe(subscriber);
final CompletionStage<List<Person>> completion = subscriber.getCompletion();
AtomicReference<List<Person>> reference = new AtomicReference<>();
completion.thenAccept(reference::set);
final List<Person> people = reference.get();
assertNotNull(people);
verify(statement).bind("id", "Ada");
}
Aggregations