Search in sources :

Example 1 with ArrayQueryValue

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

the class SelectQueryProviderTest method shouldReturnParserQuery22.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where name in (\"Ada\", \"Apollo\")" })
public void shouldReturnParserQuery22(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.IN, condition.getOperator());
    assertEquals("name", condition.getName());
    assertTrue(value instanceof ArrayQueryValue);
    List<?> values = Stream.of(ArrayQueryValue.class.cast(value).get()).map(QueryValue::get).collect(toList());
    assertThat(values, contains("Ada", "Apollo"));
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) Where(jakarta.nosql.query.Where) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ArrayQueryValue

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

the class DeleteQueryProviderTest method shouldReturnParserQuery8.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where age between 10 and 30" })
public void shouldReturnParserQuery8(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.BETWEEN, condition.getOperator());
    assertEquals("age", condition.getName());
    assertTrue(value instanceof ArrayQueryValue);
    ArrayQueryValue arrayValue = ArrayQueryValue.class.cast(value);
    QueryValue<?>[] values = arrayValue.get();
    assertThat(Stream.of(values).map(QueryValue::get).collect(toList()), contains(10L, 30L));
}
Also used : Condition(jakarta.nosql.query.Condition) DeleteQuery(jakarta.nosql.query.DeleteQuery) Where(jakarta.nosql.query.Where) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) FunctionQueryValue(jakarta.nosql.query.FunctionQueryValue) ConditionQueryValue(jakarta.nosql.query.ConditionQueryValue) StringQueryValue(jakarta.nosql.query.StringQueryValue) NumberQueryValue(jakarta.nosql.query.NumberQueryValue) QueryValue(jakarta.nosql.query.QueryValue) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) JSONQueryValue(jakarta.nosql.query.JSONQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ArrayQueryValue

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

the class DeleteQueryProviderTest method shouldReturnParserQuery10.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where name = {\"diana\"}" })
public void shouldReturnParserQuery10(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.EQUALS, condition.getOperator());
    assertEquals("name", condition.getName());
    assertTrue(value instanceof ArrayQueryValue);
    List<?> values = Stream.of(ArrayQueryValue.class.cast(value).get()).map(QueryValue::get).collect(toList());
    assertThat(values, contains("diana"));
}
Also used : Condition(jakarta.nosql.query.Condition) DeleteQuery(jakarta.nosql.query.DeleteQuery) Where(jakarta.nosql.query.Where) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ArrayQueryValue

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

the class DeleteQueryProviderTest method shouldReturnParserQuery11.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where name = {\"diana\", 17, 20.21}" })
public void shouldReturnParserQuery11(String query) {
    DeleteQuery selectQuery = checkDeleteFromStart(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 ArrayQueryValue);
    List<?> values = Stream.of(ArrayQueryValue.class.cast(value).get()).map(QueryValue::get).collect(toList());
    assertThat(values, contains("diana", 17L, 20.21));
}
Also used : Condition(jakarta.nosql.query.Condition) DeleteQuery(jakarta.nosql.query.DeleteQuery) Where(jakarta.nosql.query.Where) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with ArrayQueryValue

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

the class GetProviderTest method shouldReturnParserQuery5.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "get {1,12}" })
public void shouldReturnParserQuery5(String query) {
    GetQuery getQuery = queryProvider.apply(query);
    List<QueryValue<?>> keys = getQuery.getKeys();
    assertEquals(1, keys.size());
    QueryValue<?> key = keys.get(0);
    assertTrue(key instanceof ArrayQueryValue);
    QueryValue<?>[] values = ArrayQueryValue.class.cast(key).get();
    MatcherAssert.assertThat(Arrays.stream(values).map(QueryValue::get).collect(Collectors.toList()), Matchers.contains(1L, 12L));
}
Also used : GetQuery(jakarta.nosql.query.GetQuery) NumberQueryValue(jakarta.nosql.query.NumberQueryValue) QueryValue(jakarta.nosql.query.QueryValue) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) StringQueryValue(jakarta.nosql.query.StringQueryValue) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ArrayQueryValue (jakarta.nosql.query.ArrayQueryValue)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 ValueSource (org.junit.jupiter.params.provider.ValueSource)10 Condition (jakarta.nosql.query.Condition)8 Where (jakarta.nosql.query.Where)8 QueryValue (jakarta.nosql.query.QueryValue)5 StringQueryValue (jakarta.nosql.query.StringQueryValue)5 DeleteQuery (jakarta.nosql.query.DeleteQuery)4 NumberQueryValue (jakarta.nosql.query.NumberQueryValue)4 SelectQuery (jakarta.nosql.query.SelectQuery)4 ConditionQueryValue (jakarta.nosql.query.ConditionQueryValue)3 FunctionQueryValue (jakarta.nosql.query.FunctionQueryValue)2 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)2 ParamQueryValue (jakarta.nosql.query.ParamQueryValue)2 DelQuery (jakarta.nosql.query.DelQuery)1 GetQuery (jakarta.nosql.query.GetQuery)1 Operator (jakarta.nosql.query.Operator)1