Search in sources :

Example 1 with DocumentEntity

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

the class ArangoDBDocumentCollectionManagerAsyncTest method shouldSelect.

@Test
public void shouldSelect() {
    DocumentEntity entity = getEntity();
    AtomicReference<DocumentEntity> reference = new AtomicReference<>();
    AtomicBoolean condition = new AtomicBoolean(false);
    entityManagerAsync.insert(entity, d -> {
        condition.set(true);
        reference.set(d);
    });
    await().untilTrue(condition);
    DocumentEntity entity1 = reference.get();
    Document key = entity1.find("_key").get();
    condition.set(false);
    AtomicReference<List<DocumentEntity>> references = new AtomicReference<>();
    entityManagerAsync.select(select().from(entity1.getName()).where("_key").eq(key.get()).build(), l -> {
        condition.set(true);
        references.set(l);
    });
    await().untilTrue(condition);
    List<DocumentEntity> entities = references.get();
    assertFalse(entities.isEmpty());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) AtomicReference(java.util.concurrent.atomic.AtomicReference) List(java.util.List) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 2 with DocumentEntity

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

the class ArangoDBDocumentCollectionManagerAsyncTest 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");
    entity.add(Document.of(KEY_NAME, random.nextLong()));
    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 3 with DocumentEntity

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

the class ArangoDBDocumentCollectionManagerAsyncTest method shouldInsertCallBack.

@Test
public void shouldInsertCallBack() {
    DocumentEntity entity = getEntity();
    AtomicBoolean condition = new AtomicBoolean();
    entityManagerAsync.insert(entity, d -> condition.set(true));
    await().untilTrue(condition);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Test(org.junit.jupiter.api.Test)

Example 4 with DocumentEntity

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

the class ArangoDBDocumentCollectionManagerTest method shouldFindDocument.

@Test
public void shouldFindDocument() {
    DocumentEntity entity = entityManager.insert(getEntity());
    Document id = entity.find(KEY_NAME).get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    List<DocumentEntity> entities = entityManager.select(query);
    assertFalse(entities.isEmpty());
    DocumentEntity documentEntity = entities.get(0);
    assertEquals(entity.find(KEY_NAME).get().getValue().get(String.class), documentEntity.find(KEY_NAME).get().getValue().get(String.class));
    assertEquals(entity.find("name").get(), documentEntity.find("name").get());
    assertEquals(entity.find("city").get(), documentEntity.find("city").get());
}
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 5 with DocumentEntity

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

the class ArangoDBDocumentCollectionManagerTest method shouldRetrieveListSubdocumentList.

@Test
public void shouldRetrieveListSubdocumentList() {
    DocumentEntity entity = entityManager.insert(createSubdocumentList());
    Document key = entity.find(KEY_NAME).get();
    DocumentQuery query = select().from("AppointmentBook").where(key.getName()).eq(key.get()).build();
    DocumentEntity documentEntity = entityManager.singleResult(query).get();
    assertNotNull(documentEntity);
    List<List<Document>> contacts = (List<List<Document>>) documentEntity.find("contacts").get().get();
    assertEquals(3, contacts.size());
    assertTrue(contacts.stream().allMatch(d -> d.size() == 3));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Document(org.jnosql.diana.api.document.Document) Arrays(java.util.Arrays) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) TypeReference(org.jnosql.diana.api.TypeReference) HashMap(java.util.HashMap) Random(java.util.Random) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) DocumentConfigurationUtils.getConfiguration(org.jnosql.diana.arangodb.document.DocumentConfigurationUtils.getConfiguration) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) Documents(org.jnosql.diana.api.document.Documents) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Arrays.asList(java.util.Arrays.asList) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Map(java.util.Map) Assertions(org.junit.jupiter.api.Assertions) Collections.singletonMap(java.util.Collections.singletonMap) DocumentQueryBuilder.delete(org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) ArrayList(java.util.ArrayList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Document(org.jnosql.diana.api.document.Document) 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