use of jakarta.nosql.keyvalue.KeyValuePreparedStatement in project jnosql-diana by eclipse.
the class DelQueryParserTest method shouldReturnErrorWhenDontBindParameters.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "del @id" })
public void shouldReturnErrorWhenDontBindParameters(String query) {
KeyValuePreparedStatement prepare = parser.prepare(query, manager);
assertThrows(QueryException.class, prepare::getResult);
}
use of jakarta.nosql.keyvalue.KeyValuePreparedStatement in project jnosql-diana by eclipse.
the class DelQueryParserTest method shouldExecutePrepareStatement2.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "del @id, @id2" })
public void shouldExecutePrepareStatement2(String query) {
ArgumentCaptor<List<Object>> captor = ArgumentCaptor.forClass(List.class);
KeyValuePreparedStatement prepare = parser.prepare(query, manager);
prepare.bind("id", 10);
prepare.bind("id2", 11);
prepare.getResult();
Mockito.verify(manager).delete(captor.capture());
List<Object> value = captor.getValue();
assertEquals(2, value.size());
MatcherAssert.assertThat(value, Matchers.contains(10, 11));
}
use of jakarta.nosql.keyvalue.KeyValuePreparedStatement in project jnosql-diana by eclipse.
the class DelQueryParser method prepare.
public KeyValuePreparedStatement prepare(String query, BucketManager manager) {
DelQuery delQuery = provider.apply(query);
Params params = Params.newParams();
List<Value> values = delQuery.getKeys().stream().map(k -> Values.getValue(k, params)).collect(toList());
return DefaultKeyValuePreparedStatement.del(values, manager, params, query);
}
use of jakarta.nosql.keyvalue.KeyValuePreparedStatement in project jnosql-diana by eclipse.
the class DefaultKeyValueQueryParserTest method shouldExecutePrepareStatement2.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "put {\"Diana\", @value, 10 second}" })
public void shouldExecutePrepareStatement2(String query) {
KeyValuePreparedStatement prepare = parser.prepare(query, manager);
prepare.bind("value", "Hunt");
prepare.getResult();
ArgumentCaptor<KeyValueEntity> captor = ArgumentCaptor.forClass(KeyValueEntity.class);
ArgumentCaptor<Duration> durationCaptor = ArgumentCaptor.forClass(Duration.class);
Mockito.verify(manager).put(captor.capture(), durationCaptor.capture());
KeyValueEntity entity = captor.getValue();
final Duration duration = durationCaptor.getValue();
assertEquals("Diana", entity.getKey());
assertEquals("Hunt", entity.getValue());
assertEquals(Duration.ofSeconds(10L), duration);
}
use of jakarta.nosql.keyvalue.KeyValuePreparedStatement in project jnosql-diana by eclipse.
the class DefaultKeyValueQueryParserTest method shouldReturnSingleResult.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "get @id" })
public void shouldReturnSingleResult(String query) {
Mockito.when(manager.get(10)).thenReturn(Optional.of(Value.of(10L)));
ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(List.class);
KeyValuePreparedStatement prepare = parser.prepare(query, manager);
prepare.bind("id", 10);
final Optional<Value> result = prepare.getSingleResult();
Mockito.verify(manager).get(captor.capture());
List<Object> value = captor.getAllValues();
assertEquals(1, value.size());
MatcherAssert.assertThat(value, Matchers.contains(10));
assertEquals(10L, result.get().get());
}
Aggregations