Search in sources :

Example 31 with Document

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

the class DocumentEntityTest method shouldRemoveDocumentByName.

@Test
public void shouldRemoveDocumentByName() {
    Document document = Document.of("name", "name");
    DocumentEntity entity = DocumentEntity.of("entity", singletonList(document));
    assertTrue(entity.remove("name"));
    assertTrue(entity.isEmpty());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 32 with Document

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

the class DocumentsTest method shouldCreateDocument.

@Test
public void shouldCreateDocument() {
    Document column = Documents.of("name", "Ada");
    assertEquals("name", column.getName());
    assertEquals("Ada", column.get());
}
Also used : Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 33 with Document

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

the class DeleteQueryParserTest method shouldReturnParserQuery19.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete  from God where age = convert(12, java.lang.Integer)" })
public void shouldReturnParserQuery19(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.EQUALS, condition.getCondition());
    assertEquals("age", document.getName());
    assertEquals(Value.of(12), document.getValue());
}
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 34 with Document

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

the class DeleteQueryParserTest method shouldReturnParserQuery26.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete  from God where name = \"Ada\" and age = 20 or" + " siblings = {\"apollo\": \"Brother\", \"Zeus\": \"Father\"} and birthday =" + " convert(\"2007-12-03\", java.time.LocalDate)" })
public void shouldReturnParserQuery26(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>>() {
    });
    assertEquals(Condition.EQUALS, conditions.get(0).getCondition());
    assertEquals(Condition.EQUALS, conditions.get(1).getCondition());
    assertEquals(Condition.OR, conditions.get(2).getCondition());
    assertEquals(Condition.EQUALS, conditions.get(3).getCondition());
}
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 35 with Document

use of jakarta.nosql.document.Document 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)

Aggregations

Document (jakarta.nosql.document.Document)196 Test (org.junit.jupiter.api.Test)140 DocumentEntity (jakarta.nosql.document.DocumentEntity)115 DocumentQuery (jakarta.nosql.document.DocumentQuery)93 DocumentCondition (jakarta.nosql.document.DocumentCondition)60 List (java.util.List)60 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)44 Arrays.asList (java.util.Arrays.asList)33 ArrayList (java.util.ArrayList)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 ValueSource (org.junit.jupiter.params.provider.ValueSource)26 TypeReference (jakarta.nosql.TypeReference)21 HashMap (java.util.HashMap)20 Map (java.util.Map)17 Collectors (java.util.stream.Collectors)16 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)14 Matchers.contains (org.hamcrest.Matchers.contains)14 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14