Search in sources :

Example 6 with ArrayQueryValue

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

the class SelectQueryProviderTest method shouldReturnParserQuery18.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where name = {\"diana\", 17, 20.21}" })
public void shouldReturnParserQuery18(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 ArrayQueryValue);
    List<?> values = Stream.of(ArrayQueryValue.class.cast(value).get()).map(QueryValue::get).collect(toList());
    assertThat(values, contains("diana", 17L, 20.21));
}
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 7 with ArrayQueryValue

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

the class SelectQueryProviderTest method shouldReturnParserQuery14.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where age between 10 and 30" })
public void shouldReturnParserQuery14(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.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 : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) 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 8 with ArrayQueryValue

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

the class SelectQueryProviderTest method shouldReturnParserQuery17.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where name = {\"diana\"}" })
public void shouldReturnParserQuery17(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 ArrayQueryValue);
    List<?> values = Stream.of(ArrayQueryValue.class.cast(value).get()).map(QueryValue::get).collect(toList());
    assertThat(values, contains("diana"));
}
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 9 with ArrayQueryValue

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

the class RemoveProviderTest method shouldReturnParserQuery5.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "del {1,12}" })
public void shouldReturnParserQuery5(String query) {
    DelQuery delQuery = provider.apply(query);
    List<QueryValue<?>> keys = delQuery.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 : DelQuery(jakarta.nosql.query.DelQuery) 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)

Example 10 with ArrayQueryValue

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

the class DeleteQueryProviderTest method shouldReturnParserQuery15.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where name in (\"Ada\", \"Apollo\")" })
public void shouldReturnParserQuery15(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.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 : 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)

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