use of jakarta.nosql.query.Condition in project jnosql-diana by eclipse.
the class FindByMethodQueryProviderTest method shouldRunQuery32.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "findBySalary_CurrencyOrderBySalary_Value" })
public void shouldRunQuery32(String query) {
String entity = "entity";
SelectQuery selectQuery = queryProvider.apply(query, entity);
assertNotNull(selectQuery);
assertEquals(entity, selectQuery.getEntity());
assertTrue(selectQuery.getFields().isEmpty());
assertFalse(selectQuery.getOrderBy().isEmpty());
assertEquals(0, selectQuery.getLimit());
assertEquals(0, selectQuery.getSkip());
Optional<Where> where = selectQuery.getWhere();
assertTrue(where.isPresent());
assertTrue(where.isPresent());
Condition condition = where.get().getCondition();
Assertions.assertEquals(Operator.EQUALS, condition.getOperator());
assertEquals("salary.currency", condition.getName());
final Sort sort = selectQuery.getOrderBy().get(0);
Assertions.assertEquals("salary.value", sort.getName());
}
use of jakarta.nosql.query.Condition in project jnosql-diana by eclipse.
the class InsertQueryProviderTest method shouldReturnParserQuery5.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (birthday = convert(\"1988-01-01\", java.time.LocalDate))" })
public void shouldReturnParserQuery5(String query) {
InsertQuery insertQuery = checkInsertFromStart(query);
List<Condition> conditions = insertQuery.getConditions();
assertEquals(1, conditions.size());
Condition condition = conditions.get(0);
assertEquals("birthday", condition.getName());
assertEquals(Operator.EQUALS, condition.getOperator());
QueryValue<?> value = condition.getValue();
assertTrue(value instanceof FunctionQueryValue);
Function function = FunctionQueryValue.class.cast(value).get();
assertEquals("convert", function.getName());
Object[] params = function.getParams();
assertEquals(2, params.length);
assertEquals("1988-01-01", StringQueryValue.class.cast(params[0]).get());
assertEquals(LocalDate.class, params[1]);
assertFalse(insertQuery.getTtl().isPresent());
}
use of jakarta.nosql.query.Condition in project jnosql-diana by eclipse.
the class InsertQueryProviderTest method shouldReturnParserQuery4.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (age = @age)" })
public void shouldReturnParserQuery4(String query) {
InsertQuery insertQuery = checkInsertFromStart(query);
List<Condition> conditions = insertQuery.getConditions();
assertEquals(1, conditions.size());
Condition condition = conditions.get(0);
assertEquals("age", condition.getName());
assertEquals(Operator.EQUALS, condition.getOperator());
QueryValue<?> value = condition.getValue();
assertTrue(value instanceof ParamQueryValue);
assertEquals("age", ParamQueryValue.class.cast(value).get());
assertFalse(insertQuery.getTtl().isPresent());
}
use of jakarta.nosql.query.Condition in project jnosql-diana by eclipse.
the class InsertQueryProviderTest method shouldReturnParserQuery6.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (age = 30, name = \"Artemis\")" })
public void shouldReturnParserQuery6(String query) {
InsertQuery insertQuery = checkInsertFromStart(query);
List<Condition> conditions = insertQuery.getConditions();
assertEquals(2, conditions.size());
Condition condition = conditions.get(0);
assertEquals("age", condition.getName());
assertEquals(Operator.EQUALS, condition.getOperator());
QueryValue<?> value = condition.getValue();
assertTrue(value instanceof NumberQueryValue);
assertEquals(30L, NumberQueryValue.class.cast(value).get());
condition = conditions.get(1);
assertEquals("name", condition.getName());
assertEquals(Operator.EQUALS, condition.getOperator());
value = condition.getValue();
assertTrue(value instanceof StringQueryValue);
assertEquals("Artemis", StringQueryValue.class.cast(value).get());
assertFalse(insertQuery.getTtl().isPresent());
}
use of jakarta.nosql.query.Condition in project jnosql-diana by eclipse.
the class DeleteByMethodQueryProviderTest method checkNotCondition.
private void checkNotCondition(String query, Operator operator, String variable) {
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(Operator.NOT, condition.getOperator());
assertEquals("_NOT", condition.getName());
assertTrue(value instanceof ConditionQueryValue);
Condition condition1 = ConditionQueryValue.class.cast(value).get().get(0);
QueryValue<?> param = condition1.getValue();
assertEquals(operator, condition1.getOperator());
assertTrue(ParamQueryValue.class.cast(param).get().contains(variable));
}
Aggregations