Search in sources :

Example 6 with InsertQuery

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());
}
Also used : Condition(jakarta.nosql.query.Condition) InsertQuery(jakarta.nosql.query.InsertQuery) Function(jakarta.nosql.query.Function) JsonObject(javax.json.JsonObject) FunctionQueryValue(jakarta.nosql.query.FunctionQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with InsertQuery

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"));
}
Also used : JsonArray(javax.json.JsonArray) InsertQuery(jakarta.nosql.query.InsertQuery) 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 InsertQuery

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());
}
Also used : InsertQuery(jakarta.nosql.query.InsertQuery) JsonObject(javax.json.JsonObject) JSONQueryValue(jakarta.nosql.query.JSONQueryValue)

Example 9 with InsertQuery

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());
}
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 10 with InsertQuery

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));
}
Also used : InsertQuery(jakarta.nosql.query.InsertQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

InsertQuery (jakarta.nosql.query.InsertQuery)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 ValueSource (org.junit.jupiter.params.provider.ValueSource)16 Condition (jakarta.nosql.query.Condition)7 JsonObject (javax.json.JsonObject)5 Params (jakarta.nosql.Params)4 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)4 Duration (java.time.Duration)4 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