Search in sources :

Example 41 with SelectQuery

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

the class SelectQueryProviderTest method shouldReturnParserQuery19.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where siblings = {\"apollo\": \"Brother\", \"Zeus\": \"Father\"}" })
public void shouldReturnParserQuery19(String query) {
    SelectQuery selectQuery = checkSelectFromStart(query);
    assertTrue(selectQuery.getWhere().isPresent());
    Where where = selectQuery.getWhere().get();
    Condition condition = where.getCondition();
    QueryValue<?> 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 : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) JsonObject(javax.json.JsonObject) Where(jakarta.nosql.query.Where) JSONQueryValue(jakarta.nosql.query.JSONQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 42 with SelectQuery

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

the class SelectQueryProviderTest method shouldReturnParserQuery4.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select name, address from God order by name desc" })
public void shouldReturnParserQuery4(String query) {
    SelectQuery selectQuery = selectQueryProvider.apply(query);
    assertEquals("God", selectQuery.getEntity());
    assertFalse(selectQuery.getFields().isEmpty());
    assertThat(selectQuery.getFields(), contains("name", "address"));
    assertFalse(selectQuery.getOrderBy().isEmpty());
    assertThat(selectQuery.getOrderBy().stream().map(Sort::getName).collect(toList()), contains("name"));
    MatcherAssert.assertThat(selectQuery.getOrderBy().stream().map(Sort::getType).collect(toList()), Matchers.contains(SortType.DESC));
    assertEquals(0, selectQuery.getLimit());
    assertEquals(0, selectQuery.getSkip());
    assertFalse(selectQuery.getWhere().isPresent());
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Sort(jakarta.nosql.Sort) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 43 with SelectQuery

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

the class SelectQueryProviderTest method shouldReturnParserQuery20.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where name = @name" })
public void shouldReturnParserQuery20(String query) {
    SelectQuery selectQuery = checkSelectFromStart(query);
    assertTrue(selectQuery.getWhere().isPresent());
    Where where = selectQuery.getWhere().get();
    Condition condition = where.getCondition();
    QueryValue<?> value = condition.getValue();
    Assertions.assertEquals(Operator.EQUALS, condition.getOperator());
    assertEquals("name", condition.getName());
    assertTrue(value instanceof ParamQueryValue);
    assertEquals("name", ParamQueryValue.class.cast(value).get());
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) Where(jakarta.nosql.query.Where) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 44 with SelectQuery

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

the class SelectQueryProviderTest method shouldReturnParserQuery3.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select name, address from God order by name" })
public void shouldReturnParserQuery3(String query) {
    SelectQuery selectQuery = selectQueryProvider.apply(query);
    assertEquals("God", selectQuery.getEntity());
    assertFalse(selectQuery.getFields().isEmpty());
    assertThat(selectQuery.getFields(), contains("name", "address"));
    assertFalse(selectQuery.getOrderBy().isEmpty());
    assertThat(selectQuery.getOrderBy().stream().map(Sort::getName).collect(toList()), contains("name"));
    MatcherAssert.assertThat(selectQuery.getOrderBy().stream().map(Sort::getType).collect(toList()), Matchers.contains(SortType.ASC));
    assertEquals(0, selectQuery.getLimit());
    assertEquals(0, selectQuery.getSkip());
    assertFalse(selectQuery.getWhere().isPresent());
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Sort(jakarta.nosql.Sort) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 45 with SelectQuery

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

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