Search in sources :

Example 16 with DocumentEntity

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());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 17 with DocumentEntity

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;
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) HashMap(java.util.HashMap) JsonObject(com.couchbase.client.java.document.json.JsonObject) Document(org.jnosql.diana.api.document.Document)

Example 18 with DocumentEntity

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Document(org.jnosql.diana.api.document.Document) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 19 with DocumentEntity

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());
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 20 with DocumentEntity

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());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)205 Test (org.junit.jupiter.api.Test)167 Document (org.jnosql.diana.api.document.Document)107 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)101 List (java.util.List)63 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)47 Arrays.asList (java.util.Arrays.asList)38 ArrayList (java.util.ArrayList)36 AtomicReference (java.util.concurrent.atomic.AtomicReference)29 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)25 Duration (java.time.Duration)22 HashMap (java.util.HashMap)21 Consumer (java.util.function.Consumer)19 Arrays (java.util.Arrays)17 Collectors (java.util.stream.Collectors)17 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)17 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 Map (java.util.Map)15 Optional (java.util.Optional)15 BeforeEach (org.junit.jupiter.api.BeforeEach)15