Search in sources :

Example 6 with ParamQueryValue

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

the class InsertQueryProviderTest method shouldReturnParserQuery4.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (age = @age)" })
public void shouldReturnParserQuery4(String query) {
    InsertQuery insertQuery = checkInsertFromStart(query);
    List<Condition> conditions = insertQuery.getConditions();
    assertEquals(1, conditions.size());
    Condition condition = conditions.get(0);
    assertEquals("age", condition.getName());
    assertEquals(Operator.EQUALS, condition.getOperator());
    QueryValue<?> value = condition.getValue();
    assertTrue(value instanceof ParamQueryValue);
    assertEquals("age", ParamQueryValue.class.cast(value).get());
    assertFalse(insertQuery.getTtl().isPresent());
}
Also used : Condition(jakarta.nosql.query.Condition) InsertQuery(jakarta.nosql.query.InsertQuery) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with ParamQueryValue

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

the class DeleteByMethodQueryProviderTest method shouldReturnParserQuery27.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "deleteByAgeBetween" })
public void shouldReturnParserQuery27(String query) {
    Operator operator = Operator.BETWEEN;
    String entity = "entity";
    DeleteQuery deleteQuery = queryProvider.apply(query, entity);
    assertNotNull(deleteQuery);
    assertEquals(entity, deleteQuery.getEntity());
    assertTrue(deleteQuery.getFields().isEmpty());
    Optional<Where> where = deleteQuery.getWhere();
    assertTrue(where.isPresent());
    Condition condition = where.get().getCondition();
    QueryValue<?> value = condition.getValue();
    assertEquals(operator, condition.getOperator());
    QueryValue<?>[] values = MethodArrayValue.class.cast(value).get();
    ParamQueryValue param1 = (ParamQueryValue) values[0];
    ParamQueryValue param2 = (ParamQueryValue) values[1];
    assertNotEquals(param2.get(), param1.get());
}
Also used : Operator(jakarta.nosql.query.Operator) Condition(jakarta.nosql.query.Condition) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) DeleteQuery(jakarta.nosql.query.DeleteQuery) 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)

Example 8 with ParamQueryValue

use of jakarta.nosql.query.ParamQueryValue 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 9 with ParamQueryValue

use of jakarta.nosql.query.ParamQueryValue 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)

Example 10 with ParamQueryValue

use of jakarta.nosql.query.ParamQueryValue 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)

Aggregations

ParamQueryValue (jakarta.nosql.query.ParamQueryValue)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 ValueSource (org.junit.jupiter.params.provider.ValueSource)13 Condition (jakarta.nosql.query.Condition)10 Where (jakarta.nosql.query.Where)8 PutQuery (jakarta.nosql.query.PutQuery)5 Duration (java.time.Duration)5 ConditionQueryValue (jakarta.nosql.query.ConditionQueryValue)4 DeleteQuery (jakarta.nosql.query.DeleteQuery)4 QueryValue (jakarta.nosql.query.QueryValue)4 SelectQuery (jakarta.nosql.query.SelectQuery)4 Operator (jakarta.nosql.query.Operator)2 InsertQuery (jakarta.nosql.query.InsertQuery)1 UpdateQuery (jakarta.nosql.query.UpdateQuery)1