Search in sources :

Example 21 with KeyValueEntity

use of jakarta.nosql.keyvalue.KeyValueEntity in project jnosql-diana by eclipse.

the class DefaultKeyValueEntityTest method shouldCreateInstance.

@Test
public void shouldCreateInstance() {
    KeyValueEntity entity = KeyValueEntity.of("key", "value");
    assertNotNull(entity);
    assertEquals("key", entity.getKey());
    assertEquals("value", entity.getValue());
}
Also used : KeyValueEntity(jakarta.nosql.keyvalue.KeyValueEntity) Test(org.junit.jupiter.api.Test)

Example 22 with KeyValueEntity

use of jakarta.nosql.keyvalue.KeyValueEntity in project jnosql-diana by eclipse.

the class DefaultKeyValueEntityTest method shouldGetKeyValueSupplier.

@Test
public void shouldGetKeyValueSupplier() {
    String value = "10";
    KeyValueEntity entity = KeyValueEntity.of(value, value);
    assertEquals(value, entity.getValue());
    assertEquals(Integer.valueOf(10), entity.getKey(Integer.class));
    assertThat(singletonList(10), Matchers.contains(entity.getValue(new TypeReference<List<Integer>>() {
    }).get(0)));
}
Also used : TypeReference(jakarta.nosql.TypeReference) KeyValueEntity(jakarta.nosql.keyvalue.KeyValueEntity) Test(org.junit.jupiter.api.Test)

Example 23 with KeyValueEntity

use of jakarta.nosql.keyvalue.KeyValueEntity in project jnosql-diana by eclipse.

the class DefaultKeyValueEntityTest method shouldGetKeyClass.

@Test
public void shouldGetKeyClass() {
    Value value = Value.of("value");
    KeyValueEntity entity = KeyValueEntity.of("10", value);
    assertNotNull(entity);
    assertEquals(Long.valueOf(10L), entity.getKey(Long.class));
}
Also used : Value(jakarta.nosql.Value) KeyValueEntity(jakarta.nosql.keyvalue.KeyValueEntity) Test(org.junit.jupiter.api.Test)

Example 24 with KeyValueEntity

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

Example 25 with KeyValueEntity

use of jakarta.nosql.keyvalue.KeyValueEntity 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)

Aggregations

KeyValueEntity (jakarta.nosql.keyvalue.KeyValueEntity)38 Test (org.junit.jupiter.api.Test)31 User (jakarta.nosql.tck.entities.User)11 Duration (java.time.Duration)7 Value (jakarta.nosql.Value)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ValueSource (org.junit.jupiter.params.provider.ValueSource)6 TypeReference (jakarta.nosql.TypeReference)3 KeyValuePreparedStatement (jakarta.nosql.keyvalue.KeyValuePreparedStatement)3 Params (jakarta.nosql.Params)2 QueryException (jakarta.nosql.QueryException)1 KeyValueEntityPostPersist (jakarta.nosql.mapping.keyvalue.KeyValueEntityPostPersist)1 KeyValueEntityPrePersist (jakarta.nosql.mapping.keyvalue.KeyValueEntityPrePersist)1 PutQuery (jakarta.nosql.query.PutQuery)1 Car (jakarta.nosql.tck.entities.Car)1 Person (jakarta.nosql.tck.entities.Person)1 User (org.eclipse.jnosql.communication.hazelcast.keyvalue.model.User)1 User (org.eclipse.jnosql.communication.infinispan.keyvalue.model.User)1 User (org.eclipse.jnosql.communication.memcached.keyvalue.model.User)1