Search in sources :

Example 96 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.

the class InsertQueryParserTest method shouldReturnParserQuery3.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = \"Diana\") 10 hour" })
public void shouldReturnParserQuery3(String query) {
    ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
    ArgumentCaptor<Duration> durationCaptor = ArgumentCaptor.forClass(Duration.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).insert(captor.capture(), durationCaptor.capture());
    ColumnEntity entity = captor.getValue();
    Duration duration = durationCaptor.getValue();
    assertEquals("God", entity.getName());
    assertEquals(Column.of("name", "Diana"), entity.find("name").get());
    assertEquals(Duration.ofHours(10L), duration);
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Duration(java.time.Duration) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 97 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.

the class InsertQueryParserTest method shouldReturnParserQuery7.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = \"Diana\") 10 nanosecond" })
public void shouldReturnParserQuery7(String query) {
    ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
    ArgumentCaptor<Duration> durationCaptor = ArgumentCaptor.forClass(Duration.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).insert(captor.capture(), durationCaptor.capture());
    ColumnEntity entity = captor.getValue();
    Duration duration = durationCaptor.getValue();
    assertEquals("God", entity.getName());
    assertEquals(Column.of("name", "Diana"), entity.find("name").get());
    assertEquals(Duration.ofNanos(10L), duration);
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Duration(java.time.Duration) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 98 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.

the class UpdateQueryParserTest method shouldReturnParserQuery3.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update Person {\"name\":\"Ada Lovelace\"}" })
public void shouldReturnParserQuery3(String query) {
    ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).update(captor.capture());
    ColumnEntity entity = captor.getValue();
    assertEquals("Person", entity.getName());
    assertEquals(Column.of("name", "Ada Lovelace"), entity.find("name").get());
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 99 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.

the class UpdateQueryParserTest method shouldReturnParserQuery1.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update God (age = 30, name = \"Artemis\")" })
public void shouldReturnParserQuery1(String query) {
    ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).update(captor.capture());
    ColumnEntity entity = captor.getValue();
    assertEquals("God", entity.getName());
    assertEquals(Column.of("name", "Artemis"), entity.find("name").get());
    assertEquals(Column.of("age", 30L), entity.find("age").get());
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 100 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.

the class ConditionQueryParser method getEntity.

protected ColumnEntity getEntity(ConditionQuerySupplier query, String columnFamily, Params params, ColumnObserverParser observer) {
    ColumnEntity entity = ColumnEntity.of(columnFamily);
    if (query.useJSONCondition()) {
        JSONQueryValue jsonValue = query.getValue().orElseThrow(() -> new QueryException("It is an invalid state of" + " either Update or Insert."));
        List<Column> columns = JsonObjects.getColumns(jsonValue.get());
        entity.addAll(columns);
        return entity;
    }
    query.getConditions().stream().map(c -> Conditions.getCondition(c, params, observer, columnFamily)).map(ColumnCondition::getColumn).forEach(entity::add);
    return entity;
}
Also used : QueryException(jakarta.nosql.QueryException) ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) JSONQueryValue(jakarta.nosql.query.JSONQueryValue)

Aggregations

ColumnEntity (jakarta.nosql.column.ColumnEntity)146 Test (org.junit.jupiter.api.Test)103 Column (jakarta.nosql.column.Column)39 ColumnQuery (jakarta.nosql.column.ColumnQuery)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 ValueSource (org.junit.jupiter.params.provider.ValueSource)23 Duration (java.time.Duration)13 ArrayList (java.util.ArrayList)13 List (java.util.List)13 Arrays.asList (java.util.Arrays.asList)11 Person (jakarta.nosql.tck.entities.Person)9 ColumnFamilyManager (jakarta.nosql.column.ColumnFamilyManager)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 Value (jakarta.nosql.Value)6 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)6 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)5 Actor (jakarta.nosql.tck.entities.Actor)5 Director (jakarta.nosql.tck.entities.Director)5 Movie (jakarta.nosql.tck.entities.Movie)5