use of io.nem.symbol.sdk.api.Page in project nem2-sdk-java by nemtech.
the class MetadataTransactionServiceTest method shouldCreateMosaicMetadataTransactionFactoryWhenNotFound.
@Test
void shouldCreateMosaicMetadataTransactionFactoryWhenNotFound() throws Exception {
BigInteger metadataKey = BigInteger.valueOf(10);
String newValue = "the new Message";
MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetId(mosaicId).metadataType(MetadataType.MOSAIC);
Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.just(new Page<>(Collections.emptyList())));
MosaicMetadataTransactionFactory result = service.createMosaicMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress, mosaicId).toFuture().get();
Assertions.assertEquals(metadataKey, result.getScopedMetadataKey());
Assertions.assertArrayEquals(StringEncoder.getBytes(newValue), result.getValue());
Assertions.assertEquals(StringEncoder.getBytes(newValue).length, result.getValueSizeDelta());
Assertions.assertEquals(targetAccount.getAddress(), result.getTargetAddress());
Assertions.assertEquals(mosaicId.getId(), result.getTargetMosaicId().getId());
Mockito.verify(metadataRepositoryMock).search(Mockito.eq(criteria));
}
use of io.nem.symbol.sdk.api.Page in project nem2-sdk-java by nemtech.
the class MetadataTransactionServiceTest method shouldCreateAccountMetadataTransactionFactoryWhenNotFound.
@Test
void shouldCreateAccountMetadataTransactionFactoryWhenNotFound() throws Exception {
BigInteger metadataKey = BigInteger.valueOf(10);
String newValue = "the new Message";
MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetAddress(targetAccount.getAddress()).metadataType(MetadataType.ACCOUNT);
Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.just(new Page<>(Collections.emptyList())));
AccountMetadataTransactionFactory result = service.createAccountMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress).toFuture().get();
Assertions.assertEquals(metadataKey, result.getScopedMetadataKey());
Assertions.assertArrayEquals(StringEncoder.getBytes(newValue), result.getValue());
Assertions.assertEquals(StringEncoder.getBytes(newValue).length, result.getValueSizeDelta());
Assertions.assertEquals(targetAccount.getAddress(), result.getTargetAddress());
Mockito.verify(metadataRepositoryMock).search(Mockito.eq(criteria));
}
use of io.nem.symbol.sdk.api.Page in project nem2-sdk-java by nemtech.
the class StateProofServiceTest method namespace.
@Test
void namespace() throws Exception {
NamespaceRepository repository = mock(NamespaceRepository.class);
when(factory.createNamespaceRepository()).thenReturn(repository);
NamespaceId id = NamespaceId.createFromId(BigInteger.ONE);
NamespaceInfo state = Mockito.mock(NamespaceInfo.class);
when(state.getId()).thenReturn(id);
when(state.serialize(any())).thenReturn(ConvertUtils.fromHexToBytes(serialized));
when(repository.streamer()).thenReturn(new PaginationStreamer<>(repository));
when(repository.search(any())).thenReturn(Observable.just(new Page<>(new ArrayList<>())));
when(repository.getNamespace(eq(id))).thenReturn(Observable.just(state));
when(repository.getNamespaceMerkle(eq(id))).thenReturn(Observable.just(tree));
StateMerkleProof<NamespaceInfo> proof = service.namespace(id).toFuture().get();
Assertions.assertTrue(proof.isValid());
Assertions.assertEquals(state, proof.getState());
}
use of io.nem.symbol.sdk.api.Page in project nem2-sdk-java by nemtech.
the class ReceiptRepositoryVertxImpl method searchReceipts.
@Override
public Observable<Page<TransactionStatement>> searchReceipts(TransactionStatementSearchCriteria criteria) {
BigInteger height = criteria.getHeight();
BigInteger fromHeight = criteria.getFromHeight();
BigInteger toHeight = criteria.getToHeight();
List<ReceiptTypeEnum> receiptTypes = toDto(criteria.getReceiptTypes());
String recipientAddress = toDto(criteria.getRecipientAddress());
String senderAddress = toDto(criteria.getSenderAddress());
String targetAddress = toDto(criteria.getTargetAddress());
String artifactId = criteria.getArtifactId();
Integer pageSize = criteria.getPageSize();
Integer pageNumber = criteria.getPageNumber();
String offset = criteria.getOffset();
Order order = toDto(criteria.getOrder());
Consumer<Handler<AsyncResult<TransactionStatementPage>>> callback = (handler) -> getClient().searchReceipts(height, fromHeight, toHeight, receiptTypes, recipientAddress, senderAddress, targetAddress, artifactId, pageSize, pageNumber, offset, order, handler);
return exceptionHandling(call(callback).map(page -> this.toPage(page.getPagination(), page.getData().stream().map(mapper::createTransactionStatement).collect(Collectors.toList()))));
}
use of io.nem.symbol.sdk.api.Page in project nem2-sdk-java by nemtech.
the class ReceiptRepositoryVertxImpl method searchAddressResolutionStatements.
@Override
public Observable<Page<AddressResolutionStatement>> searchAddressResolutionStatements(ResolutionStatementSearchCriteria criteria) {
BigInteger height = criteria.getHeight();
Integer pageSize = criteria.getPageSize();
Integer pageNumber = criteria.getPageNumber();
String offset = criteria.getOffset();
Order order = toDto(criteria.getOrder());
Consumer<Handler<AsyncResult<ResolutionStatementPage>>> callback = (handler) -> getClient().searchAddressResolutionStatements(height, pageSize, pageNumber, offset, order, handler);
return exceptionHandling(call(callback).map(page -> this.toPage(page.getPagination(), page.getData().stream().map(mapper::createAddressResolutionStatementFromDto).collect(Collectors.toList()))));
}
Aggregations