use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerAsyncTest 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");
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 OrientDBDocumentCollectionManagerAsyncTest method shouldRemoveEntityAsyncWithoutCallback.
@Test
public void shouldRemoveEntityAsyncWithoutCallback() throws InterruptedException {
DocumentEntity entity = entityManager.insert(getEntity());
Document id = entity.find(OrientDBConverter.RID_FIELD).get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
entityManagerAsync.delete(deleteQuery);
Thread.sleep(1000L);
assertTrue(entityManager.select(query).isEmpty());
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerAsyncTest method shouldSaveAsync.
@Test
public void shouldSaveAsync() throws InterruptedException {
AtomicReference<DocumentEntity> entityAtomic = new AtomicReference<>();
entityManagerAsync.insert(getEntity(), entityAtomic::set);
await().until(entityAtomic::get, notNullValue(DocumentEntity.class));
DocumentEntity entity = entityAtomic.get();
Document id = entity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
List<DocumentEntity> entities = entityManager.select(query);
assertFalse(entities.isEmpty());
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerAsyncTest method shouldUpdateAsync.
@Test
public void shouldUpdateAsync() {
DocumentEntity entity = getEntity();
entityManager.insert(entity);
Document newField = Documents.of("newField", "10");
entity.add(newField);
entityManagerAsync.update(entity);
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerAsyncTest method shouldUpdateAsyncWithCallback.
@Test
public void shouldUpdateAsyncWithCallback() {
final String NEW_FIELD_NAME = "newField2";
final String NEW_FIELD_VALUE = "55";
DocumentEntity entity = entityManager.insert(getEntity());
Document newField = Documents.of(NEW_FIELD_NAME, NEW_FIELD_VALUE);
entity.add(newField);
AtomicBoolean condition = new AtomicBoolean(false);
entityManagerAsync.update(entity, c -> condition.set(true));
await().untilTrue(condition);
Optional<Document> idDocument = entity.find(OrientDBConverter.RID_FIELD);
DocumentQuery query = select().from(entity.getName()).where(idDocument.get().getName()).eq(idDocument.get().get()).build();
Optional<DocumentEntity> entityUpdated = entityManager.singleResult(query);
assertTrue(entityUpdated.isPresent());
assertEquals(entityUpdated.get().find(NEW_FIELD_NAME).get(), newField);
}
Aggregations