Search in sources :

Example 21 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity 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 22 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity 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 23 with DocumentEntity

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

Example 24 with DocumentEntity

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

the class DocumentEntityTest method shouldReturnErrorWhenAddAnNullIterable.

@Test
public void shouldReturnErrorWhenAddAnNullIterable() {
    Assertions.assertThrows(NullPointerException.class, () -> {
        DocumentEntity entity = new DefaultDocumentEntity("name");
        entity.addAll(null);
    });
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Test(org.junit.jupiter.api.Test)

Example 25 with DocumentEntity

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

Aggregations

DocumentEntity (jakarta.nosql.document.DocumentEntity)312 Test (org.junit.jupiter.api.Test)238 DocumentQuery (jakarta.nosql.document.DocumentQuery)131 Document (jakarta.nosql.document.Document)129 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)62 List (java.util.List)54 Arrays.asList (java.util.Arrays.asList)51 ArrayList (java.util.ArrayList)46 Duration (java.time.Duration)31 HashMap (java.util.HashMap)30 Map (java.util.Map)27 Collectors (java.util.stream.Collectors)27 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)25 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 ValueSource (org.junit.jupiter.params.provider.ValueSource)23 TypeReference (jakarta.nosql.TypeReference)21 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)21 Matchers.contains (org.hamcrest.Matchers.contains)21 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)21