Search in sources :

Example 71 with DocumentEntity

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

the class MongoDBDocumentCollectionManagerAsyncTest method shouldUpdateIterableAsync.

@Test
public void shouldUpdateIterableAsync() throws InterruptedException {
    Random random = new Random();
    long id = random.nextLong();
    AtomicBoolean condition = new AtomicBoolean(false);
    AtomicReference<DocumentEntity> reference = new AtomicReference<>();
    DocumentEntity entity = getEntity();
    entity.add("_id", id);
    entityManager.insert(entity, c -> {
        condition.set(true);
        reference.set(c);
    });
    await().untilTrue(condition);
    entityManager.update(Collections.singletonList(entity));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Random(java.util.Random) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 72 with DocumentEntity

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

the class MongoDBDocumentCollectionManagerAsyncTest method shouldRemoveEntity.

@Test
public void shouldRemoveEntity() {
    AtomicReference<DocumentEntity> entityAtomic = new AtomicReference<>();
    entityManager.insert(getEntity(), entityAtomic::set);
    await().until(entityAtomic::get, notNullValue(DocumentEntity.class));
    DocumentEntity entity = entityAtomic.get();
    Document document = entity.find("name").get();
    DocumentDeleteQuery deleteQuery = delete().from(entity.getName()).where(document.getName()).eq(document.get()).build();
    entityManager.delete(deleteQuery);
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) 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 73 with DocumentEntity

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

the class MongoDBDocumentCollectionManagerAsyncTest method shouldUpdateAsync.

@Test
public void shouldUpdateAsync() throws InterruptedException {
    Random random = new Random();
    long id = random.nextLong();
    AtomicBoolean condition = new AtomicBoolean(false);
    AtomicReference<DocumentEntity> reference = new AtomicReference<>();
    DocumentEntity entity = getEntity();
    entity.add("_id", id);
    entityManager.insert(entity, c -> {
        condition.set(true);
        reference.set(c);
    });
    await().untilTrue(condition);
    entityManager.update(reference.get(), c -> condition.set(true));
    assertTrue(condition.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Random(java.util.Random) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 74 with DocumentEntity

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

the class MongoDBDocumentCollectionManagerAsyncTest method shouldInsertAsync.

@Test
public void shouldInsertAsync() throws InterruptedException {
    AtomicBoolean condition = new AtomicBoolean(false);
    DocumentEntity entity = getEntity();
    entityManager.insert(entity, c -> condition.set(true));
    await().untilTrue(condition);
    assertTrue(condition.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Test(org.junit.jupiter.api.Test)

Example 75 with DocumentEntity

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

the class MongoDBDocumentCollectionManagerAsyncTest 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)

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