Search in sources :

Example 6 with TransactionMetaDTO

use of io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO in project nem2-sdk-java by nemtech.

the class ListenerVertxTest method subscribeAlias.

@ParameterizedTest
@ValueSource(strings = { "CONFIRMED_ADDED", "AGGREGATE_BONDED_ADDED", "UNCONFIRMED_ADDED" })
public void subscribeAlias(ListenerChannel channel) throws InterruptedException, ExecutionException, TimeoutException {
    String channelName = channel.toString();
    simulateWebSocketStartup();
    TransactionInfoDTO transactionInfo = TestHelperVertx.loadTransactionInfoDTO("transferEmptyMessage.json");
    NamespaceId namespaceId = NamespaceId.createFromName("alias");
    ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, ObjectNode.class);
    List<Transaction> transactions = new ArrayList<>();
    BiFunction<UnresolvedAddress, String, Observable<? extends Transaction>> subscriber = channel == ListenerChannel.CONFIRMED_ADDED ? listener::confirmed : channel == ListenerChannel.UNCONFIRMED_ADDED ? listener::unconfirmedAdded : listener::aggregateBondedAdded;
    TransactionMetaDTO meta = jsonHelper.convert(transactionInfo.getMeta(), TransactionMetaDTO.class);
    subscriber.apply(namespaceId, meta.getHash()).forEach(transactions::add);
    handle(transactionInfoDtoJsonObject, channelName + "/" + namespaceId.plain());
    Assertions.assertEquals(1, transactions.size());
    Mockito.verify(webSocketMock).handler(Mockito.any());
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + namespaceId.plain())));
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + namespaceId.plain())));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) ArrayList(java.util.ArrayList) Observable(io.reactivex.Observable) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) TransactionMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with TransactionMetaDTO

use of io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO in project nem2-sdk-java by nemtech.

the class TransactionRepositoryVertxImplTest method exceptionWhenRestCallFails.

@Test
public void exceptionWhenRestCallFails() {
    TransactionInfoDTO transactionInfoDTO = new TransactionInfoDTO();
    TransactionMetaDTO meta = new TransactionMetaDTO();
    meta.setHash("ABC");
    transactionInfoDTO.setMeta(meta);
    mockErrorCode(400, "The error message");
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> {
        ExceptionUtils.propagateVoid(() -> {
            repository.getTransaction(TransactionGroup.CONFIRMED, meta.getHash()).toFuture().get();
        });
    });
    Assertions.assertTrue(exception.getMessage().contains("The error message"));
}
Also used : RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) TestHelperVertx.loadTransactionInfoDTO(io.nem.symbol.sdk.infrastructure.vertx.TestHelperVertx.loadTransactionInfoDTO) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) AnnounceTransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.AnnounceTransactionInfoDTO) TransactionMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO) Test(org.junit.jupiter.api.Test)

Example 8 with TransactionMetaDTO

use of io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO in project nem2-sdk-java by nemtech.

the class TransactionRepositoryVertxImplTest method exceptionWhenMapperFails.

@Test
public void exceptionWhenMapperFails() {
    TransactionInfoDTO transactionInfoDTO = new TransactionInfoDTO();
    TransactionMetaDTO meta = new TransactionMetaDTO();
    String hash = "ABC";
    meta.setHash(hash);
    transactionInfoDTO.setMeta(meta);
    mockRemoteCall(transactionInfoDTO);
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> {
        ExceptionUtils.propagateVoid(() -> {
            repository.getTransaction(TransactionGroup.CONFIRMED, hash).toFuture().get();
        });
    });
    Assertions.assertTrue(exception.getMessage().contains("Transaction cannot be mapped, object does not not have transaction type."));
}
Also used : RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) TestHelperVertx.loadTransactionInfoDTO(io.nem.symbol.sdk.infrastructure.vertx.TestHelperVertx.loadTransactionInfoDTO) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) AnnounceTransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.AnnounceTransactionInfoDTO) TransactionMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO) Test(org.junit.jupiter.api.Test)

Example 9 with TransactionMetaDTO

use of io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO in project nem2-sdk-java by nemtech.

the class ListenerVertxTest method subscribeOnHash.

@ParameterizedTest
@ValueSource(strings = { "CONFIRMED_ADDED", "AGGREGATE_BONDED_ADDED" })
public void subscribeOnHash(ListenerChannel channel) throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    TransactionInfoDTO transactionInfo = TestHelperVertx.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
    ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, ObjectNode.class);
    Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), NETWORK_TYPE);
    String channelName = channel.toString();
    List<Transaction> transactions = new ArrayList<>();
    List<Throwable> exceptions = new ArrayList<>();
    BiFunction<Address, String, Observable<? extends Transaction>> subscriber = channel == ListenerChannel.CONFIRMED_ADDED ? listener::confirmedOrError : listener::aggregateBondedAddedOrError;
    TransactionMetaDTO meta = jsonHelper.convert(transactionInfo.getMeta(), TransactionMetaDTO.class);
    subscriber.apply(address, meta.getHash()).doOnError(exceptions::add).forEach(transactions::add);
    handle(transactionInfoDtoJsonObject, channel.toString() + "/" + address.plain());
    Assertions.assertEquals(1, transactions.size());
    Assertions.assertEquals(0, exceptions.size());
    Assertions.assertEquals(address, transactions.get(0).getSigner().get().getAddress());
    Mockito.verify(webSocketMock).handler(Mockito.any());
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + address.plain())));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Address(io.nem.symbol.sdk.model.account.Address) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) ArrayList(java.util.ArrayList) Observable(io.reactivex.Observable) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) TransactionMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TransactionMetaDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO)9 TransactionInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 ListenerSubscribeMessage (io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)5 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)5 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)5 ArrayList (java.util.ArrayList)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 ValueSource (org.junit.jupiter.params.provider.ValueSource)5 Address (io.nem.symbol.sdk.model.account.Address)4 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)4 Observable (io.reactivex.Observable)4 RepositoryCallException (io.nem.symbol.sdk.api.RepositoryCallException)2 TestHelperVertx.loadTransactionInfoDTO (io.nem.symbol.sdk.infrastructure.vertx.TestHelperVertx.loadTransactionInfoDTO)2 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)2 MosaicSupplyChangeTransaction (io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction)2 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)2 SecretProofTransaction (io.nem.symbol.sdk.model.transaction.SecretProofTransaction)2 TransactionInfo (io.nem.symbol.sdk.model.transaction.TransactionInfo)2 AnnounceTransactionInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.AnnounceTransactionInfoDTO)2