use of jakarta.nosql.keyvalue.KeyValuePreparedStatement in project jnosql-diana by eclipse.
the class DefaultKeyValueQueryParserTest method shouldReturnErrorSingleResult.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "get @id, @id2" })
public void shouldReturnErrorSingleResult(String query) {
Mockito.when(manager.get(10)).thenReturn(Optional.of(Value.of(10)));
Mockito.when(manager.get(11)).thenReturn(Optional.of(Value.of(11)));
ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(List.class);
KeyValuePreparedStatement prepare = parser.prepare(query, manager);
prepare.bind("id", 10);
prepare.bind("id2", 11);
Assertions.assertThrows(NonUniqueResultException.class, () -> prepare.getSingleResult());
}
use of jakarta.nosql.keyvalue.KeyValuePreparedStatement in project jnosql-diana by eclipse.
the class DefaultKeyValueQueryParserTest method shouldExecutePrepareStatement1.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "put {\"Diana\", @value}" })
public void shouldExecutePrepareStatement1(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 DefaultKeyValueQueryParserTest method shouldExecutePrepareStatement.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "del @id" })
public void shouldExecutePrepareStatement(String query) {
ArgumentCaptor<List<Object>> captor = ArgumentCaptor.forClass(List.class);
KeyValuePreparedStatement prepare = parser.prepare(query, manager);
prepare.bind("id", 10);
prepare.getResult();
Mockito.verify(manager).delete(captor.capture());
List<Object> value = captor.getValue();
assertEquals(1, value.size());
MatcherAssert.assertThat(value, Matchers.contains(10));
}
use of jakarta.nosql.keyvalue.KeyValuePreparedStatement in project jnosql-diana by eclipse.
the class DefaultKeyValueQueryParserTest method shouldReturnEmptySingleResult.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "get @id" })
public void shouldReturnEmptySingleResult(String query) {
Mockito.when(manager.get(10)).thenReturn(Optional.empty());
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));
assertFalse(result.isPresent());
}
use of jakarta.nosql.keyvalue.KeyValuePreparedStatement in project jnosql-diana by eclipse.
the class GetQueryParserTest method shouldExecutePrepareStatement.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "get @id" })
public void shouldExecutePrepareStatement(String query) {
ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(List.class);
KeyValuePreparedStatement prepare = parser.prepare(query, manager);
prepare.bind("id", 10);
prepare.getResult().collect(Collectors.toList());
verify(manager).get(captor.capture());
List<Object> value = captor.getAllValues();
assertEquals(1, value.size());
MatcherAssert.assertThat(value, Matchers.contains(10));
}
Aggregations