Search in sources :

Example 31 with DocumentEntity

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

the class DocumentQueryTest method shouldSelectAll.

@Test
public void shouldSelectAll() {
    DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id"), Document.of("name", "name")));
    DocumentQuery query = select().from(COLLECTION_NAME).build();
    Optional<Document> name = entity.find("name");
    List<DocumentEntity> entities = entityManager.select(query);
    assertFalse(entities.isEmpty());
    assertTrue(entities.size() >= 4);
}
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 32 with DocumentEntity

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

the class SearchQueryTest method shouldSearchElement3.

@Test
public void shouldSearchElement3() {
    MatchQuery match = SearchQuery.match("Salvador").field("name");
    SearchQuery query = new SearchQuery("index-diana", match);
    List<DocumentEntity> entities = entityManager.search(query);
    assertEquals(1, entities.size());
    List<String> result = entities.stream().flatMap(e -> e.getDocuments().stream()).filter(d -> "name".equals(d.getName())).map(d -> d.get(String.class)).collect(Collectors.toList());
    assertThat(result, containsInAnyOrder("Salvador"));
}
Also used : SearchQuery(com.couchbase.client.java.search.SearchQuery) Document(org.jnosql.diana.api.document.Document) Arrays(java.util.Arrays) CouchbaseKeyValueConfiguration(org.jnosql.diana.couchbase.key.CouchbaseKeyValueConfiguration) MatchQuery(com.couchbase.client.java.search.queries.MatchQuery) Collectors(java.util.stream.Collectors) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) List(java.util.List) BeforeAll(org.junit.jupiter.api.BeforeAll) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Arrays.asList(java.util.Arrays.asList) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) BucketManager(org.jnosql.diana.api.key.BucketManager) CouchbaseUtil(org.jnosql.diana.couchbase.CouchbaseUtil) BucketManagerFactory(org.jnosql.diana.api.key.BucketManagerFactory) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SearchQuery(com.couchbase.client.java.search.SearchQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) MatchQuery(com.couchbase.client.java.search.queries.MatchQuery) Test(org.junit.jupiter.api.Test)

Example 33 with DocumentEntity

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

the class DocumentEntityGerator method getEntity.

static 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) Document(org.jnosql.diana.api.document.Document)

Example 34 with DocumentEntity

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

the class ElasticsearchDocumentCollectionManagerAsyncTest method shouldReturnAll.

@Test
public void shouldReturnAll() {
    DocumentEntity entity = getEntity();
    entityManagerAsync.insert(entity);
    DocumentQuery query = select().from(COLLECTION_NAME).build();
    AtomicBoolean condition = new AtomicBoolean(false);
    AtomicReference<List<DocumentEntity>> result = new AtomicReference<>();
    entityManagerAsync.select(query, l -> {
        condition.set(true);
        result.set(l);
    });
    Awaitility.await().untilTrue(condition);
    List<DocumentEntity> entities = result.get();
    assertFalse(entities.isEmpty());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 35 with DocumentEntity

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

the class ElasticsearchDocumentCollectionManagerTest method createSubdocumentList.

private DocumentEntity createSubdocumentList() {
    DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
    entity.add(Document.of("_id", "ids"));
    List<List<Document>> documents = new ArrayList<>();
    documents.add(asList(Document.of("name", "Ada"), Document.of("type", ContactType.EMAIL), Document.of("information", "ada@lovelace.com")));
    documents.add(asList(Document.of("name", "Ada"), Document.of("type", ContactType.MOBILE), Document.of("information", "11 1231231 123")));
    documents.add(asList(Document.of("name", "Ada"), Document.of("type", ContactType.PHONE), Document.of("information", "phone")));
    entity.add(Document.of("contacts", documents));
    return entity;
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List)

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