@@ -174,30 +174,65 @@ void findByAccountId() throws Exception {
174174 hederaTestUtils .waitForMirrorNodeRecords ();
175175
176176 //when
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 findByAccountIdWIthZeroResult () throws Exception {
189- //given
190- final String name = "Tokemon cards" ;
191- final String symbol = "TOK" ;
192- final TokenId tokenId = nftClient .createNftType (name , symbol );
193- final Account account = accountClient .createAccount ();
194- final AccountId newOwner = account .accountId ();
195- final PrivateKey newOwnerPrivateKey = account .privateKey ();
196- nftClient .associateNft (tokenId , newOwner , newOwnerPrivateKey );
197- hederaTestUtils .waitForMirrorNodeRecords ();
198-
199- //when
200- final Page <Nft > slice = 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 );
201236 final List <Nft > result = getAll (slice );
202237
203238 //then
@@ -235,6 +270,40 @@ void findByTokenIdAndAccountId() throws Exception {
235270 Assertions .assertTrue (result .stream ().anyMatch (nft -> nft .serial () == serial .get (0 )));
236271 Assertions .assertTrue (result .stream ().anyMatch (nft -> nft .serial () == serial .get (1 )));
237272 }
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+ }
238307
239308 @ Test
240309 void findByTokenIdAndAccountIdWithZeroResult () throws Exception {
@@ -339,5 +408,6 @@ void findByTokenIdAndAccountIdAndSerialWithZeroResult() throws Exception {
339408 //then
340409 Assertions .assertNotNull (result );
341410 Assertions .assertFalse (result .isPresent ());
411+
342412 }
343413}
0 commit comments