Search in sources :

Example 31 with Condition

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());
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) Sort(jakarta.nosql.Sort) Where(jakarta.nosql.query.Where) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 32 with Condition

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());
}
Also used : Condition(jakarta.nosql.query.Condition) InsertQuery(jakarta.nosql.query.InsertQuery) Function(jakarta.nosql.query.Function) JsonObject(javax.json.JsonObject) FunctionQueryValue(jakarta.nosql.query.FunctionQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 33 with Condition

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());
}
Also used : Condition(jakarta.nosql.query.Condition) InsertQuery(jakarta.nosql.query.InsertQuery) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 34 with Condition

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());
}
Also used : Condition(jakarta.nosql.query.Condition) NumberQueryValue(jakarta.nosql.query.NumberQueryValue) InsertQuery(jakarta.nosql.query.InsertQuery) StringQueryValue(jakarta.nosql.query.StringQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 35 with Condition

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

Aggregations

Condition (jakarta.nosql.query.Condition)79 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)66 ValueSource (org.junit.jupiter.params.provider.ValueSource)66 Where (jakarta.nosql.query.Where)61 SelectQuery (jakarta.nosql.query.SelectQuery)31 DeleteQuery (jakarta.nosql.query.DeleteQuery)29 NumberQueryValue (jakarta.nosql.query.NumberQueryValue)28 ConditionQueryValue (jakarta.nosql.query.ConditionQueryValue)25 StringQueryValue (jakarta.nosql.query.StringQueryValue)24 ParamQueryValue (jakarta.nosql.query.ParamQueryValue)18 JsonObject (javax.json.JsonObject)18 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)16 FunctionQueryValue (jakarta.nosql.query.FunctionQueryValue)10 ArrayQueryValue (jakarta.nosql.query.ArrayQueryValue)8 Function (jakarta.nosql.query.Function)8 InsertQuery (jakarta.nosql.query.InsertQuery)7 UpdateQuery (jakarta.nosql.query.UpdateQuery)7 QueryValue (jakarta.nosql.query.QueryValue)6 Operator (jakarta.nosql.query.Operator)3 ArrayList (java.util.ArrayList)2