Search in sources :

Example 46 with Document

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

Example 47 with Document

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());
}
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 48 with Document

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());
}
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 49 with Document

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

Example 50 with Document

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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)

Aggregations

Document (org.jnosql.diana.api.document.Document)126 Test (org.junit.jupiter.api.Test)102 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)94 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)71 List (java.util.List)41 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)37 ArrayList (java.util.ArrayList)25 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)25 Arrays.asList (java.util.Arrays.asList)23 HashMap (java.util.HashMap)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 Map (java.util.Map)11 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)11 TypeReference (org.jnosql.diana.api.TypeReference)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 Matchers.contains (org.hamcrest.Matchers.contains)10 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)10 Arrays (java.util.Arrays)8 Optional (java.util.Optional)8 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)8