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);
});
}
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());
}
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());
}
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"));
}
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")));
}
Aggregations