Search in sources :

Example 76 with DocumentQuery

use of org.jnosql.diana.api.document.DocumentQuery 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 77 with DocumentQuery

use of org.jnosql.diana.api.document.DocumentQuery 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 78 with DocumentQuery

use of org.jnosql.diana.api.document.DocumentQuery 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 79 with DocumentQuery

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

the class DefaultDocumentTemplateTest method shouldReturnFind.

@Test
public void shouldReturnFind() {
    subject.find(Person.class, "10");
    ArgumentCaptor<DocumentQuery> queryCaptor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(managerMock).select(queryCaptor.capture());
    DocumentQuery query = queryCaptor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(DocumentCondition.eq(Document.of("_id", 10L)), condition);
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 80 with DocumentQuery

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

the class DefaultDocumentTemplateTest method shouldReturnSingleResultIsEmpty.

@Test
public void shouldReturnSingleResultIsEmpty() {
    Mockito.when(managerMock.select(any(DocumentQuery.class))).thenReturn(emptyList());
    DocumentQuery query = select().from("person").build();
    Optional<Person> result = subject.singleResult(query);
    assertFalse(result.isPresent());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)201 Test (org.junit.jupiter.api.Test)186 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)95 Document (org.jnosql.diana.api.document.Document)84 List (java.util.List)50 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)46 Person (org.jnosql.artemis.model.Person)37 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)35 Arrays.asList (java.util.Arrays.asList)27 ArrayList (java.util.ArrayList)21 Duration (java.time.Duration)20 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)20 Optional (java.util.Optional)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)18 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)18 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)17 DocumentQueryBuilder.delete (org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete)17 BeforeEach (org.junit.jupiter.api.BeforeEach)17 Consumer (java.util.function.Consumer)16 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)16