Search in sources :

Example 21 with Document

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

the class DocumentEntityTest method shouldRemoveAllElementsWhenUseClearMethod.

@Test
public void shouldRemoveAllElementsWhenUseClearMethod() {
    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);
    assertFalse(collection.isEmpty());
    collection.clear();
    assertTrue(collection.isEmpty());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 22 with Document

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

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

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

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

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