1515package org .eclipse .jnosql .databases .arangodb .integration ;
1616
1717
18+ import jakarta .data .page .CursoredPage ;
19+ import jakarta .data .page .PageRequest ;
1820import jakarta .inject .Inject ;
1921import org .assertj .core .api .SoftAssertions ;
22+ import org .eclipse .jnosql .communication .semistructured .SelectQuery ;
2023import org .eclipse .jnosql .databases .arangodb .communication .ArangoDBConfigurations ;
2124import org .eclipse .jnosql .databases .arangodb .mapping .ArangoDBTemplate ;
2225import org .eclipse .jnosql .mapping .Database ;
3033import org .jboss .weld .junit5 .auto .AddExtensions ;
3134import org .jboss .weld .junit5 .auto .AddPackages ;
3235import org .jboss .weld .junit5 .auto .EnableAutoWeld ;
36+ import org .junit .jupiter .api .BeforeEach ;
3337import org .junit .jupiter .api .Test ;
3438import org .junit .jupiter .api .condition .EnabledIfSystemProperty ;
3539
40+ import java .util .List ;
3641import java .util .Optional ;
3742
3843import static java .util .UUID .randomUUID ;
@@ -61,6 +66,11 @@ class ArangoDBTemplateIntegrationTest {
6166 System .setProperty (MappingConfigurations .DOCUMENT_DATABASE .get (), "library" );
6267 }
6368
69+ @ BeforeEach
70+ void setUp () {
71+ this .template .delete (Book .class ).execute ();
72+ }
73+
6474 @ Test
6575 void shouldInsert () {
6676 Book book = new Book (randomUUID ().toString (), "Effective Java" , 1 );
@@ -112,7 +122,7 @@ void shouldDelete() {
112122 }
113123
114124 @ Test
115- void shouldDeleteAll (){
125+ void shouldDeleteAll () {
116126 for (int index = 0 ; index < 20 ; index ++) {
117127 Book book = new Book (randomUUID ().toString (), "Effective Java" , 1 );
118128 assertThat (template .insert (book ))
@@ -126,7 +136,7 @@ void shouldDeleteAll(){
126136
127137
128138 @ Test
129- void shouldUpdateNullValues (){
139+ void shouldUpdateNullValues () {
130140 var book = new Book (randomUUID ().toString (), "Effective Java" , 1 );
131141 template .insert (book );
132142 template .update (new Book (book .id (), null , 2 ));
@@ -138,7 +148,76 @@ void shouldUpdateNullValues(){
138148 softly .assertThat (optional ).get ().extracting (Book ::edition ).isEqualTo (2 );
139149 });
140150 }
141-
142151
152+ @ Test
153+ void shouldExecuteLimit () {
154+
155+ for (int index = 1 ; index < 10 ; index ++) {
156+ var book = new Book (randomUUID ().toString (), "Effective Java" , index );
157+ template .insert (book );
158+ }
159+
160+ List <Book > books = template .select (Book .class ).orderBy ("edition" )
161+ .asc ().limit (4 ).result ();
162+
163+ SoftAssertions .assertSoftly (soft -> {
164+ soft .assertThat (books ).hasSize (4 );
165+ var editions = books .stream ().map (Book ::edition ).toList ();
166+ soft .assertThat (editions ).hasSize (4 ).contains (1 , 2 , 3 , 4 );
167+ });
168+
169+ }
170+
171+ @ Test
172+ void shouldExecuteSkip () {
173+ for (int index = 1 ; index < 10 ; index ++) {
174+ var book = new Book (randomUUID ().toString (), "Effective Java" , index );
175+ template .insert (book );
176+ }
177+
178+ List <Book > books = template .select (Book .class ).orderBy ("edition" )
179+ .asc ().skip (4 ).result ();
180+
181+ SoftAssertions .assertSoftly (soft -> {
182+ soft .assertThat (books ).hasSize (5 );
183+ var editions = books .stream ().map (Book ::edition ).toList ();
184+ soft .assertThat (editions ).hasSize (5 ).contains (5 , 6 , 7 , 8 , 9 );
185+ });
186+ }
187+
188+ @ Test
189+ void shouldExecuteLimitStart () {
190+ for (int index = 1 ; index < 10 ; index ++) {
191+ var book = new Book (randomUUID ().toString (), "Effective Java" , index );
192+ template .insert (book );
193+ }
194+
195+ List <Book > books = template .select (Book .class ).orderBy ("edition" )
196+ .asc ().skip (4 ).limit (3 ).result ();
143197
198+ SoftAssertions .assertSoftly (soft -> {
199+ soft .assertThat (books ).hasSize (3 );
200+ var editions = books .stream ().map (Book ::edition ).toList ();
201+ soft .assertThat (editions ).hasSize (3 ).contains (5 , 6 , 7 );
202+ });
203+ }
204+
205+ @ Test
206+ void shouldSelectCursorSize () {
207+ for (int index = 1 ; index < 10 ; index ++) {
208+ var book = new Book (randomUUID ().toString (), "Effective Java" , index );
209+ template .insert (book );
210+ }
211+ var select = SelectQuery .select ().from ("Book" ).orderBy ("edition" ).asc ()
212+ .skip (4 ).limit (3 ).build ();
213+ var pageRequest = PageRequest .ofSize (3 );
214+ CursoredPage <Book > entities = template .selectCursor (select , pageRequest );
215+
216+ SoftAssertions .assertSoftly (soft -> {
217+ var content = entities .content ();
218+ soft .assertThat (content ).hasSize (3 );
219+ var editions = content .stream ().map (Book ::edition ).toList ();
220+ soft .assertThat (editions ).hasSize (3 ).contains (1 , 2 , 3 );
221+ });
222+ }
144223}
0 commit comments