use of jakarta.nosql.query.Condition in project jnosql-diana by eclipse.
the class UpdateQueryProviderTest method shouldReturnParserQuery.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update God (name = \"Diana\")" })
public void shouldReturnParserQuery(String query) {
UpdateQuery updateQuery = checkUpdateFromStart(query);
List<Condition> conditions = updateQuery.getConditions();
assertEquals(1, conditions.size());
Condition condition = conditions.get(0);
assertEquals("name", condition.getName());
assertEquals(Operator.EQUALS, condition.getOperator());
QueryValue<?> value = condition.getValue();
assertTrue(value instanceof StringQueryValue);
assertEquals("Diana", StringQueryValue.class.cast(value).get());
}
use of jakarta.nosql.query.Condition in project jnosql-diana by eclipse.
the class DeleteByMethodQueryProviderTest method checkAppendCondition.
private void checkAppendCondition(String query, Operator operator, Operator operator2, String variable, String variable2, Operator operatorAppender) {
String entity = "entity";
DeleteQuery deleteQuery = queryProvider.apply(query, entity);
assertNotNull(deleteQuery);
assertEquals(entity, deleteQuery.getEntity());
assertTrue(deleteQuery.getFields().isEmpty());
Optional<Where> where = deleteQuery.getWhere();
assertTrue(where.isPresent());
Condition condition = where.get().getCondition();
QueryValue<?> value = condition.getValue();
assertEquals(operatorAppender, condition.getOperator());
assertTrue(value instanceof ConditionQueryValue);
Condition condition1 = ConditionQueryValue.class.cast(value).get().get(0);
Condition condition2 = ConditionQueryValue.class.cast(value).get().get(1);
assertEquals(operator, condition1.getOperator());
QueryValue<?> param = condition1.getValue();
assertEquals(operator, condition1.getOperator());
assertTrue(ParamQueryValue.class.cast(param).get().contains(variable));
assertEquals(operator2, condition2.getOperator());
QueryValue<?> param2 = condition2.getValue();
assertEquals(condition2.getOperator(), operator2);
assertTrue(ParamQueryValue.class.cast(param2).get().contains(variable2));
}
use of jakarta.nosql.query.Condition in project jnosql-diana by eclipse.
the class FindByMethodQueryProviderTest method checkCondition.
private void checkCondition(String query, Operator operator, String variable) {
String entity = "entity";
SelectQuery selectQuery = queryProvider.apply(query, entity);
assertNotNull(selectQuery);
assertEquals(entity, selectQuery.getEntity());
assertTrue(selectQuery.getFields().isEmpty());
assertTrue(selectQuery.getOrderBy().isEmpty());
assertEquals(0, selectQuery.getLimit());
assertEquals(0, selectQuery.getSkip());
Optional<Where> where = selectQuery.getWhere();
assertTrue(where.isPresent());
Condition condition = where.get().getCondition();
QueryValue<?> value = condition.getValue();
assertEquals(operator, condition.getOperator());
assertTrue(ParamQueryValue.class.cast(value).get().contains(variable));
}
use of jakarta.nosql.query.Condition in project jnosql-diana by eclipse.
the class InsertQueryProviderTest method shouldReturnParserQuery.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = \"Diana\")" })
public void shouldReturnParserQuery(String query) {
InsertQuery insertQuery = checkInsertFromStart(query);
List<Condition> conditions = insertQuery.getConditions();
assertEquals(1, conditions.size());
Condition condition = conditions.get(0);
assertEquals("name", condition.getName());
assertEquals(Operator.EQUALS, condition.getOperator());
QueryValue<?> value = condition.getValue();
assertTrue(value instanceof StringQueryValue);
assertEquals("Diana", StringQueryValue.class.cast(value).get());
assertFalse(insertQuery.getTtl().isPresent());
}
use of jakarta.nosql.query.Condition in project jnosql-diana by eclipse.
the class InsertQueryProviderTest method shouldReturnParserQuery2.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (stamina = 32.23)" })
public void shouldReturnParserQuery2(String query) {
InsertQuery insertQuery = checkInsertFromStart(query);
List<Condition> conditions = insertQuery.getConditions();
assertEquals(1, conditions.size());
Condition condition = conditions.get(0);
assertEquals("stamina", condition.getName());
assertEquals(Operator.EQUALS, condition.getOperator());
QueryValue<?> value = condition.getValue();
assertTrue(value instanceof NumberQueryValue);
assertEquals(32.23, NumberQueryValue.class.cast(value).get());
assertFalse(insertQuery.getTtl().isPresent());
}
Aggregations