Search in sources :

Example 16 with ConditionQueryValue

use of jakarta.nosql.query.ConditionQueryValue in project jnosql-diana by eclipse.

the class DeleteQueryProviderTest method shouldReturnParserQuery17.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where name not like \"Ada\"" })
public void shouldReturnParserQuery17(String query) {
    DeleteQuery deleteQuery = checkDeleteFromStart(query);
    assertTrue(deleteQuery.getWhere().isPresent());
    Where where = deleteQuery.getWhere().get();
    Condition condition = where.getCondition();
    QueryValue<?> value = condition.getValue();
    Assertions.assertEquals(Operator.NOT, condition.getOperator());
    assertEquals("_NOT", condition.getName());
    assertTrue(value instanceof ConditionQueryValue);
    List<Condition> conditions = ConditionQueryValue.class.cast(value).get();
    assertEquals(1, conditions.size());
    condition = conditions.get(0);
    value = condition.getValue();
    Assertions.assertEquals(Operator.LIKE, condition.getOperator());
    assertEquals("name", condition.getName());
    assertTrue(value instanceof StringQueryValue);
    assertEquals("Ada", StringQueryValue.class.cast(value).get());
}
Also used : Condition(jakarta.nosql.query.Condition) ConditionQueryValue(jakarta.nosql.query.ConditionQueryValue) DeleteQuery(jakarta.nosql.query.DeleteQuery) StringQueryValue(jakarta.nosql.query.StringQueryValue) Where(jakarta.nosql.query.Where) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with ConditionQueryValue

use of jakarta.nosql.query.ConditionQueryValue in project jnosql-diana by eclipse.

the class DeleteQueryProviderTest method shouldReturnParserQuery19.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where name = \"Ada\" or age = 20 or" + " siblings = {\"apollo\": \"Brother\", \"Zeus\": \"Father\"}" })
public void shouldReturnParserQuery19(String query) {
    DeleteQuery deleteQuery = checkDeleteFromStart(query);
    assertTrue(deleteQuery.getWhere().isPresent());
    Where where = deleteQuery.getWhere().get();
    Condition condition = where.getCondition();
    QueryValue<?> value = condition.getValue();
    Assertions.assertEquals(Operator.OR, condition.getOperator());
    assertEquals("_OR", condition.getName());
    assertTrue(value instanceof ConditionQueryValue);
    List<Condition> conditions = ConditionQueryValue.class.cast(value).get();
    assertEquals(3, conditions.size());
    condition = conditions.get(0);
    value = condition.getValue();
    Assertions.assertEquals(Operator.EQUALS, condition.getOperator());
    assertEquals("name", condition.getName());
    assertTrue(value instanceof StringQueryValue);
    assertEquals("Ada", StringQueryValue.class.cast(value).get());
    condition = conditions.get(1);
    value = condition.getValue();
    Assertions.assertEquals(Operator.EQUALS, condition.getOperator());
    assertEquals("age", condition.getName());
    assertTrue(value instanceof NumberQueryValue);
    assertEquals(20L, NumberQueryValue.class.cast(value).get());
    condition = conditions.get(2);
    value = condition.getValue();
    Assertions.assertEquals(Operator.EQUALS, condition.getOperator());
    assertEquals("siblings", condition.getName());
    assertTrue(value instanceof JSONQueryValue);
    JsonObject jsonObject = JSONQueryValue.class.cast(value).get();
    assertEquals("Brother", jsonObject.getString("apollo"));
    assertEquals("Father", jsonObject.getString("Zeus"));
}
Also used : Condition(jakarta.nosql.query.Condition) NumberQueryValue(jakarta.nosql.query.NumberQueryValue) ConditionQueryValue(jakarta.nosql.query.ConditionQueryValue) JsonObject(javax.json.JsonObject) DeleteQuery(jakarta.nosql.query.DeleteQuery) StringQueryValue(jakarta.nosql.query.StringQueryValue) Where(jakarta.nosql.query.Where) JSONQueryValue(jakarta.nosql.query.JSONQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with ConditionQueryValue

use of jakarta.nosql.query.ConditionQueryValue in project jnosql-diana by eclipse.

the class FindByMethodQueryProviderTest method checkAppendCondition.

private void checkAppendCondition(String query, Operator operator, Operator operator2, String variable, String variable2, Operator operatorAppender) {
    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(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));
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) ConditionQueryValue(jakarta.nosql.query.ConditionQueryValue) Where(jakarta.nosql.query.Where)

Example 19 with ConditionQueryValue

use of jakarta.nosql.query.ConditionQueryValue in project jnosql-diana by eclipse.

the class FindByMethodQueryProviderTest method checkNotCondition.

private void checkNotCondition(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.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));
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) ConditionQueryValue(jakarta.nosql.query.ConditionQueryValue) Where(jakarta.nosql.query.Where)

Aggregations

Condition (jakarta.nosql.query.Condition)19 ConditionQueryValue (jakarta.nosql.query.ConditionQueryValue)19 Where (jakarta.nosql.query.Where)16 StringQueryValue (jakarta.nosql.query.StringQueryValue)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 ValueSource (org.junit.jupiter.params.provider.ValueSource)12 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)10 NumberQueryValue (jakarta.nosql.query.NumberQueryValue)10 JsonObject (javax.json.JsonObject)10 DeleteQuery (jakarta.nosql.query.DeleteQuery)8 SelectQuery (jakarta.nosql.query.SelectQuery)8 Function (jakarta.nosql.query.Function)4 FunctionQueryValue (jakarta.nosql.query.FunctionQueryValue)4 ParamQueryValue (jakarta.nosql.query.ParamQueryValue)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Operator (jakarta.nosql.query.Operator)1