use of jakarta.nosql.query.InsertQuery in project jnosql-diana by eclipse.
the class InsertQueryProviderTest method shouldReturnParserQuery5.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (birthday = convert(\"1988-01-01\", java.time.LocalDate))" })
public void shouldReturnParserQuery5(String query) {
InsertQuery insertQuery = checkInsertFromStart(query);
List<Condition> conditions = insertQuery.getConditions();
assertEquals(1, conditions.size());
Condition condition = conditions.get(0);
assertEquals("birthday", condition.getName());
assertEquals(Operator.EQUALS, condition.getOperator());
QueryValue<?> value = condition.getValue();
assertTrue(value instanceof FunctionQueryValue);
Function function = FunctionQueryValue.class.cast(value).get();
assertEquals("convert", function.getName());
Object[] params = function.getParams();
assertEquals(2, params.length);
assertEquals("1988-01-01", StringQueryValue.class.cast(params[0]).get());
assertEquals(LocalDate.class, params[1]);
assertFalse(insertQuery.getTtl().isPresent());
}
use of jakarta.nosql.query.InsertQuery in project jnosql-diana by eclipse.
the class InsertQueryProviderTest method shouldReturnParserQuery21.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert Person {\"name\": \"Ada Lovelace\", \"age\": 12, \"sibling\":" + " [\"Ana\" ,\"Maria\"]," + " \"address\":{\"country\": \"United Kingdom\", \"city\": \"London\"}}" })
public void shouldReturnParserQuery21(String query) {
InsertQuery insertQuery = insertQueryProvider.apply(query);
assertEquals("Person", insertQuery.getEntity());
Assertions.assertTrue(insertQuery.getConditions().isEmpty());
Assertions.assertTrue(insertQuery.getValue().isPresent());
JSONQueryValue JSONQueryValue = insertQuery.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.InsertQuery in project jnosql-diana by eclipse.
the class InsertQueryProviderTest method checkJSONInsertQuery.
private void checkJSONInsertQuery(String query, Duration duration) {
InsertQuery insertQuery = insertQueryProvider.apply(query);
assertEquals("Person", insertQuery.getEntity());
Assertions.assertTrue(insertQuery.getConditions().isEmpty());
Assertions.assertTrue(insertQuery.getValue().isPresent());
JSONQueryValue JSONQueryValue = insertQuery.getValue().get();
JsonObject jsonObject = JSONQueryValue.get();
assertEquals("Ada Lovelace", jsonObject.getString("name"));
assertEquals(duration, insertQuery.getTtl().get());
}
use of jakarta.nosql.query.InsertQuery 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());
}
use of jakarta.nosql.query.InsertQuery in project jnosql-diana by eclipse.
the class InsertQueryProviderTest method shouldReturnParserQuery7.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = \"Diana\") 10 day" })
public void shouldReturnParserQuery7(String query) {
InsertQuery insertQuery = checkInsertFromStart(query);
checkTTL(insertQuery, Duration.ofDays(10L));
}
Aggregations