Search in sources :

Example 41 with DocumentEntity

use of org.jnosql.diana.api.document.DocumentEntity 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;
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) HashMap(java.util.HashMap) Document(org.jnosql.diana.api.document.Document)

Example 42 with DocumentEntity

use of org.jnosql.diana.api.document.DocumentEntity 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());
}
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)

Example 43 with DocumentEntity

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

Example 44 with DocumentEntity

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

Example 45 with DocumentEntity

use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.

the class OrientDBDocumentCollectionManagerAsyncTest method shouldFindAsync.

@Test
public void shouldFindAsync() {
    DocumentEntity entity = entityManager.insert(getEntity());
    AtomicReference<List<DocumentEntity>> reference = new AtomicReference<>();
    DocumentQuery query = select().from(COLLECTION_NAME).build();
    entityManagerAsync.select(query, reference::set);
    await().until(reference::get, notNullValue(List.class));
    assertFalse(reference.get().isEmpty());
    assertEquals(reference.get().get(0), entity);
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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