Search in sources :

Example 16 with Person

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

the class ColumnRepositoryProxyTest method shouldSaveUsingUpdateWhenDataExists.

@Test
public void shouldSaveUsingUpdateWhenDataExists() {
    when(template.find(Person.class, 10L)).thenReturn(Optional.of(Person.builder().build()));
    ArgumentCaptor<Person> captor = ArgumentCaptor.forClass(Person.class);
    Person person = Person.builder().withName("Ada").withId(10L).withPhones(singletonList("123123")).build();
    assertNotNull(personRepository.save(person));
    verify(template).update(captor.capture());
    Person value = captor.getValue();
    assertEquals(person, value);
}
Also used : Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 17 with Person

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

the class ColumnRepositoryProxyTest method shouldFindByNameANDAge.

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

Example 18 with Person

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

the class ColumnRepositoryProxyTest method shouldFindByNameLike.

@Test
public void shouldFindByNameLike() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(singletonList(ada));
    personRepository.findByNameLike("Ada");
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    ColumnQuery query = captor.getValue();
    ColumnCondition condition = query.getCondition().get();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(LIKE, condition.getCondition());
    assertEquals(Column.of("name", "Ada"), condition.getColumn());
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Person(org.jnosql.artemis.model.Person) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 19 with Person

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

the class ColumnRepositoryProxyTest method shouldExecuteQuery.

@Test
public void shouldExecuteQuery() {
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional.of(ada));
    ColumnQuery query = select().from("Person").where("name").eq("Ada").build();
    Person person = personRepository.query(query);
    verify(template).singleResult(captor.capture());
    assertEquals(ada, person);
    assertEquals(query, captor.getValue());
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 20 with Person

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

the class ColumnRepositoryProxyTest method shouldFindByAgeANDName.

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