Skip to content

Commit

Permalink
test: add special parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
  • Loading branch information
otaviojava committed Apr 13, 2024
1 parent 516aec2 commit 3a1bc31
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package org.eclipse.jnosql.lite.mapping.entities;

import jakarta.data.Order;
import jakarta.data.Sort;
import jakarta.data.page.CursoredPage;
import jakarta.data.page.Page;
import jakarta.data.page.PageRequest;
Expand Down Expand Up @@ -73,5 +75,13 @@ default Map<Boolean, List<Person>> merge(String name) {
@Find
Page<Person> findOffSet(@By("name") String name, PageRequest pageRequest);

@Find
@OrderBy("name")
Page<Person> findOffSet(@By("name") String name, PageRequest pageRequest, Sort<Person> sort);


@Find
@OrderBy("name")
Page<Person> findOffSet(@By("name") String name, PageRequest pageRequest, Order<Person> order);

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.eclipse.jnosql.lite.mapping.entities;

import jakarta.data.Order;
import jakarta.data.Sort;
import jakarta.data.page.CursoredPage;
import jakarta.data.page.PageRequest;
Expand Down Expand Up @@ -345,5 +346,41 @@ void shouldFindByOffSetPagination() {
});
}

@Test
void shouldFindByOffSetPaginationSpecialParameter() {
when(template.select(any(SelectQuery.class))).thenReturn(Stream.of(new Person(), new Person()));
var result = this.personRepository.findOffSet("Ada", PageRequest.ofPage(1).size(2),
Sort.asc("age"));
ArgumentCaptor<SelectQuery> captor = ArgumentCaptor.forClass(SelectQuery.class);
assertThat(result).isNotNull();
verify(template).select(captor.capture());
SelectQuery query = captor.getValue();
CriteriaCondition condition = query.condition().orElseThrow();
SoftAssertions.assertSoftly(soft -> {
soft.assertThat(condition.condition()).isEqualTo(Condition.EQUALS);
soft.assertThat(condition.element().get(String.class)).isEqualTo("Ada");
soft.assertThat(query.sorts()).hasSize(2);
soft.assertThat(query.sorts()).contains(Sort.asc("name"), Sort.asc("age"));
});
}

@Test
void shouldFindByOffSetPaginationSpecialParameter2() {
when(template.select(any(SelectQuery.class))).thenReturn(Stream.of(new Person(), new Person()));
var result = this.personRepository.findOffSet("Ada", PageRequest.ofPage(1).size(2),
Order.by(Sort.asc("age"), Sort.desc("name")));
ArgumentCaptor<SelectQuery> captor = ArgumentCaptor.forClass(SelectQuery.class);
assertThat(result).isNotNull();
verify(template).select(captor.capture());
SelectQuery query = captor.getValue();
CriteriaCondition condition = query.condition().orElseThrow();
SoftAssertions.assertSoftly(soft -> {
soft.assertThat(condition.condition()).isEqualTo(Condition.EQUALS);
soft.assertThat(condition.element().get(String.class)).isEqualTo("Ada");
soft.assertThat(query.sorts()).hasSize(3);
soft.assertThat(query.sorts()).contains(Sort.asc("name"), Sort.asc("age"), Sort.desc("name"));
});
}


}

0 comments on commit 3a1bc31

Please sign in to comment.