Search in sources :

Example 11 with KeyValuePreparedStatement

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());
}
Also used : KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with KeyValuePreparedStatement

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());
}
Also used : KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) KeyValueEntity(jakarta.nosql.keyvalue.KeyValueEntity) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with KeyValuePreparedStatement

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));
}
Also used : KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) List(java.util.List) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with KeyValuePreparedStatement

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());
}
Also used : KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) Value(jakarta.nosql.Value) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with KeyValuePreparedStatement

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));
}
Also used : KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

KeyValuePreparedStatement (jakarta.nosql.keyvalue.KeyValuePreparedStatement)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 ValueSource (org.junit.jupiter.params.provider.ValueSource)14 Value (jakarta.nosql.Value)5 List (java.util.List)5 KeyValueEntity (jakarta.nosql.keyvalue.KeyValueEntity)3 Params (jakarta.nosql.Params)2 QueryException (jakarta.nosql.QueryException)2 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)2 BucketManager (jakarta.nosql.keyvalue.BucketManager)2 Collectors.toList (java.util.stream.Collectors.toList)2 Stream (java.util.stream.Stream)2 PreparedStatement (jakarta.nosql.mapping.PreparedStatement)1 DelQuery (jakarta.nosql.query.DelQuery)1 DelQueryProvider (jakarta.nosql.query.DelQuery.DelQueryProvider)1 GetQuery (jakarta.nosql.query.GetQuery)1 GetQueryProvider (jakarta.nosql.query.GetQuery.GetQueryProvider)1 Duration (java.time.Duration)1 Optional (java.util.Optional)1 Test (org.junit.jupiter.api.Test)1