use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerAsyncTest method shouldSelect.
@Test
public void shouldSelect() {
DocumentEntity entity = getEntity();
AtomicReference<DocumentEntity> reference = new AtomicReference<>();
AtomicBoolean condition = new AtomicBoolean(false);
entityManagerAsync.insert(entity, d -> {
condition.set(true);
reference.set(d);
});
await().untilTrue(condition);
DocumentEntity entity1 = reference.get();
Document key = entity1.find("_key").get();
condition.set(false);
AtomicReference<List<DocumentEntity>> references = new AtomicReference<>();
entityManagerAsync.select(select().from(entity1.getName()).where("_key").eq(key.get()).build(), l -> {
condition.set(true);
references.set(l);
});
await().untilTrue(condition);
List<DocumentEntity> entities = references.get();
assertFalse(entities.isEmpty());
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerAsyncTest 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.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerAsyncTest method shouldInsertCallBack.
@Test
public void shouldInsertCallBack() {
DocumentEntity entity = getEntity();
AtomicBoolean condition = new AtomicBoolean();
entityManagerAsync.insert(entity, d -> condition.set(true));
await().untilTrue(condition);
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerTest method shouldFindDocument.
@Test
public void shouldFindDocument() {
DocumentEntity entity = entityManager.insert(getEntity());
Document id = entity.find(KEY_NAME).get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
List<DocumentEntity> entities = entityManager.select(query);
assertFalse(entities.isEmpty());
DocumentEntity documentEntity = entities.get(0);
assertEquals(entity.find(KEY_NAME).get().getValue().get(String.class), documentEntity.find(KEY_NAME).get().getValue().get(String.class));
assertEquals(entity.find("name").get(), documentEntity.find("name").get());
assertEquals(entity.find("city").get(), documentEntity.find("city").get());
}
use of org.jnosql.diana.api.document.DocumentEntity 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));
}
Aggregations