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