Search in sources :

Example 11 with Page

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));
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) BigInteger(java.math.BigInteger) Page(io.nem.symbol.sdk.api.Page) MosaicMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransactionFactory) Test(org.junit.jupiter.api.Test)

Example 12 with Page

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));
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) BigInteger(java.math.BigInteger) AccountMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.AccountMetadataTransactionFactory) Page(io.nem.symbol.sdk.api.Page) Test(org.junit.jupiter.api.Test)

Example 13 with Page

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());
}
Also used : NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) Page(io.nem.symbol.sdk.api.Page) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) Test(org.junit.jupiter.api.Test)

Example 14 with Page

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()))));
}
Also used : BigInteger(java.math.BigInteger) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) ApiClient(io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient) Collectors(java.util.stream.Collectors) TransactionStatementSearchCriteria(io.nem.symbol.sdk.api.TransactionStatementSearchCriteria) ReceiptType(io.nem.symbol.sdk.model.receipt.ReceiptType) TransactionStatementPage(io.nem.symbol.sdk.openapi.vertx.model.TransactionStatementPage) ReceiptRepository(io.nem.symbol.sdk.api.ReceiptRepository) Consumer(java.util.function.Consumer) List(java.util.List) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) ReceiptRoutesApi(io.nem.symbol.sdk.openapi.vertx.api.ReceiptRoutesApi) TransactionStatement(io.nem.symbol.sdk.model.receipt.TransactionStatement) ResolutionStatementSearchCriteria(io.nem.symbol.sdk.api.ResolutionStatementSearchCriteria) AddressResolutionStatement(io.nem.symbol.sdk.model.receipt.AddressResolutionStatement) MosaicResolutionStatement(io.nem.symbol.sdk.model.receipt.MosaicResolutionStatement) ReceiptRoutesApiImpl(io.nem.symbol.sdk.openapi.vertx.api.ReceiptRoutesApiImpl) ResolutionStatementPage(io.nem.symbol.sdk.openapi.vertx.model.ResolutionStatementPage) ReceiptTypeEnum(io.nem.symbol.sdk.openapi.vertx.model.ReceiptTypeEnum) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) Page(io.nem.symbol.sdk.api.Page) TransactionStatementPage(io.nem.symbol.sdk.openapi.vertx.model.TransactionStatementPage) BigInteger(java.math.BigInteger) Handler(io.vertx.core.Handler) ReceiptTypeEnum(io.nem.symbol.sdk.openapi.vertx.model.ReceiptTypeEnum)

Example 15 with Page

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()))));
}
Also used : BigInteger(java.math.BigInteger) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) ApiClient(io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient) Collectors(java.util.stream.Collectors) TransactionStatementSearchCriteria(io.nem.symbol.sdk.api.TransactionStatementSearchCriteria) ReceiptType(io.nem.symbol.sdk.model.receipt.ReceiptType) TransactionStatementPage(io.nem.symbol.sdk.openapi.vertx.model.TransactionStatementPage) ReceiptRepository(io.nem.symbol.sdk.api.ReceiptRepository) Consumer(java.util.function.Consumer) List(java.util.List) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) ReceiptRoutesApi(io.nem.symbol.sdk.openapi.vertx.api.ReceiptRoutesApi) TransactionStatement(io.nem.symbol.sdk.model.receipt.TransactionStatement) ResolutionStatementSearchCriteria(io.nem.symbol.sdk.api.ResolutionStatementSearchCriteria) AddressResolutionStatement(io.nem.symbol.sdk.model.receipt.AddressResolutionStatement) MosaicResolutionStatement(io.nem.symbol.sdk.model.receipt.MosaicResolutionStatement) ReceiptRoutesApiImpl(io.nem.symbol.sdk.openapi.vertx.api.ReceiptRoutesApiImpl) ResolutionStatementPage(io.nem.symbol.sdk.openapi.vertx.model.ResolutionStatementPage) ReceiptTypeEnum(io.nem.symbol.sdk.openapi.vertx.model.ReceiptTypeEnum) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) Page(io.nem.symbol.sdk.api.Page) BigInteger(java.math.BigInteger) Handler(io.vertx.core.Handler) ResolutionStatementPage(io.nem.symbol.sdk.openapi.vertx.model.ResolutionStatementPage)

Aggregations

Page (io.nem.symbol.sdk.api.Page)26 BigInteger (java.math.BigInteger)18 Observable (io.reactivex.Observable)17 Collectors (java.util.stream.Collectors)17 List (java.util.List)13 ApiClient (io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient)10 Order (io.nem.symbol.sdk.openapi.vertx.model.Order)10 AsyncResult (io.vertx.core.AsyncResult)10 Handler (io.vertx.core.Handler)10 Consumer (java.util.function.Consumer)10 MerkleStateInfo (io.nem.symbol.sdk.model.blockchain.MerkleStateInfo)9 ObjectUtils (org.apache.commons.lang3.ObjectUtils)9 Test (org.junit.jupiter.api.Test)9 MetadataSearchCriteria (io.nem.symbol.sdk.api.MetadataSearchCriteria)8 MapperUtils (io.nem.symbol.core.utils.MapperUtils)7 ReceiptRepository (io.nem.symbol.sdk.api.ReceiptRepository)7 ResolutionStatementSearchCriteria (io.nem.symbol.sdk.api.ResolutionStatementSearchCriteria)7 Address (io.nem.symbol.sdk.model.account.Address)7 AddressResolutionStatement (io.nem.symbol.sdk.model.receipt.AddressResolutionStatement)7 MosaicResolutionStatement (io.nem.symbol.sdk.model.receipt.MosaicResolutionStatement)7