Search in sources :

Example 11 with DocumentEntity

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

the class DocumentEntityTest method shouldReturnsTheDocumentValues.

@Test
public void shouldReturnsTheDocumentValues() {
    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);
    assertThat(collection.getValues(), containsInAnyOrder(Value.of(10), Value.of(11), Value.of(12), Value.of(13), Value.of(16)));
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 12 with DocumentEntity

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

the class DocumentEntityTest method shouldAddANewDocument.

@Test
public void shouldAddANewDocument() {
    DocumentEntity entity = new DefaultDocumentEntity("name");
    entity.add(Document.of("document", 12));
    assertFalse(entity.isEmpty());
    assertEquals(1, entity.size());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Test(org.junit.jupiter.api.Test)

Example 13 with DocumentEntity

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

the class DocumentEntityTest method shouldAddDocumentAsNameAndObject.

@Test
public void shouldAddDocumentAsNameAndObject() {
    DocumentEntity entity = new DefaultDocumentEntity("documentCollection");
    entity.add("name", 10);
    assertEquals(1, entity.size());
    Optional<Document> name = entity.find("name");
    assertTrue(name.isPresent());
    assertEquals(10, name.get().get());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 14 with DocumentEntity

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

the class DocumentEntityTest method shouldConvertToMap.

@Test
public void shouldConvertToMap() {
    Document document = Document.of("name", "name");
    DocumentEntity entity = DocumentEntity.of("entity", singletonList(document));
    Map<String, Object> result = entity.toMap();
    assertFalse(result.isEmpty());
    assertEquals(Integer.valueOf(1), Integer.valueOf(result.size()));
    assertEquals(document.getName(), result.keySet().stream().findAny().get());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 15 with DocumentEntity

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

the class DocumentEntityTest method shouldFindValue.

@Test
public void shouldFindValue() {
    Document document = Document.of("name", "name");
    DocumentEntity entity = DocumentEntity.of("entity", singletonList(document));
    Optional<String> name = entity.find("name", String.class);
    Assertions.assertNotNull(name);
    Assertions.assertTrue(name.isPresent());
    Assertions.assertEquals("name", name.orElse(""));
}
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