Search in sources :

Example 26 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery 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 27 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery 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 28 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery 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)

Example 29 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.

the class ColumnRepositoryProxyTest method shouldFindByAgeLessEqual.

@Test
public void shouldFindByAgeLessEqual() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(singletonList(ada));
    personRepository.findByAgeLessThan(33);
    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(LESSER_THAN, condition.getCondition());
    assertEquals(Column.of("age", 33), 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 30 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.

the class DefaultColumnMapperSelectBuilderTest method shouldSelectOrderDesc.

@Test
public void shouldSelectOrderDesc() {
    ColumnQuery query = mapperBuilder.selectFrom(Worker.class).orderBy("salary").desc().build();
    ColumnQuery queryExpected = select().from("Worker").orderBy("money").desc().build();
    assertEquals(queryExpected, query);
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Worker(org.jnosql.artemis.model.Worker) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)117 Test (org.junit.jupiter.api.Test)113 Person (org.jnosql.artemis.model.Person)37 ColumnCondition (org.jnosql.diana.api.column.ColumnCondition)35 Column (org.jnosql.diana.api.column.Column)29 List (java.util.List)26 ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)26 Collections.singletonList (java.util.Collections.singletonList)20 ColumnDeleteQuery (org.jnosql.diana.api.column.ColumnDeleteQuery)19 Arrays.asList (java.util.Arrays.asList)15 Duration (java.time.Duration)14 ColumnQueryBuilder.delete (org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete)14 ColumnQueryBuilder.select (org.jnosql.diana.api.column.query.ColumnQueryBuilder.select)14 BeforeEach (org.junit.jupiter.api.BeforeEach)14 Optional (java.util.Optional)13 Consumer (java.util.function.Consumer)13 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)13 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)13 Inject (javax.inject.Inject)12 CDIExtension (org.jnosql.artemis.CDIExtension)12