Search in sources :

Example 6 with UpdateQuery

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

the class UpdateQueryProviderTest method shouldReturnParserQuery1.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update God (age = 30)" })
public void shouldReturnParserQuery1(String query) {
    UpdateQuery updateQuery = checkUpdateFromStart(query);
    List<Condition> conditions = updateQuery.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 NumberQueryValue);
    assertEquals(30L, NumberQueryValue.class.cast(value).get());
}
Also used : Condition(jakarta.nosql.query.Condition) NumberQueryValue(jakarta.nosql.query.NumberQueryValue) UpdateQuery(jakarta.nosql.query.UpdateQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with UpdateQuery

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

the class UpdateQueryProviderTest method shouldReturnParserQuery8.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update Person {\"name\": \"Ada Lovelace\", \"age\": 12, \"sibling\":" + " [\"Ana\" ,\"Maria\"]," + " \"address\":{\"country\": \"United Kingdom\", \"city\": \"London\"}}" })
public void shouldReturnParserQuery8(String query) {
    UpdateQuery updateQuery = update.apply(query);
    assertEquals("Person", updateQuery.getEntity());
    Assertions.assertTrue(updateQuery.getConditions().isEmpty());
    Assertions.assertTrue(updateQuery.getValue().isPresent());
    JSONQueryValue JSONQueryValue = updateQuery.getValue().get();
    JsonObject jsonObject = JSONQueryValue.get();
    JsonArray sibling = jsonObject.getJsonArray("sibling");
    JsonObject address = jsonObject.getJsonObject("address");
    assertEquals("Ada Lovelace", jsonObject.getString("name"));
    assertEquals("Ana", sibling.getString(0));
    assertEquals("Maria", sibling.getString(1));
    assertEquals("United Kingdom", address.getString("country"));
    assertEquals("London", address.getString("city"));
}
Also used : JsonArray(javax.json.JsonArray) UpdateQuery(jakarta.nosql.query.UpdateQuery) JsonObject(javax.json.JsonObject) JSONQueryValue(jakarta.nosql.query.JSONQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with UpdateQuery

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

the class UpdateQueryProviderTest method checkUpdateFromStart.

private UpdateQuery checkUpdateFromStart(String query) {
    UpdateQuery updateQuery = update.apply(query);
    assertEquals("God", updateQuery.getEntity());
    return updateQuery;
}
Also used : UpdateQuery(jakarta.nosql.query.UpdateQuery)

Example 9 with UpdateQuery

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

the class UpdateQueryProviderTest method shouldReturnParserQuery4.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update God (age = @age)" })
public void shouldReturnParserQuery4(String query) {
    UpdateQuery updateQuery = checkUpdateFromStart(query);
    List<Condition> conditions = updateQuery.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());
}
Also used : Condition(jakarta.nosql.query.Condition) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) UpdateQuery(jakarta.nosql.query.UpdateQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with UpdateQuery

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

the class UpdateQueryProviderTest method shouldReturnParserQuery7.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update Person {\"name\":\"Ada Lovelace\"}" })
public void shouldReturnParserQuery7(String query) {
    UpdateQuery updateQuery = update.apply(query);
    assertEquals("Person", updateQuery.getEntity());
    Assertions.assertTrue(updateQuery.getConditions().isEmpty());
    Assertions.assertTrue(updateQuery.getValue().isPresent());
    JSONQueryValue JSONQueryValue = updateQuery.getValue().get();
    JsonObject jsonObject = JSONQueryValue.get();
    assertEquals("Ada Lovelace", jsonObject.getString("name"));
}
Also used : UpdateQuery(jakarta.nosql.query.UpdateQuery) JsonObject(javax.json.JsonObject) JSONQueryValue(jakarta.nosql.query.JSONQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

UpdateQuery (jakarta.nosql.query.UpdateQuery)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 ValueSource (org.junit.jupiter.params.provider.ValueSource)9 Condition (jakarta.nosql.query.Condition)7 Params (jakarta.nosql.Params)4 JsonObject (javax.json.JsonObject)4 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)3 NumberQueryValue (jakarta.nosql.query.NumberQueryValue)3 QueryException (jakarta.nosql.QueryException)2 ColumnEntity (jakarta.nosql.column.ColumnEntity)2 DocumentEntity (jakarta.nosql.document.DocumentEntity)2 StringQueryValue (jakarta.nosql.query.StringQueryValue)2 Function (jakarta.nosql.query.Function)1 FunctionQueryValue (jakarta.nosql.query.FunctionQueryValue)1 ParamQueryValue (jakarta.nosql.query.ParamQueryValue)1 JsonArray (javax.json.JsonArray)1