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);
}
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);
}
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());
}
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());
}
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;
}
Aggregations