Search in sources :

Example 16 with KeyValuePreparedStatement

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());
}
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 17 with KeyValuePreparedStatement

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());
}
Also used : KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Test(org.junit.jupiter.api.Test)

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