Search in sources :

Example 16 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.

the class DeleteQueryParserTest method shouldReturnParserQuery22.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where name not like \"Ada\"" })
public void shouldReturnParserQuery22(String query) {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    parser.query(query, documentCollection, observer);
    Mockito.verify(documentCollection).delete(captor.capture());
    DocumentDeleteQuery documentQuery = captor.getValue();
    checkBaseQuery(documentQuery);
    assertTrue(documentQuery.getCondition().isPresent());
    DocumentCondition condition = documentQuery.getCondition().get();
    Document document = condition.getDocument();
    assertEquals(Condition.NOT, condition.getCondition());
    List<DocumentCondition> conditions = document.get(new TypeReference<List<DocumentCondition>>() {
    });
    DocumentCondition documentCondition = conditions.get(0);
    assertEquals(Condition.LIKE, documentCondition.getCondition());
    assertEquals(Document.of("name", "Ada"), documentCondition.getDocument());
}
Also used : List(java.util.List) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.

the class DeleteQueryParserTest method shouldReturnParserQuery20.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete  from God where name in (\"Ada\", \"Apollo\")" })
public void shouldReturnParserQuery20(String query) {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    parser.query(query, documentCollection, observer);
    Mockito.verify(documentCollection).delete(captor.capture());
    DocumentDeleteQuery documentQuery = captor.getValue();
    checkBaseQuery(documentQuery);
    assertTrue(documentQuery.getCondition().isPresent());
    DocumentCondition condition = documentQuery.getCondition().get();
    Document document = condition.getDocument();
    assertEquals(Condition.IN, condition.getCondition());
    assertEquals("name", document.getName());
    List<String> values = document.get(new TypeReference<List<String>>() {
    });
    assertThat(values, containsInAnyOrder("Ada", "Apollo"));
}
Also used : List(java.util.List) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.

the class DeleteQueryParserTest method shouldReturnParserQuery18.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete  from God where siblings = {\"apollo\": \"Brother\", \"Zeus\": \"Father\"}" })
public void shouldReturnParserQuery18(String query) {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    parser.query(query, documentCollection, observer);
    Mockito.verify(documentCollection).delete(captor.capture());
    DocumentDeleteQuery documentQuery = captor.getValue();
    checkBaseQuery(documentQuery);
    assertTrue(documentQuery.getCondition().isPresent());
    DocumentCondition condition = documentQuery.getCondition().get();
    assertEquals(Condition.EQUALS, condition.getCondition());
    Document document = condition.getDocument();
    List<Document> documents = document.get(new TypeReference<List<Document>>() {
    });
    assertThat(documents, containsInAnyOrder(Document.of("apollo", "Brother"), Document.of("Zeus", "Father")));
    assertEquals("siblings", document.getName());
}
Also used : List(java.util.List) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 19 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.

the class DeleteQueryParserTest method shouldReturnParserQuery21.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where name like \"Ada\"" })
public void shouldReturnParserQuery21(String query) {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    parser.query(query, documentCollection, observer);
    Mockito.verify(documentCollection).delete(captor.capture());
    DocumentDeleteQuery documentQuery = captor.getValue();
    checkBaseQuery(documentQuery);
    assertTrue(documentQuery.getCondition().isPresent());
    DocumentCondition condition = documentQuery.getCondition().get();
    Document document = condition.getDocument();
    assertEquals(Condition.LIKE, condition.getCondition());
    assertEquals("name", document.getName());
    assertEquals("Ada", document.get());
}
Also used : Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.

the class DeleteQueryParserTest method shouldReturnParserQuery23.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete  from God where name = \"Ada\" and age = 20" })
public void shouldReturnParserQuery23(String query) {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    parser.query(query, documentCollection, observer);
    Mockito.verify(documentCollection).delete(captor.capture());
    DocumentDeleteQuery documentQuery = captor.getValue();
    checkBaseQuery(documentQuery);
    assertTrue(documentQuery.getCondition().isPresent());
    DocumentCondition condition = documentQuery.getCondition().get();
    Document document = condition.getDocument();
    assertEquals(Condition.AND, condition.getCondition());
    List<DocumentCondition> conditions = document.get(new TypeReference<List<DocumentCondition>>() {
    });
    assertThat(conditions, contains(eq(Document.of("name", "Ada")), eq(Document.of("age", 20L))));
}
Also used : List(java.util.List) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)114 Test (org.junit.jupiter.api.Test)79 DocumentEntity (jakarta.nosql.document.DocumentEntity)45 DocumentQuery (jakarta.nosql.document.DocumentQuery)43 Document (jakarta.nosql.document.Document)37 DocumentCondition (jakarta.nosql.document.DocumentCondition)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 ValueSource (org.junit.jupiter.params.provider.ValueSource)20 List (java.util.List)15 Person (jakarta.nosql.tck.entities.Person)12 Collectors (java.util.stream.Collectors)7 Params (jakarta.nosql.Params)5 DocumentDeleteQueryParams (jakarta.nosql.document.DocumentDeleteQueryParams)5 Duration (java.time.Duration)5 HashMap (java.util.HashMap)5 Optional (java.util.Optional)5 StreamSupport (java.util.stream.StreamSupport)5 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)4 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)4 Map (java.util.Map)4