6
6
import java .util .List ;
7
7
import java .util .logging .Logger ;
8
8
9
- import static org .junit .jupiter .api .Assertions .assertEquals ;
10
9
11
10
@ TestInstance (TestInstance .Lifecycle .PER_CLASS )
12
11
@ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
@@ -24,15 +23,15 @@ void testNewAssetLibrary() {
24
23
public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
25
24
Asset model = assets .get (0 );
26
25
Assertions .assertTrue (model .getAssetUid ().startsWith ("blt" ));
27
- assertEquals ("image/png" , model .getFileType ());
28
- assertEquals ("13006" , model .getFileSize ());
29
- assertEquals ("iot-icon.png" , model .getFileName ());
26
+ Assertions . assertEquals ("image/png" , model .getFileType ());
27
+ Assertions . assertEquals ("13006" , model .getFileSize ());
28
+ Assertions . assertEquals ("iot-icon.png" , model .getFileName ());
30
29
Assertions .assertTrue (model .getUrl ().endsWith ("iot-icon.png" ));
31
30
Assertions .assertTrue (model .toJSON ().has ("created_at" ));
32
31
Assertions .assertTrue (model .getCreatedBy ().startsWith ("blt" ));
33
- assertEquals ("gregory" , model .getUpdateAt ().getCalendarType ());
32
+ Assertions . assertEquals ("gregory" , model .getUpdateAt ().getCalendarType ());
34
33
Assertions .assertTrue (model .getUpdatedBy ().startsWith ("blt" ));
35
- assertEquals ("" , model .getDeletedBy ());
34
+ Assertions . assertEquals ("" , model .getDeletedBy ());
36
35
logger .info ("passed..." );
37
36
}
38
37
});
@@ -107,4 +106,60 @@ public void onCompletion(ResponseType responseType, List<Asset> assets, Error er
107
106
}
108
107
});
109
108
}
109
+
110
+ @ Test
111
+ void testFetchFirst10Assets () throws IllegalAccessException {
112
+ AssetLibrary assetLibrary = stack .assetLibrary ();
113
+ assetLibrary .skip (0 ).limit (10 ).fetchAll (new FetchAssetsCallback () {
114
+ @ Override
115
+ public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
116
+ Assertions .assertNotNull (assets , "Assets list should not be null" );
117
+ Assertions .assertTrue (assets .size () <= 10 , "Assets fetched should not exceed the limit" );
118
+ }
119
+ });
120
+ }
121
+
122
+ @ Test
123
+ void testFetchAssetsWithSkip () throws IllegalAccessException {
124
+ AssetLibrary assetLibrary = stack .assetLibrary ();
125
+ assetLibrary .skip (10 ).limit (10 ).fetchAll (new FetchAssetsCallback () {
126
+ @ Override
127
+ public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
128
+ Assertions .assertNotNull (assets , "Assets list should not be null" );
129
+ Assertions .assertTrue (assets .size () <= 10 , "Assets fetched should not exceed the limit" );
130
+ }
131
+ });
132
+ }
133
+
134
+ @ Test
135
+ void testFetchBeyondAvailableAssets () throws IllegalAccessException {
136
+ AssetLibrary assetLibrary = stack .assetLibrary ();
137
+ assetLibrary .skip (5000 ).limit (10 ).fetchAll (new FetchAssetsCallback () {
138
+ @ Override
139
+ public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
140
+ Assertions .assertNotNull (assets , "Assets list should not be null" );
141
+ Assertions .assertEquals (0 , assets .size (), "No assets should be fetched when skip exceeds available assets" );
142
+ }
143
+ });
144
+ }
145
+
146
+ @ Test
147
+ void testFetchAllAssetsInBatches () throws IllegalAccessException {
148
+ AssetLibrary assetLibrary = stack .assetLibrary ();
149
+ int limit = 50 ;
150
+ int totalAssetsFetched [] = {0 };
151
+
152
+ for (int skip = 0 ; skip < 150 ; skip += limit ) {
153
+ assetLibrary .skip (skip ).limit (limit ).fetchAll (new FetchAssetsCallback () {
154
+ @ Override
155
+ public void onCompletion (ResponseType responseType , List <Asset > assets , Error error ) {
156
+ totalAssetsFetched [0 ] += assets .size ();
157
+ Assertions .assertNotNull (assets , "Assets list should not be null" );
158
+ Assertions .assertTrue (assets .size () <= limit , "Assets fetched should not exceed the limit" );
159
+ Assertions .assertEquals (6 , totalAssetsFetched [0 ]);
160
+ }
161
+ });
162
+ }
163
+ }
164
+
110
165
}
0 commit comments