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())));
}
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"));
}
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."));
}
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())));
}
Aggregations