use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerAsyncTest method shouldInserAsyncTTL.
@Test
public void shouldInserAsyncTTL() throws InterruptedException {
DocumentEntity entity = getEntity();
entityManagerAsync.insert(entity, Duration.ofSeconds(1L));
TimeUnit.SECONDS.sleep(2L);
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);
assertTrue(entities.isEmpty());
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerAsyncTest 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");
map.put("_id", "id");
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 CouchbaseDocumentCollectionManagerAsyncTest method shouldRemoveEntityAsyncCallBack.
@Test
public void shouldRemoveEntityAsyncCallBack() {
AtomicBoolean condition = new AtomicBoolean(false);
AtomicReference<List<DocumentEntity>> references = new AtomicReference<>();
DocumentEntity documentEntity = entityManager.insert(getEntity());
Document id = documentEntity.find("name").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, d -> {
condition.set(true);
});
await().untilTrue(condition);
entityManagerAsync.select(query, references::set);
await().until(() -> references.get(), notNullValue());
assertFalse(references.get().isEmpty());
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerAsyncTest method shouldRunN1Ql.
@Test
public void shouldRunN1Ql() {
DocumentEntity entity = getEntity();
entityManager.insert(entity);
AtomicReference<List<DocumentEntity>> references = new AtomicReference<>();
entityManagerAsync.n1qlQuery("select * from jnosql", references::set);
await().until(references::get, notNullValue());
assertFalse(references.get().isEmpty());
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldRemoveEntityByName.
@Test
public void shouldRemoveEntityByName() {
DocumentEntity documentEntity = entityManager.insert(getEntity());
Document name = documentEntity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
DocumentDeleteQuery deleteQuery = DocumentQueryBuilder.delete().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
entityManager.delete(deleteQuery);
assertTrue(entityManager.select(query).isEmpty());
}
Aggregations