From 3a1bc31274d47f3056e53a9a03833ca3c5a7a2e2 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 13 Apr 2024 08:41:07 +0100 Subject: [PATCH] test: add special parameter Signed-off-by: Otavio Santana --- .../entities/PersonCrudRepository.java | 10 +++++ .../entities/PersonCrudRepositoryTest.java | 37 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/jnosql-lite/mapping-lite-document-test/src/main/java/org/eclipse/jnosql/lite/mapping/entities/PersonCrudRepository.java b/jnosql-lite/mapping-lite-document-test/src/main/java/org/eclipse/jnosql/lite/mapping/entities/PersonCrudRepository.java index 8d8786c6..3e28ecf4 100644 --- a/jnosql-lite/mapping-lite-document-test/src/main/java/org/eclipse/jnosql/lite/mapping/entities/PersonCrudRepository.java +++ b/jnosql-lite/mapping-lite-document-test/src/main/java/org/eclipse/jnosql/lite/mapping/entities/PersonCrudRepository.java @@ -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; @@ -73,5 +75,13 @@ default Map> merge(String name) { @Find Page findOffSet(@By("name") String name, PageRequest pageRequest); + @Find + @OrderBy("name") + Page findOffSet(@By("name") String name, PageRequest pageRequest, Sort sort); + + + @Find + @OrderBy("name") + Page findOffSet(@By("name") String name, PageRequest pageRequest, Order order); } diff --git a/jnosql-lite/mapping-lite-document-test/src/test/java/org/eclipse/jnosql/lite/mapping/entities/PersonCrudRepositoryTest.java b/jnosql-lite/mapping-lite-document-test/src/test/java/org/eclipse/jnosql/lite/mapping/entities/PersonCrudRepositoryTest.java index 352cad1c..6c260340 100644 --- a/jnosql-lite/mapping-lite-document-test/src/test/java/org/eclipse/jnosql/lite/mapping/entities/PersonCrudRepositoryTest.java +++ b/jnosql-lite/mapping-lite-document-test/src/test/java/org/eclipse/jnosql/lite/mapping/entities/PersonCrudRepositoryTest.java @@ -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; @@ -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 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 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")); + }); + } + } \ No newline at end of file