Search in sources :

Example 26 with Document

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

the class DocumentEntityTest method shouldReturnErrorWhenFindDocumentIsNull.

@Test
public void shouldReturnErrorWhenFindDocumentIsNull() {
    Assertions.assertThrows(NullPointerException.class, () -> {
        Document document = Document.of("name", "name");
        DocumentEntity entity = DocumentEntity.of("entity", singletonList(document));
        entity.find(null);
    });
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 27 with Document

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

the class DocumentEntityTest method shouldFindDocument.

@Test
public void shouldFindDocument() {
    Document document = Document.of("name", "name");
    DocumentEntity entity = DocumentEntity.of("entity", singletonList(document));
    Optional<Document> name = entity.find("name");
    Optional<Document> notfound = entity.find("not_found");
    assertTrue(name.isPresent());
    assertFalse(notfound.isPresent());
    assertEquals(document, name.get());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 28 with Document

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

the class DocumentEntityTest method shouldAvoidDuplicatedDocumentWhenAddList.

@Test
public void shouldAvoidDuplicatedDocumentWhenAddList() {
    List<Document> documents = asList(Document.of("name", 10), Document.of("name", 13));
    DocumentEntity entity = new DefaultDocumentEntity("documentCollection");
    entity.addAll(documents);
    assertEquals(1, entity.size());
    assertEquals(1, DocumentEntity.of("documentCollection", documents).size());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 29 with Document

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

the class DocumentEntityTest method shouldReturnTrueWhenContainsElement.

@Test
public void shouldReturnTrueWhenContainsElement() {
    List<Document> documents = asList(Document.of("name", 10), Document.of("name2", 11), Document.of("name3", 12), Document.of("name4", 13), Document.of("name5", 14), Document.of("name5", 16));
    DocumentEntity collection = DocumentEntity.of("documentCollection", documents);
    assertTrue(collection.contains("name"));
    assertTrue(collection.contains("name2"));
    assertTrue(collection.contains("name3"));
    assertTrue(collection.contains("name4"));
    assertTrue(collection.contains("name5"));
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 30 with Document

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

the class DocumentEntityTest method shouldConvertSubDocumentListToMap.

@Test
public void shouldConvertSubDocumentListToMap() {
    DocumentEntity entity = DocumentEntity.of("entity");
    entity.add(Document.of("_id", "id"));
    List<Document> documents = asList(Document.of("name", "Ada"), Document.of("type", "type"), Document.of("information", "ada@lovelace.com"));
    entity.add(Document.of("contacts", documents));
    Map<String, Object> result = entity.toMap();
    assertEquals("id", result.get("_id"));
    List<Map<String, Object>> contacts = (List<Map<String, Object>>) result.get("contacts");
    assertEquals(3, contacts.size());
    assertThat(contacts, containsInAnyOrder(singletonMap("name", "Ada"), singletonMap("type", "type"), singletonMap("information", "ada@lovelace.com")));
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Document(jakarta.nosql.document.Document) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Test(org.junit.jupiter.api.Test)

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