use of io.nem.symbol.sdk.infrastructure.ListenerRequest 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())));
}
Aggregations