use of jakarta.nosql.keyvalue.KeyValuePreparedStatement in project jnosql-diana by eclipse.
the class PutQueryParserTest method shouldExecutePrepareStatement.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "put {\"Diana\", @value}" })
public void shouldExecutePrepareStatement(String query) {
KeyValuePreparedStatement prepare = parser.prepare(query, manager);
prepare.bind("value", "Hunt");
prepare.getResult();
ArgumentCaptor<KeyValueEntity> captor = ArgumentCaptor.forClass(KeyValueEntity.class);
Mockito.verify(manager).put(captor.capture());
KeyValueEntity entity = captor.getValue();
assertEquals("Diana", entity.getKey());
assertEquals("Hunt", entity.getValue());
}
use of jakarta.nosql.keyvalue.KeyValuePreparedStatement 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());
}
Aggregations