Search in sources :

Example 96 with Document

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

the class ElasticsearchDocumentCollectionManagerTest method shouldRetrieveListSubdocumentList.

@Test
public void shouldRetrieveListSubdocumentList() {
    DocumentEntity entity = entityManager.insert(createSubdocumentList());
    Document key = entity.find("_id").get();
    DocumentQuery query = select().from(COLLECTION_NAME).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 : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Document(org.jnosql.diana.api.document.Document) Arrays(java.util.Arrays) TypeReference(org.jnosql.diana.api.TypeReference) ArrayList(java.util.ArrayList) DocumentEntityGerator.getEntity(org.jnosql.diana.elasticsearch.document.DocumentEntityGerator.getEntity) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) DocumentQueryBuilder.delete(org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) INDEX(org.jnosql.diana.elasticsearch.document.DocumentEntityGerator.INDEX) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) QueryBuilders.termQuery(org.elasticsearch.index.query.QueryBuilders.termQuery) Documents(org.jnosql.diana.api.document.Documents) COLLECTION_NAME(org.jnosql.diana.elasticsearch.document.DocumentEntityGerator.COLLECTION_NAME) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 97 with Document

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

the class ElasticsearchDocumentCollectionManagerTest method shouldRemoveEntityById.

@Test
public void shouldRemoveEntityById() {
    DocumentEntity documentEntity = entityManager.insert(getEntity());
    Document id = documentEntity.find("_id").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();
    entityManager.delete(deleteQuery);
    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 98 with Document

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

the class ElasticsearchDocumentCollectionManagerTest method shouldFindDocumentById.

@Test
public void shouldFindDocumentById() {
    DocumentEntity entity = entityManager.insert(getEntity());
    Document id = entity.find("_id").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    List<DocumentEntity> entities = entityManager.select(query);
    assertFalse(entities.isEmpty());
    assertThat(entities, contains(entity));
}
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 99 with Document

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

the class ElasticsearchDocumentCollectionManagerTest method shouldRemoveEntityByName.

@Test
public void shouldRemoveEntityByName() throws InterruptedException {
    DocumentEntity documentEntity = entityManager.insert(getEntity());
    Document name = documentEntity.find("name").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
    TimeUnit.SECONDS.sleep(1L);
    entityManager.delete(deleteQuery);
    TimeUnit.SECONDS.sleep(1L);
    List<DocumentEntity> entities = entityManager.select(query);
    System.out.println(entities);
    assertTrue(entities.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 100 with Document

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

the class ElasticsearchDocumentCollectionManagerTest method shouldSaveSubDocument2.

@Test
public void shouldSaveSubDocument2() {
    DocumentEntity entity = getEntity();
    entity.add(Document.of("phones", Arrays.asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
    DocumentEntity entitySaved = entityManager.insert(entity);
    Document id = entitySaved.find("_id").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    DocumentEntity entityFound = entityManager.select(query).get(0);
    Document subDocument = entityFound.find("phones").get();
    List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
    });
    assertThat(documents, containsInAnyOrder(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231")));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) 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