15
15
package org .eclipse .jnosql .databases .arangodb .integration ;
16
16
17
17
18
+ import jakarta .data .page .CursoredPage ;
19
+ import jakarta .data .page .PageRequest ;
18
20
import jakarta .inject .Inject ;
19
21
import org .assertj .core .api .SoftAssertions ;
22
+ import org .eclipse .jnosql .communication .semistructured .SelectQuery ;
20
23
import org .eclipse .jnosql .databases .arangodb .communication .ArangoDBConfigurations ;
21
24
import org .eclipse .jnosql .databases .arangodb .mapping .ArangoDBTemplate ;
22
25
import org .eclipse .jnosql .mapping .Database ;
30
33
import org .jboss .weld .junit5 .auto .AddExtensions ;
31
34
import org .jboss .weld .junit5 .auto .AddPackages ;
32
35
import org .jboss .weld .junit5 .auto .EnableAutoWeld ;
36
+ import org .junit .jupiter .api .BeforeEach ;
33
37
import org .junit .jupiter .api .Test ;
34
38
import org .junit .jupiter .api .condition .EnabledIfSystemProperty ;
35
39
40
+ import java .util .List ;
36
41
import java .util .Optional ;
37
42
38
43
import static java .util .UUID .randomUUID ;
@@ -61,6 +66,11 @@ class ArangoDBTemplateIntegrationTest {
61
66
System .setProperty (MappingConfigurations .DOCUMENT_DATABASE .get (), "library" );
62
67
}
63
68
69
+ @ BeforeEach
70
+ void setUp () {
71
+ this .template .delete (Book .class ).execute ();
72
+ }
73
+
64
74
@ Test
65
75
void shouldInsert () {
66
76
Book book = new Book (randomUUID ().toString (), "Effective Java" , 1 );
@@ -112,7 +122,7 @@ void shouldDelete() {
112
122
}
113
123
114
124
@ Test
115
- void shouldDeleteAll (){
125
+ void shouldDeleteAll () {
116
126
for (int index = 0 ; index < 20 ; index ++) {
117
127
Book book = new Book (randomUUID ().toString (), "Effective Java" , 1 );
118
128
assertThat (template .insert (book ))
@@ -126,7 +136,7 @@ void shouldDeleteAll(){
126
136
127
137
128
138
@ Test
129
- void shouldUpdateNullValues (){
139
+ void shouldUpdateNullValues () {
130
140
var book = new Book (randomUUID ().toString (), "Effective Java" , 1 );
131
141
template .insert (book );
132
142
template .update (new Book (book .id (), null , 2 ));
@@ -138,7 +148,76 @@ void shouldUpdateNullValues(){
138
148
softly .assertThat (optional ).get ().extracting (Book ::edition ).isEqualTo (2 );
139
149
});
140
150
}
141
-
142
151
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 ();
143
197
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
+ }
144
223
}
0 commit comments