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"));
}
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());
}
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());
}
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());
}
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));
}
Aggregations