Search in sources :

Example 86 with DocumentEntity

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

the class DefaultDocumentTemplateAsyncTest method shouldReturnErrorWhenThereIsMoreThanOneResultInSingleResult.

@Test
public void shouldReturnErrorWhenThereIsMoreThanOneResultInSingleResult() {
    assertThrows(NonUniqueResultException.class, () -> {
        ArgumentCaptor<Consumer<List<DocumentEntity>>> dianaCallbackCaptor = ArgumentCaptor.forClass(Consumer.class);
        DocumentQuery query = select().from("Person").build();
        Consumer<Optional<Person>> callback = l -> {
        };
        subject.singleResult(query, callback);
        verify(managerMock).select(Mockito.any(DocumentQuery.class), dianaCallbackCaptor.capture());
        Consumer<List<DocumentEntity>> dianaCallBack = dianaCallbackCaptor.getValue();
        dianaCallBack.accept(asList(DocumentEntity.of("Person", asList(documents)), DocumentEntity.of("Person", asList(documents))));
    });
}
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) Converters(org.jnosql.artemis.Converters) DocumentCollectionManagerAsync(org.jnosql.diana.api.document.DocumentCollectionManagerAsync) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collections.singletonList(java.util.Collections.singletonList) Person(org.jnosql.artemis.model.Person) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) DocumentQueryBuilder.delete(org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete) NonUniqueResultException(org.jnosql.diana.api.NonUniqueResultException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Instance(javax.enterprise.inject.Instance) Awaitility.await(org.awaitility.Awaitility.await) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) Collections.emptyList(java.util.Collections.emptyList) Mockito.when(org.mockito.Mockito.when) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Collectors(java.util.stream.Collectors) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Optional(java.util.Optional) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Consumer(java.util.function.Consumer) Optional(java.util.Optional) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 87 with DocumentEntity

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

the class DefaultDocumentTemplateAsyncTest method shouldFindByIdReturnEmptyWhenElementDoesNotFind.

@Test
public void shouldFindByIdReturnEmptyWhenElementDoesNotFind() {
    ArgumentCaptor<Consumer<List<DocumentEntity>>> dianaCallbackCaptor = ArgumentCaptor.forClass(Consumer.class);
    ArgumentCaptor<DocumentQuery> queryCaptor = ArgumentCaptor.forClass(DocumentQuery.class);
    AtomicBoolean condition = new AtomicBoolean(false);
    AtomicReference<Person> atomicReference = new AtomicReference<>();
    Consumer<Optional<Person>> callback = p -> {
        condition.set(true);
        p.ifPresent(atomicReference::set);
    };
    subject.find(Person.class, 10L, callback);
    verify(managerMock).select(queryCaptor.capture(), dianaCallbackCaptor.capture());
    Consumer<List<DocumentEntity>> dianaCallBack = dianaCallbackCaptor.getValue();
    dianaCallBack.accept(emptyList());
    DocumentQuery query = queryCaptor.getValue();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(DocumentCondition.eq(Document.of("_id", 10L)), query.getCondition().get());
    assertNull(atomicReference.get());
}
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) Converters(org.jnosql.artemis.Converters) DocumentCollectionManagerAsync(org.jnosql.diana.api.document.DocumentCollectionManagerAsync) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collections.singletonList(java.util.Collections.singletonList) Person(org.jnosql.artemis.model.Person) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) DocumentQueryBuilder.delete(org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete) NonUniqueResultException(org.jnosql.diana.api.NonUniqueResultException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Instance(javax.enterprise.inject.Instance) Awaitility.await(org.awaitility.Awaitility.await) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) Collections.emptyList(java.util.Collections.emptyList) Mockito.when(org.mockito.Mockito.when) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Collectors(java.util.stream.Collectors) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Optional(java.util.Optional) Optional(java.util.Optional) AtomicReference(java.util.concurrent.atomic.AtomicReference) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Consumer(java.util.function.Consumer) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 88 with DocumentEntity

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

the class DefaultDocumentTemplateAsyncTest method shouldReturnErrorFindByIdReturnMoreThanOne.

@Test
public void shouldReturnErrorFindByIdReturnMoreThanOne() {
    assertThrows(NonUniqueResultException.class, () -> {
        ArgumentCaptor<Consumer<List<DocumentEntity>>> dianaCallbackCaptor = ArgumentCaptor.forClass(Consumer.class);
        ArgumentCaptor<DocumentQuery> queryCaptor = ArgumentCaptor.forClass(DocumentQuery.class);
        AtomicBoolean condition = new AtomicBoolean(false);
        AtomicReference<Person> atomicReference = new AtomicReference<>();
        Consumer<Optional<Person>> callback = p -> {
            condition.set(true);
            p.ifPresent(atomicReference::set);
        };
        subject.find(Person.class, 10L, callback);
        verify(managerMock).select(queryCaptor.capture(), dianaCallbackCaptor.capture());
        Consumer<List<DocumentEntity>> dianaCallBack = dianaCallbackCaptor.getValue();
        dianaCallBack.accept(asList(DocumentEntity.of("Person", asList(documents)), DocumentEntity.of("Person", asList(documents))));
    });
}
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) Converters(org.jnosql.artemis.Converters) DocumentCollectionManagerAsync(org.jnosql.diana.api.document.DocumentCollectionManagerAsync) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collections.singletonList(java.util.Collections.singletonList) Person(org.jnosql.artemis.model.Person) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) DocumentQueryBuilder.delete(org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete) NonUniqueResultException(org.jnosql.diana.api.NonUniqueResultException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Instance(javax.enterprise.inject.Instance) Awaitility.await(org.awaitility.Awaitility.await) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) Collections.emptyList(java.util.Collections.emptyList) Mockito.when(org.mockito.Mockito.when) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Collectors(java.util.stream.Collectors) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Optional(java.util.Optional) Optional(java.util.Optional) AtomicReference(java.util.concurrent.atomic.AtomicReference) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Consumer(java.util.function.Consumer) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 89 with DocumentEntity

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

the class DefaultDocumentTemplateTest method shouldSave.

@Test
public void shouldSave() {
    DocumentEntity document = DocumentEntity.of("Person");
    document.addAll(Stream.of(documents).collect(Collectors.toList()));
    when(managerMock.insert(any(DocumentEntity.class))).thenReturn(document);
    subject.insert(this.person);
    verify(managerMock).insert(captor.capture());
    verify(documentEventPersistManager).firePostEntity(any(Person.class));
    verify(documentEventPersistManager).firePreEntity(any(Person.class));
    verify(documentEventPersistManager).firePreDocument(any(DocumentEntity.class));
    verify(documentEventPersistManager).firePostDocument(any(DocumentEntity.class));
    DocumentEntity value = captor.getValue();
    assertEquals("Person", value.getName());
    assertEquals(4, value.getDocuments().size());
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 90 with DocumentEntity

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

the class DefaultDocumentTemplateTest method shouldInsertEntities.

@Test
public void shouldInsertEntities() {
    DocumentEntity documentEntity = DocumentEntity.of("Person");
    documentEntity.addAll(Stream.of(documents).collect(Collectors.toList()));
    Mockito.when(managerMock.insert(any(DocumentEntity.class))).thenReturn(documentEntity);
    subject.insert(Arrays.asList(person, person));
    verify(managerMock, times(2)).insert(any(DocumentEntity.class));
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) 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