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