Search in sources :

Example 46 with Person

use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.

the class DocumentRepositoryAsyncProxyTest method shouldDeleteByNameCallBack.

@Test
public void shouldDeleteByNameCallBack() {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    Consumer<Void> voidConsumer = v -> {
    };
    personRepository.deleteByName("name", voidConsumer);
    verify(template).delete(captor.capture(), consumerCaptor.capture());
    DocumentDeleteQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals(Document.of("name", "name"), condition.getDocument());
    assertEquals(voidConsumer, consumerCaptor.getValue());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Document(org.jnosql.diana.api.document.Document) Converters(org.jnosql.artemis.Converters) Proxy(java.lang.reflect.Proxy) Matchers(org.mockito.Matchers) RepositoryAsync(org.jnosql.artemis.RepositoryAsync) Pagination(org.jnosql.artemis.Pagination) DynamicQueryException(org.jnosql.artemis.DynamicQueryException) Collections.singletonList(java.util.Collections.singletonList) Person(org.jnosql.artemis.model.Person) Reflections(org.jnosql.artemis.reflection.Reflections) Condition(org.jnosql.diana.api.Condition) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Duration(java.time.Duration) DocumentTemplateAsync(org.jnosql.artemis.document.DocumentTemplateAsync) DocumentQueryBuilder.delete(org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) Sort(org.jnosql.diana.api.Sort) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) 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) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) List(java.util.List) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) Consumer(java.util.function.Consumer) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 47 with Person

use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.

the class DocumentRepositoryAsyncProxyTest method shouldSaveUsingInsertWhenThereIsNotData.

@Test
public void shouldSaveUsingInsertWhenThereIsNotData() {
    ArgumentCaptor<Person> captor = ArgumentCaptor.forClass(Person.class);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    Person person = Person.builder().withName("Ada").withId(10L).withPhones(singletonList("123123")).build();
    personRepository.save(person);
    verify(template).find(Mockito.eq(Person.class), Mockito.eq(10L), consumerCaptor.capture());
    Consumer consumer = consumerCaptor.getValue();
    consumer.accept(Optional.empty());
    verify(template).insert(captor.capture());
    Person value = captor.getValue();
    assertEquals(person, value);
}
Also used : Consumer(java.util.function.Consumer) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 48 with Person

use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.

the class DocumentRepositoryAsyncProxyTest method shouldSaveUsingUpdateWhenThereIsData.

@Test
public void shouldSaveUsingUpdateWhenThereIsData() {
    ArgumentCaptor<Person> captor = ArgumentCaptor.forClass(Person.class);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    Person person = Person.builder().withName("Ada").withId(10L).withPhones(singletonList("123123")).build();
    personRepository.save(person);
    verify(template).find(Mockito.eq(Person.class), Mockito.eq(10L), consumerCaptor.capture());
    Consumer consumer = consumerCaptor.getValue();
    consumer.accept(Optional.of(Person.builder().build()));
    verify(template).update(captor.capture());
    Person value = captor.getValue();
    assertEquals(person, value);
}
Also used : Consumer(java.util.function.Consumer) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 49 with Person

use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.

the class DocumentRepositoryExtensionTest method shouldInitiate.

@Test
public void shouldInitiate() {
    assertNotNull(repository);
    Person person = repository.save(Person.builder().build());
    assertEquals("Default", person.getName());
}
Also used : Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 50 with Person

use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.

the class BucketManagerProducerExtensionTest method shouldUseMock.

@Test
public void shouldUseMock() {
    Person person = repository.get("key", Person.class).get();
    Person personMock = repositoryMock.get("key", Person.class).get();
    assertEquals("Default", person.getName());
    assertEquals("keyvalueMock", personMock.getName());
}
Also used : Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Aggregations

Person (org.jnosql.artemis.model.Person)126 Test (org.junit.jupiter.api.Test)124 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)40 ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)39 Consumer (java.util.function.Consumer)32 Duration (java.time.Duration)30 Collections.singletonList (java.util.Collections.singletonList)30 List (java.util.List)30 Optional (java.util.Optional)28 Inject (javax.inject.Inject)28 CDIExtension (org.jnosql.artemis.CDIExtension)28 Converters (org.jnosql.artemis.Converters)28 ClassRepresentations (org.jnosql.artemis.reflection.ClassRepresentations)28 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)28 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)28 BeforeEach (org.junit.jupiter.api.BeforeEach)28 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)28 ArgumentCaptor (org.mockito.ArgumentCaptor)28 Mockito (org.mockito.Mockito)28 Mockito.verify (org.mockito.Mockito.verify)28