@@ -174,29 +174,66 @@ void findByAccountId() throws Exception {
174174 hederaTestUtils .waitForMirrorNodeRecords ();
175175
176176 //when
177- final List <Nft > result = nftRepository .findByOwner (newOwner );
178-
179- //then
180- Assertions .assertNotNull (result );
181- Assertions .assertEquals (2 , result .size ());
182- Assertions .assertTrue (result .stream ().anyMatch (nft -> nft .serial () == serial .get (0 )));
183- Assertions .assertTrue (result .stream ().anyMatch (nft -> nft .serial () == serial .get (1 )));
184- }
185-
186- @ Test
187- void findByAccountIdWIthZeroResult () throws Exception {
188- //given
189- final String name = "Tokemon cards" ;
190- final String symbol = "TOK" ;
191- final TokenId tokenId = nftClient .createNftType (name , symbol );
192- final Account account = accountClient .createAccount ();
193- final AccountId newOwner = account .accountId ();
194- final PrivateKey newOwnerPrivateKey = account .privateKey ();
195- nftClient .associateNft (tokenId , newOwner , newOwnerPrivateKey );
196- hederaTestUtils .waitForMirrorNodeRecords ();
197-
198- //when
199- final List <Nft > result = nftRepository .findByOwner (newOwner );
177+ final Page <Nft > slice = nftRepository .findByOwner (newOwner );
178+ final List <Nft > result = getAll (slice );
179+
180+ // then
181+ Assertions .assertNotNull (result );
182+ Assertions .assertEquals (2 , result .size ());
183+ Assertions .assertTrue (result .stream ().anyMatch (nft -> nft .serial () == serial .get (0 )));
184+ Assertions .assertTrue (result .stream ().anyMatch (nft -> nft .serial () == serial .get (1 )));
185+ }
186+
187+ @ Test
188+ void findByAccountIdForSomePages () throws Exception {
189+ // given
190+ final String name = "Tokemon cards" ;
191+ final String symbol = "TOK" ;
192+
193+ final AccountId adminAccountId = adminAccount .accountId ();
194+ final PrivateKey adminAccountPrivateKey = adminAccount .privateKey ();
195+ final Account account = accountClient .createAccount ();
196+ final AccountId newOwner = account .accountId ();
197+ final PrivateKey newOwnerPrivateKey = account .privateKey ();
198+ final List <byte []> metadata = IntStream .range (0 , 40 ).mapToObj (i -> "metadata" + i )
199+ .map (s -> s .getBytes (StandardCharsets .UTF_8 )).toList ();
200+ final TokenId tokenId = nftClient .createNftType (name , symbol );
201+ final int batchSize = 10 ;
202+ for (int i = 0 ; i < metadata .size (); i += batchSize ) {
203+ final int start = i ;
204+ final int end = Math .min (i + batchSize , metadata .size ());
205+ final List <Long > serial = nftClient .mintNfts (tokenId , metadata .subList (start , end ).toArray (new byte [0 ][]));
206+ nftClient .transferNft (tokenId , serial .get (i ), adminAccountId , adminAccountPrivateKey , newOwner );
207+
208+ }
209+ nftClient .associateNft (tokenId , newOwner , newOwnerPrivateKey );
210+ hederaTestUtils .waitForMirrorNodeRecords ();
211+
212+ // when
213+ final Page <Nft > slice = nftRepository .findByOwner (newOwner );
214+ final List <Nft > result = getAll (slice );
215+
216+ // then
217+ Assertions .assertNotNull (result );
218+ Assertions .assertEquals (metadata .size (), result .size ());
219+
220+ }
221+
222+ @ Test
223+ void findByAccountIdWIthZeroResult () throws Exception {
224+ // given
225+ final String name = "Tokemon cards" ;
226+ final String symbol = "TOK" ;
227+ final TokenId tokenId = nftClient .createNftType (name , symbol );
228+ final Account account = accountClient .createAccount ();
229+ final AccountId newOwner = account .accountId ();
230+ final PrivateKey newOwnerPrivateKey = account .privateKey ();
231+ nftClient .associateNft (tokenId , newOwner , newOwnerPrivateKey );
232+ hederaTestUtils .waitForMirrorNodeRecords ();
233+
234+ // when
235+ final Page <Nft > slice = nftRepository .findByOwner (newOwner );
236+ final List <Nft > result = getAll (slice );
200237
201238 //then
202239 Assertions .assertNotNull (result );
@@ -224,14 +261,49 @@ void findByTokenIdAndAccountId() throws Exception {
224261 hederaTestUtils .waitForMirrorNodeRecords ();
225262
226263 //when
227- final List <Nft > result = nftRepository .findByOwnerAndType (newOwner , tokenId );
264+ final Page <Nft > slice = nftRepository .findByOwnerAndType (newOwner , tokenId );
265+ final List <Nft > result = getAll (slice );
228266
229267 //then
230268 Assertions .assertNotNull (result );
231269 Assertions .assertEquals (2 , result .size ());
232270 Assertions .assertTrue (result .stream ().anyMatch (nft -> nft .serial () == serial .get (0 )));
233271 Assertions .assertTrue (result .stream ().anyMatch (nft -> nft .serial () == serial .get (1 )));
234272 }
273+
274+ @ Test
275+ void findByTokenIdAndAccountIdForSomePages () throws Exception {
276+ // given
277+ final String name = "Tokemon cards" ;
278+ final String symbol = "TOK" ;
279+ final List <byte []> metadata = IntStream .range (0 , 40 ).mapToObj (i -> "metadata" + i )
280+ .map (s -> s .getBytes (StandardCharsets .UTF_8 )).toList ();
281+ final TokenId tokenId = nftClient .createNftType (name , symbol );
282+
283+ final AccountId adminAccountId = adminAccount .accountId ();
284+ final PrivateKey adminAccountPrivateKey = adminAccount .privateKey ();
285+ final Account account = accountClient .createAccount ();
286+ final AccountId newOwner = account .accountId ();
287+ final PrivateKey newOwnerPrivateKey = account .privateKey ();
288+ final int batchSize = 10 ;
289+ for (int i = 0 ; i < metadata .size (); i += batchSize ) {
290+ final int start = i ;
291+ final int end = Math .min (i + batchSize , metadata .size ());
292+ final List <Long > serial = nftClient .mintNfts (tokenId , metadata .subList (start , end ).toArray (new byte [0 ][]));
293+ nftClient .transferNft (tokenId , serial .get (i ), adminAccountId , adminAccountPrivateKey , newOwner );
294+
295+ }
296+ nftClient .associateNft (tokenId , newOwner , newOwnerPrivateKey );
297+ hederaTestUtils .waitForMirrorNodeRecords ();
298+
299+ // when
300+ final Page <Nft > slice = nftRepository .findByOwnerAndType (newOwner , tokenId );
301+ final List <Nft > result = getAll (slice );
302+
303+ // then
304+ Assertions .assertNotNull (result );
305+ Assertions .assertEquals (metadata .size (), result .size ());
306+ }
235307
236308 @ Test
237309 void findByTokenIdAndAccountIdWithZeroResult () throws Exception {
@@ -246,7 +318,8 @@ void findByTokenIdAndAccountIdWithZeroResult() throws Exception {
246318 hederaTestUtils .waitForMirrorNodeRecords ();
247319
248320 //when
249- final List <Nft > result = nftRepository .findByOwnerAndType (newOwner , tokenId );
321+ final Page <Nft > slice = nftRepository .findByOwnerAndType (newOwner , tokenId );
322+ final List <Nft > result = getAll (slice );
250323
251324 //then
252325 Assertions .assertNotNull (result );
@@ -335,5 +408,6 @@ void findByTokenIdAndAccountIdAndSerialWithZeroResult() throws Exception {
335408 //then
336409 Assertions .assertNotNull (result );
337410 Assertions .assertFalse (result .isPresent ());
411+
338412 }
339413}
0 commit comments