Search in sources :

Example 86 with Person

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

the class DocumentRepositoryExtensionTest method shouldUseMock.

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

Example 87 with Person

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

the class DocumentRepositoryProxyTest method shouldSaveIterable.

@Test
public void shouldSaveIterable() {
    when(personRepository.findById(10L)).thenReturn(Optional.empty());
    when(template.singleResult(Mockito.any(DocumentQuery.class))).thenReturn(Optional.empty());
    ArgumentCaptor<Person> captor = ArgumentCaptor.forClass(Person.class);
    Person person = Person.builder().withName("Ada").withId(10L).withPhones(singletonList("123123")).build();
    personRepository.save(singletonList(person));
    verify(template).insert(captor.capture());
    verify(template).insert(captor.capture());
    Person personCapture = captor.getValue();
    assertEquals(person, personCapture);
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 88 with Person

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

the class DocumentRepositoryProxyTest method shouldFindByNameANDAge.

@Test
public void shouldFindByNameANDAge() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(Mockito.any(DocumentQuery.class))).thenReturn(singletonList(ada));
    List<Person> persons = personRepository.findByNameAndAge("name", 20);
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    assertThat(persons, Matchers.contains(ada));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 89 with Person

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

the class DocumentRepositoryProxyTest method shouldFindByGreaterThan.

@Test
public void shouldFindByGreaterThan() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(DocumentQuery.class))).thenReturn(singletonList(ada));
    personRepository.findByAgeGreaterThan(33);
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(GREATER_THAN, condition.getCondition());
    assertEquals(Document.of("age", 33), condition.getDocument());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Person(org.jnosql.artemis.model.Person) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 90 with Person

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

the class DocumentRepositoryProxyTest method shouldFindByNameANDAgeOrderByAge.

@Test
public void shouldFindByNameANDAgeOrderByAge() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(Mockito.any(DocumentQuery.class))).thenReturn(singletonList(ada));
    Queue<Person> persons = personRepository.findByNameAndAgeOrderByAge("name", 20);
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    assertThat(persons, Matchers.contains(ada));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) 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