use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.
the class ListenerVertxTest method subscribeToHashIncorrectAddress.
@ParameterizedTest
@ValueSource(strings = { "AGGREGATE_BONDED_REMOVED", "UNCONFIRMED_REMOVED" })
public void subscribeToHashIncorrectAddress(ListenerChannel channel) throws InterruptedException, ExecutionException, TimeoutException {
String channelName = channel.toString();
simulateWebSocketStartup();
Address address = Address.generateRandom(NETWORK_TYPE);
String hash = "someHash";
List<String> hashes = new ArrayList<>();
BiFunction<Address, String, Observable<String>> subscriber = channel == ListenerChannel.AGGREGATE_BONDED_REMOVED ? listener::aggregateBondedRemoved : listener::unconfirmedRemoved;
subscriber.apply(address, hash).forEach(hashes::add);
Map<String, Map<String, String>> message = new HashMap<>();
Map<String, String> meta = new HashMap<>();
meta.put("hash", hash);
message.put("meta", meta);
Address invalidAddress = Address.generateRandom(NETWORK_TYPE);
handle(message, channel.toString() + "/" + invalidAddress.plain());
Assertions.assertEquals(0, hashes.size());
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, channelName + "/" + address.plain())));
}
use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.
the class ListenerVertxTest method subscribeFinalizedBlock.
@Test
public void subscribeFinalizedBlock() throws ExecutionException, InterruptedException, TimeoutException {
simulateWebSocketStartup();
String channelName = ListenerChannel.FINALIZED_BLOCK.toString();
FinalizedBlock finalizedBlock = new FinalizedBlock(1L, 2L, BigInteger.valueOf(3), "abc");
ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(finalizedBlock, ObjectNode.class);
List<FinalizedBlock> finalizedBlocks = new ArrayList<>();
listener.finalizedBlock().forEach(finalizedBlocks::add);
handle(transactionInfoDtoJsonObject, channelName);
Assertions.assertEquals(1, finalizedBlocks.size());
Assertions.assertEquals(1, finalizedBlocks.size());
Mockito.verify(webSocketMock).handler(Mockito.any());
Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName)));
}
use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage 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())));
}
use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.
the class ListenerVertxTest method shouldHandleStatus.
@Test
public void shouldHandleStatus() throws InterruptedException, ExecutionException, TimeoutException {
Account account1 = Account.generateNewAccount(NETWORK_TYPE);
AtomicReference<TransactionStatusError> reference = new AtomicReference<>();
simulateWebSocketStartup();
Assertions.assertNotNull(listener.status(account1.getAddress()).subscribe(reference::set));
Map<String, Object> message = new HashMap<>();
message.put("hash", "1234hash");
message.put("address", account1.getAddress().encoded());
message.put("code", "some error");
message.put("deadline", 5555);
handle(message, "status/" + account1.getAddress().plain());
Assertions.assertNotNull(reference.get());
Assertions.assertEquals(message.get("hash"), reference.get().getHash());
Assertions.assertEquals(message.get("code"), reference.get().getStatus());
Assertions.assertEquals(account1.getAddress(), reference.get().getAddress());
Mockito.verify(webSocketMock).handler(Mockito.any());
Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + account1.getAddress().plain())));
}
Aggregations