Search in sources :

Example 1 with KeyValueEntity

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

the class DefaultKeyValueEntityTest method shouldAliasOnValue.

@Test
public void shouldAliasOnValue() {
    String value = "10";
    KeyValueEntity entity = KeyValueEntity.of("key", value);
    assertEquals(value, entity.getValue());
    assertEquals(Integer.valueOf(10), entity.getValue(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 2 with KeyValueEntity

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

the class DefaultKeyValueEntityTest method shouldReturnErrorWhenGetKeyClassIsNull.

@Test
public void shouldReturnErrorWhenGetKeyClassIsNull() {
    Value value = Value.of("value");
    KeyValueEntity entity = KeyValueEntity.of("10", value);
    assertNotNull(entity);
    Assertions.assertThrows(NullPointerException.class, () -> entity.getKey((Class<Object>) null));
}
Also used : Value(jakarta.nosql.Value) KeyValueEntity(jakarta.nosql.keyvalue.KeyValueEntity) Test(org.junit.jupiter.api.Test)

Example 3 with KeyValueEntity

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

the class DefaultKeyValueEntityTest method shouldReturnErrorWhenGetKeySupplierIsNull.

@Test
public void shouldReturnErrorWhenGetKeySupplierIsNull() {
    Value value = Value.of("value");
    KeyValueEntity entity = KeyValueEntity.of("10", value);
    assertNotNull(entity);
    Assertions.assertThrows(NullPointerException.class, () -> entity.getKey((TypeReference<Object>) null));
}
Also used : Value(jakarta.nosql.Value) TypeReference(jakarta.nosql.TypeReference) KeyValueEntity(jakarta.nosql.keyvalue.KeyValueEntity) Test(org.junit.jupiter.api.Test)

Example 4 with KeyValueEntity

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

the class PutQueryParserTest method shouldReturnParserQuery2.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "put {\"Diana\", \"goddess of hunt\", 10 hour}" })
public void shouldReturnParserQuery2(String query) {
    ArgumentCaptor<KeyValueEntity> captor = ArgumentCaptor.forClass(KeyValueEntity.class);
    ArgumentCaptor<Duration> durationCaptor = ArgumentCaptor.forClass(Duration.class);
    parser.query(query, manager);
    Mockito.verify(manager).put(captor.capture(), durationCaptor.capture());
    KeyValueEntity entity = captor.getValue();
    Duration ttl = durationCaptor.getValue();
    assertEquals(Duration.ofHours(10), ttl);
    assertEquals("Diana", entity.getKey());
    assertEquals("goddess of hunt", entity.getValue());
}
Also used : Duration(java.time.Duration) KeyValueEntity(jakarta.nosql.keyvalue.KeyValueEntity) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with KeyValueEntity

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

the class DefaultKeyValueEntityConverterTest method shouldConvertToKeyWhenThereIsConverterAnnotation.

@Test
public void shouldConvertToKeyWhenThereIsConverterAnnotation() {
    Car car = new Car();
    car.setPlate(Plate.of("123-BRL"));
    car.setName("Ferrari");
    KeyValueEntity entity = converter.toKeyValue(car);
    Assertions.assertEquals("123-BRL", entity.getKey());
    Assertions.assertEquals(car, entity.getValue());
}
Also used : Car(jakarta.nosql.tck.entities.Car) KeyValueEntity(jakarta.nosql.keyvalue.KeyValueEntity) Test(org.junit.jupiter.api.Test)

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