Search in sources :

Example 1 with ListenerMessage

use of io.nem.symbol.sdk.infrastructure.ListenerMessage in project nem2-sdk-java by nemtech.

the class ListenerVertxTest method subscribeValidUsingBase.

@ParameterizedTest
@ValueSource(strings = { "CONFIRMED_ADDED", "AGGREGATE_BONDED_ADDED" })
public void subscribeValidUsingBase(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<ListenerMessage<Transaction>> messages = new ArrayList<>();
    List<Throwable> exceptions = new ArrayList<>();
    TransactionMetaDTO meta = jsonHelper.convert(transactionInfo.getMeta(), TransactionMetaDTO.class);
    listener.subscribe(new ListenerRequest<Transaction>(channel, address).transactionHashOrError(meta.getHash())).doOnError(exceptions::add).forEach(messages::add);
    handle(transactionInfoDtoJsonObject, channelName + "/" + address.plain());
    Assertions.assertEquals(1, messages.size());
    Assertions.assertEquals(0, exceptions.size());
    Assertions.assertEquals(meta.getHash(), messages.get(0).getTransactionHash());
    Assertions.assertEquals(channel, messages.get(0).getChannel());
    Assertions.assertEquals(address.plain(), messages.get(0).getChannelParams());
    Assertions.assertEquals(channelName + "/" + address.plain(), messages.get(0).getTopic());
    Assertions.assertEquals(address, messages.get(0).getMessage().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) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) ListenerRequest(io.nem.symbol.sdk.infrastructure.ListenerRequest) ListenerMessage(io.nem.symbol.sdk.infrastructure.ListenerMessage) TransactionMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ListenerMessage (io.nem.symbol.sdk.infrastructure.ListenerMessage)1 ListenerRequest (io.nem.symbol.sdk.infrastructure.ListenerRequest)1 ListenerSubscribeMessage (io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)1 Address (io.nem.symbol.sdk.model.account.Address)1 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)1 TransactionInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO)1 TransactionMetaDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO)1 ArrayList (java.util.ArrayList)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1