use of jakarta.nosql.column.ColumnQuery in project jnosql-diana by eclipse.
the class ColumnPageTest method shouldExecutePaginationAsQuery.
@Test
public void shouldExecutePaginationAsQuery() {
Pagination pagination = Pagination.page(1).size(1);
ColumnQueryPagination queryPagination = ColumnQueryPagination.of(select().from("person").build(), pagination);
ColumnQuery query = queryPagination;
List<Person> people = subject.<Person>select(query).collect(Collectors.toList());
assertEquals(0L, people.stream().map(Person::getId).findFirst().orElse(-0L));
queryPagination = queryPagination.next();
query = queryPagination;
people = subject.<Person>select(query).collect(Collectors.toList());
assertEquals(1L, people.stream().map(Person::getId).findFirst().orElse(-0L));
queryPagination = queryPagination.next();
query = queryPagination;
people = subject.<Person>select(query).collect(Collectors.toList());
assertEquals(2L, people.stream().map(Person::getId).findFirst().orElse(-0L));
queryPagination = queryPagination.next();
query = queryPagination;
people = subject.<Person>select(query).collect(Collectors.toList());
assertEquals(3L, people.stream().map(Person::getId).findFirst().orElse(-0L));
queryPagination = queryPagination.next();
query = queryPagination;
people = subject.<Person>select(query).collect(Collectors.toList());
assertEquals(4L, people.stream().map(Person::getId).findFirst().orElse(-0L));
queryPagination = queryPagination.next();
query = queryPagination;
people = subject.<Person>select(query).collect(Collectors.toList());
assertEquals(5L, people.stream().map(Person::getId).findFirst().orElse(-0L));
}
use of jakarta.nosql.column.ColumnQuery in project jnosql-diana by eclipse.
the class ColumnRepositoryProxySortTest method shouldFindByNameOrderByName2.
@Test
public void shouldFindByNameOrderByName2() {
when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of((Person.builder().build())));
Pagination pagination = getPagination();
personRepository.findByNameOrderByName("name", pagination, Sorts.sorts().desc("age").asc("phone"));
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(EQUALS, condition.getCondition());
assertEquals(Column.of("name", "name"), condition.getColumn());
assertEquals(pagination.getSkip(), query.getSkip());
assertEquals(pagination.getLimit(), query.getLimit());
assertThat(query.getSorts(), Matchers.contains(Sort.asc("name"), Sort.desc("age"), Sort.asc("phone")));
}
use of jakarta.nosql.column.ColumnQuery in project jnosql-diana by eclipse.
the class DefaultColumnEventPersistManagerTest method shouldFirePreQuery.
@Test
public void shouldFirePreQuery() {
ColumnQuery query = select().from("person").build();
subject.firePreQuery(query);
ArgumentCaptor<ColumnQueryExecute> captor = ArgumentCaptor.forClass(ColumnQueryExecute.class);
verify(columnQueryExecute).fire(captor.capture());
assertEquals(query, captor.getValue().getQuery());
}
use of jakarta.nosql.column.ColumnQuery in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method shouldPagingState.
@Test
public void shouldPagingState() {
for (long index = 1; index <= 10; index++) {
ColumnEntity columnFamily = getColumnFamily();
columnFamily.add("id", index);
entityManager.insert(columnFamily);
}
ColumnQuery query = select().from(Constants.COLUMN_FAMILY).build();
CassandraQuery cassandraQuery = CassandraQuery.of(query);
assertFalse(cassandraQuery.getPagingState().isPresent());
List<ColumnEntity> entities = entityManager.select(cassandraQuery).collect(toList());
assertEquals(10, entities.size());
assertTrue(cassandraQuery.getPagingState().isPresent());
}
use of jakarta.nosql.column.ColumnQuery in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method shouldReturnSingleResult.
@Test
public void shouldReturnSingleResult() {
ColumnEntity columnEntity = getColumnFamily();
entityManager.insert(columnEntity);
ColumnQuery query = select().from(columnEntity.getName()).where("id").eq(10L).build();
Optional<ColumnEntity> entity = entityManager.singleResult(query);
query = select().from(columnEntity.getName()).where("id").eq(-10L).build();
entity = entityManager.singleResult(query);
assertFalse(entity.isPresent());
}
Aggregations