use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerTest method shouldRetrieveListSubdocumentList.
@Test
public void shouldRetrieveListSubdocumentList() {
DocumentEntity entity = entityManager.insert(createSubdocumentList());
Document key = entity.find(KEY_NAME).get();
DocumentQuery query = select().from("AppointmentBook").where(key.getName()).eq(key.get()).build();
DocumentEntity documentEntity = entityManager.singleResult(query).get();
assertNotNull(documentEntity);
List<List<Document>> contacts = (List<List<Document>>) documentEntity.find("contacts").get().get();
assertEquals(3, contacts.size());
assertTrue(contacts.stream().allMatch(d -> d.size() == 3));
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerTest method getEntity.
private DocumentEntity getEntity() {
DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
Map<String, Object> map = new HashMap<>();
map.put("name", "Poliana");
map.put("city", "Salvador");
entity.add(Document.of(KEY_NAME, random.nextLong()));
List<Document> documents = Documents.of(map);
documents.forEach(entity::add);
return entity;
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerTest method shouldRemoveEntity2.
@Test
public void shouldRemoveEntity2() {
DocumentEntity documentEntity = entityManager.insert(getEntity());
Document id = documentEntity.find("name").get();
DocumentQuery select = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
entityManager.delete(deleteQuery);
assertTrue(entityManager.select(select).isEmpty());
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerTest method shouldUpdateSave.
@Test
public void shouldUpdateSave() {
DocumentEntity entity = getEntity();
DocumentEntity documentEntity = entityManager.insert(entity);
Document newField = Documents.of("newField", "10");
entity.add(newField);
DocumentEntity updated = entityManager.update(entity);
assertEquals(newField, updated.find("newField").get());
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerTest method shouldRemoveEntity.
@Test
public void shouldRemoveEntity() {
DocumentEntity documentEntity = entityManager.insert(getEntity());
Document id = documentEntity.find("_key").get();
DocumentQuery select = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
entityManager.delete(deleteQuery);
assertTrue(entityManager.select(select).isEmpty());
}
Aggregations