Search in sources :

Example 21 with SelectQuery

use of jakarta.nosql.query.SelectQuery 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 22 with SelectQuery

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

the class FindByMethodQueryProviderTest method shouldRunQuery30.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "findBySalary_CurrencyAndCredential_Role" })
public void shouldRunQuery30(String query) {
    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();
    Assertions.assertEquals(Operator.AND, condition.getOperator());
    final QueryValue<?> value = condition.getValue();
    Condition condition1 = ConditionQueryValue.class.cast(value).get().get(0);
    Condition condition2 = ConditionQueryValue.class.cast(value).get().get(1);
    assertEquals("salary.currency", condition1.getName());
    assertEquals("credential.role", condition2.getName());
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) Where(jakarta.nosql.query.Where) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with SelectQuery

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

the class FindByMethodQueryProviderTest method checkEqualsQuery.

private void checkEqualsQuery(String query, String 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.EQUALS, condition.getOperator());
    assertEquals("name", condition.getName());
    assertTrue(value instanceof ParamQueryValue);
    assertTrue(ParamQueryValue.class.cast(value).get().contains("name"));
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) Where(jakarta.nosql.query.Where)

Example 24 with SelectQuery

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

the class FindByMethodQueryProviderTest method shouldReturnParserQuery.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "findBy" })
public void shouldReturnParserQuery(String query) {
    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();
    assertFalse(where.isPresent());
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Where(jakarta.nosql.query.Where) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with SelectQuery

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

the class FindByMethodQueryProviderTest method shouldReturnParserQuery28.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "findByAgeNotBetween" })
public void shouldReturnParserQuery28(String query) {
    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());
    Condition notCondition = MethodConditionValue.class.cast(value).get().get(0);
    assertEquals(Operator.BETWEEN, notCondition.getOperator());
    QueryValue<?>[] values = MethodArrayValue.class.cast(notCondition.getValue()).get();
    ParamQueryValue param1 = (ParamQueryValue) values[0];
    ParamQueryValue param2 = (ParamQueryValue) values[1];
    assertNotEquals(param2.get(), param1.get());
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) Where(jakarta.nosql.query.Where) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) ConditionQueryValue(jakarta.nosql.query.ConditionQueryValue) QueryValue(jakarta.nosql.query.QueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SelectQuery (jakarta.nosql.query.SelectQuery)55 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)36 ValueSource (org.junit.jupiter.params.provider.ValueSource)36 Where (jakarta.nosql.query.Where)32 Condition (jakarta.nosql.query.Condition)31 Params (jakarta.nosql.Params)12 ConditionQueryValue (jakarta.nosql.query.ConditionQueryValue)11 NumberQueryValue (jakarta.nosql.query.NumberQueryValue)11 StringQueryValue (jakarta.nosql.query.StringQueryValue)10 Sort (jakarta.nosql.Sort)9 ParamQueryValue (jakarta.nosql.query.ParamQueryValue)8 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)7 JsonObject (javax.json.JsonObject)7 SelectMethodProvider (org.eclipse.jnosql.communication.query.method.SelectMethodProvider)7 ColumnQuery (jakarta.nosql.column.ColumnQuery)6 ColumnQueryParams (jakarta.nosql.column.ColumnQueryParams)6 DocumentQuery (jakarta.nosql.document.DocumentQuery)6 DocumentQueryParams (jakarta.nosql.document.DocumentQueryParams)6 List (java.util.List)6 SelectQueryConverter (jakarta.nosql.document.SelectQueryConverter)5